Source Code Cross Referenced for DB2400QueryHandler.java in  » Wiki-Engine » JAMWiki » org » jamwiki » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » JAMWiki » org.jamwiki.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.text.MessageFormat;
019:        import java.util.Properties;
020:        import org.jamwiki.Environment;
021:        import org.jamwiki.utils.Pagination;
022:        import org.jamwiki.utils.Utilities;
023:        import org.jamwiki.utils.WikiLogger;
024:
025:        /**
026:         * DB2/400-specific implementation of the QueryHandler interface.  This class implements
027:         * DB2/400-specific methods for instances where DB2/400 does not support the default
028:         * ASCII SQL syntax.
029:         */
030:        public class DB2400QueryHandler extends AnsiQueryHandler {
031:
032:            private static final WikiLogger logger = WikiLogger
033:                    .getLogger(DB2400QueryHandler.class.getName());
034:            private static final String SQL_PROPERTY_FILE_NAME = "sql.db2400.properties";
035:            private static Properties props = null;
036:            private static Properties defaults = null;
037:
038:            /**
039:             *
040:             */
041:            protected DB2400QueryHandler() {
042:                defaults = Environment
043:                        .loadProperties(AnsiQueryHandler.SQL_PROPERTY_FILE_NAME);
044:                props = Environment.loadProperties(SQL_PROPERTY_FILE_NAME,
045:                        defaults);
046:                super .init(props);
047:            }
048:
049:            /**
050:             * DB2/400 will not allow query parameters such as "fetch ? rows only", so
051:             * this method provides a way of formatting the query limits without using
052:             * query parameters.
053:             *
054:             * @param sql The SQL statement, with the last result parameter specified as
055:             *  {0} and the total number of rows parameter specified as {1}.
056:             * @param pagination A Pagination object that specifies the number of results
057:             *  and starting result offset for the result set to be retrieved.
058:             * @return A formatted SQL string.
059:             */
060:            private static String formatStatement(String sql,
061:                    Pagination pagination) {
062:                try {
063:                    Object[] objects = { new Integer(pagination.getEnd()),
064:                            new Integer(pagination.getNumResults()) };
065:                    return MessageFormat.format(sql, objects);
066:                } catch (Exception e) {
067:                    logger.warning("Unable to format " + sql + " with values "
068:                            + pagination.getEnd() + " / "
069:                            + pagination.getNumResults(), e);
070:                    return null;
071:                }
072:            }
073:
074:            /**
075:             *
076:             */
077:            public WikiResultSet getCategories(int virtualWikiId,
078:                    Pagination pagination) throws Exception {
079:                String sql = formatStatement(STATEMENT_SELECT_CATEGORIES,
080:                        pagination);
081:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
082:                stmt.setInt(1, virtualWikiId);
083:                return stmt.executeQuery();
084:            }
085:
086:            /**
087:             *
088:             */
089:            public WikiResultSet getRecentChanges(String virtualWiki,
090:                    Pagination pagination, boolean descending) throws Exception {
091:                String sql = formatStatement(STATEMENT_SELECT_RECENT_CHANGES,
092:                        pagination);
093:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
094:                stmt.setString(1, virtualWiki);
095:                // FIXME - sort order ignored
096:                return stmt.executeQuery();
097:            }
098:
099:            /**
100:             *
101:             */
102:            public WikiResultSet getRecentChanges(int topicId,
103:                    Pagination pagination, boolean descending) throws Exception {
104:                String sql = formatStatement(
105:                        STATEMENT_SELECT_RECENT_CHANGES_TOPIC, pagination);
106:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
107:                stmt.setInt(1, topicId);
108:                // FIXME - sort order ignored
109:                return stmt.executeQuery();
110:            }
111:
112:            /**
113:             *
114:             */
115:            public WikiResultSet getTopicsAdmin(int virtualWikiId,
116:                    Pagination pagination) throws Exception {
117:                String sql = formatStatement(STATEMENT_SELECT_TOPICS_ADMIN,
118:                        pagination);
119:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
120:                stmt.setInt(1, virtualWikiId);
121:                return stmt.executeQuery();
122:            }
123:
124:            /**
125:             *
126:             */
127:            public WikiResultSet getUserContributions(String virtualWiki,
128:                    String userString, Pagination pagination, boolean descending)
129:                    throws Exception {
130:                String sql = null;
131:                if (Utilities.isIpAddress(userString)) {
132:                    sql = formatStatement(
133:                            STATEMENT_SELECT_WIKI_USER_CHANGES_ANONYMOUS,
134:                            pagination);
135:                } else {
136:                    sql = formatStatement(
137:                            STATEMENT_SELECT_WIKI_USER_CHANGES_LOGIN,
138:                            pagination);
139:                }
140:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
141:                stmt.setString(1, virtualWiki);
142:                stmt.setString(2, userString);
143:                // FIXME - sort order ignored
144:                return stmt.executeQuery();
145:            }
146:
147:            /**
148:             *
149:             */
150:            public WikiResultSet getWatchlist(int virtualWikiId, int userId,
151:                    Pagination pagination) throws Exception {
152:                String sql = formatStatement(
153:                        STATEMENT_SELECT_WATCHLIST_CHANGES, pagination);
154:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
155:                stmt.setInt(1, virtualWikiId);
156:                stmt.setInt(2, userId);
157:                return stmt.executeQuery();
158:            }
159:
160:            /**
161:             *
162:             */
163:            public WikiResultSet lookupTopicByType(int virtualWikiId,
164:                    int topicType, Pagination pagination) throws Exception {
165:                String sql = formatStatement(STATEMENT_SELECT_TOPIC_BY_TYPE,
166:                        pagination);
167:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
168:                stmt.setInt(1, virtualWikiId);
169:                stmt.setInt(2, topicType);
170:                return stmt.executeQuery();
171:            }
172:
173:            /**
174:             *
175:             */
176:            public WikiResultSet lookupWikiUsers(Pagination pagination)
177:                    throws Exception {
178:                String sql = formatStatement(STATEMENT_SELECT_WIKI_USERS,
179:                        pagination);
180:                WikiPreparedStatement stmt = new WikiPreparedStatement(sql);
181:                return stmt.executeQuery();
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.