001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: */package org.jamwiki.db;
017:
018: import java.util.Properties;
019: import org.jamwiki.Environment;
020: import org.jamwiki.utils.Pagination;
021: import org.jamwiki.utils.Utilities;
022: import org.jamwiki.utils.WikiLogger;
023:
024: /**
025: * DB2-specific implementation of the QueryHandler interface. This class implements
026: * DB2-specific methods for instances where DB2 does not support the default
027: * ASCII SQL syntax.
028: */
029: public class DB2QueryHandler extends AnsiQueryHandler {
030:
031: private static final WikiLogger logger = WikiLogger
032: .getLogger(DB2QueryHandler.class.getName());
033: private static final String SQL_PROPERTY_FILE_NAME = "sql.db2.properties";
034: private static Properties props = null;
035: private static Properties defaults = null;
036:
037: /**
038: *
039: */
040: protected DB2QueryHandler() {
041: defaults = Environment
042: .loadProperties(AnsiQueryHandler.SQL_PROPERTY_FILE_NAME);
043: props = Environment.loadProperties(SQL_PROPERTY_FILE_NAME,
044: defaults);
045: super .init(props);
046: }
047:
048: /**
049: *
050: */
051: public WikiResultSet getCategories(int virtualWikiId,
052: Pagination pagination) throws Exception {
053: WikiPreparedStatement stmt = new WikiPreparedStatement(
054: STATEMENT_SELECT_CATEGORIES);
055: stmt.setInt(1, virtualWikiId);
056: stmt.setInt(2, pagination.getStart());
057: stmt.setInt(3, pagination.getEnd());
058: return stmt.executeQuery();
059: }
060:
061: /**
062: *
063: */
064: public WikiResultSet getRecentChanges(String virtualWiki,
065: Pagination pagination, boolean descending) throws Exception {
066: WikiPreparedStatement stmt = new WikiPreparedStatement(
067: STATEMENT_SELECT_RECENT_CHANGES);
068: stmt.setString(1, virtualWiki);
069: stmt.setInt(2, pagination.getStart());
070: stmt.setInt(3, pagination.getEnd());
071: // FIXME - sort order ignored
072: return stmt.executeQuery();
073: }
074:
075: /**
076: *
077: */
078: public WikiResultSet getRecentChanges(int topicId,
079: Pagination pagination, boolean descending) throws Exception {
080: WikiPreparedStatement stmt = new WikiPreparedStatement(
081: STATEMENT_SELECT_RECENT_CHANGES_TOPIC);
082: stmt.setInt(1, topicId);
083: stmt.setInt(2, pagination.getStart());
084: stmt.setInt(3, pagination.getEnd());
085: // FIXME - sort order ignored
086: return stmt.executeQuery();
087: }
088:
089: /**
090: *
091: */
092: public WikiResultSet getTopicsAdmin(int virtualWikiId,
093: Pagination pagination) throws Exception {
094: WikiPreparedStatement stmt = new WikiPreparedStatement(
095: STATEMENT_SELECT_TOPICS_ADMIN);
096: stmt.setInt(1, virtualWikiId);
097: stmt.setInt(2, pagination.getStart());
098: stmt.setInt(3, pagination.getEnd());
099: return stmt.executeQuery();
100: }
101:
102: /**
103: *
104: */
105: public WikiResultSet getUserContributions(String virtualWiki,
106: String userString, Pagination pagination, boolean descending)
107: throws Exception {
108: WikiPreparedStatement stmt = null;
109: if (Utilities.isIpAddress(userString)) {
110: stmt = new WikiPreparedStatement(
111: STATEMENT_SELECT_WIKI_USER_CHANGES_ANONYMOUS);
112: } else {
113: stmt = new WikiPreparedStatement(
114: STATEMENT_SELECT_WIKI_USER_CHANGES_LOGIN);
115: }
116: stmt.setString(1, virtualWiki);
117: stmt.setString(2, userString);
118: stmt.setInt(3, pagination.getStart());
119: stmt.setInt(4, pagination.getEnd());
120: // FIXME - sort order ignored
121: return stmt.executeQuery();
122: }
123:
124: /**
125: *
126: */
127: public WikiResultSet getWatchlist(int virtualWikiId, int userId,
128: Pagination pagination) throws Exception {
129: WikiPreparedStatement stmt = new WikiPreparedStatement(
130: STATEMENT_SELECT_WATCHLIST_CHANGES);
131: stmt.setInt(1, virtualWikiId);
132: stmt.setInt(2, userId);
133: stmt.setInt(3, pagination.getStart());
134: stmt.setInt(4, pagination.getEnd());
135: return stmt.executeQuery();
136: }
137:
138: /**
139: *
140: */
141: public WikiResultSet lookupTopicByType(int virtualWikiId,
142: int topicType, Pagination pagination) throws Exception {
143: WikiPreparedStatement stmt = new WikiPreparedStatement(
144: STATEMENT_SELECT_TOPIC_BY_TYPE);
145: stmt.setInt(1, virtualWikiId);
146: stmt.setInt(2, topicType);
147: stmt.setInt(3, pagination.getStart());
148: stmt.setInt(4, pagination.getEnd());
149: return stmt.executeQuery();
150: }
151:
152: /**
153: *
154: */
155: public WikiResultSet lookupWikiUsers(Pagination pagination)
156: throws Exception {
157: WikiPreparedStatement stmt = new WikiPreparedStatement(
158: STATEMENT_SELECT_WIKI_USERS);
159: stmt.setInt(1, pagination.getStart());
160: stmt.setInt(2, pagination.getEnd());
161: return stmt.executeQuery();
162: }
163: }
|