01: /*
02: * Piscator: a small SQL/XML search engine
03: * Copyright (C) 2007 Luk Morbee
04: *
05: * This program is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package piscator.dao.jdbc;
20:
21: import java.util.List;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.springframework.jdbc.core.support.JdbcDaoSupport;
26:
27: import piscator.dao.DocumentTableDao;
28:
29: public class DocumentTableDaoImpl extends JdbcDaoSupport implements
30: DocumentTableDao {
31:
32: private static Log LOG = LogFactory
33: .getLog(DocumentTableDaoImpl.class);
34:
35: /* (non-Javadoc)
36: * @see piscator.dao.DocumentTableDao#create(java.lang.String)
37: */
38: public void create(String table) {
39: StringBuffer sql = new StringBuffer();
40: sql.append("DROP TABLE ").append(table).append(" IF EXISTS;\n");
41: sql
42: .append("CREATE TABLE ")
43: .append(table)
44: .append(
45: " (doc_id INTEGER IDENTITY PRIMARY KEY, xml LONGVARCHAR);\n");
46: LOG.info(sql.toString());
47: getJdbcTemplate().execute(sql.toString());
48: }
49:
50: /* (non-Javadoc)
51: * @see piscator.dao.DocumentTableDao#insert(java.lang.String, java.lang.String)
52: */
53: public void insert(String table, String xml) {
54: Object[] args = { xml };
55: getJdbcTemplate().update(
56: "INSERT INTO " + table + " (xml) VALUES(?)", args);
57: }
58:
59: /* (non-Javadoc)
60: * @see piscator.dao.DocumentTableDao#getDocIds(java.lang.String)
61: */
62: public List getDocIds(String table) {
63: return getJdbcTemplate().queryForList(
64: "SELECT doc_id FROM " + table, String.class);
65: }
66:
67: /* (non-Javadoc)
68: * @see piscator.dao.DocumentTableDao#getDocument(java.lang.String, java.lang.String)
69: */
70: public String getDocument(String table, String docId) {
71: String sql = "SELECT xml FROM " + table + " WHERE doc_id = "
72: + docId;
73: return (String) getJdbcTemplate().queryForObject(sql,
74: String.class);
75: }
76:
77: }
|