Source Code Cross Referenced for CachedStatement.java in  » Database-JDBC-Connection-Pool » DBPool » snaq » 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 » Database JDBC Connection Pool » DBPool » snaq.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        	DBPool - JDBC Connection Pool Manager
003:        	Copyright (c) Giles Winstanley
004:         */
005:        package snaq.db;
006:
007:        import snaq.util.Reusable;
008:        import java.sql.*;
009:
010:        /**
011:         * Statement wrapper that provides methods for caching support.
012:         * @author Giles Winstanley
013:         */
014:        public class CachedStatement implements  Statement, Reusable {
015:            protected StatementListener listener;
016:            protected Statement st;
017:            protected boolean open = true; // Exists to avoid repeat cleaning of statement
018:
019:            /**
020:             * Creates a new CachedStatement object, using the supplied Statement.
021:             */
022:            public CachedStatement(Statement st) {
023:                this .st = st;
024:            }
025:
026:            /** Returns a string descriptions of the ResultSet parameters. */
027:            protected String getParametersString() {
028:                StringBuffer sb = new StringBuffer();
029:                try {
030:                    switch (getResultSetType()) {
031:                    case ResultSet.TYPE_SCROLL_INSENSITIVE:
032:                        sb.append("TYPE_SCROLL_INSENSITIVE");
033:                        break;
034:                    case ResultSet.TYPE_SCROLL_SENSITIVE:
035:                        sb.append("TYPE_SCROLL_SENSITIVE");
036:                        break;
037:                    default:
038:                        sb.append("TYPE_FORWARD_ONLY");
039:                    }
040:                } catch (SQLException sqle) {
041:                    sb.append("TYPE_UNKNOWN");
042:                }
043:                sb.append(',');
044:                try {
045:                    switch (getResultSetConcurrency()) {
046:                    case ResultSet.CONCUR_UPDATABLE:
047:                        sb.append("CONCUR_UPDATABLE");
048:                        break;
049:                    default:
050:                        sb.append("CONCUR_READ_ONLY");
051:                    }
052:                } catch (SQLException sqle) {
053:                    sb.append("CONCUR_UNKNOWN");
054:                }
055:                sb.append(',');
056:                try {
057:                    switch (getResultSetHoldability()) {
058:                    case ResultSet.CLOSE_CURSORS_AT_COMMIT:
059:                        sb.append("CLOSE_CURSORS_AT_COMMIT");
060:                        break;
061:                    case ResultSet.HOLD_CURSORS_OVER_COMMIT:
062:                        sb.append("HOLD_CURSORS_OVER_COMMIT");
063:                    }
064:                } catch (SQLException sqle) {
065:                    sb.append("HOLD_UNKNOWN");
066:                }
067:                return sb.toString();
068:            }
069:
070:            // Cleans up the statement ready to be reused or closed.
071:            public void recycle() throws SQLException {
072:                ResultSet rs = st.getResultSet();
073:                if (rs != null)
074:                    rs.close();
075:
076:                try {
077:                    st.clearWarnings();
078:                } catch (SQLException sqle) {
079:                } // Caught to fix bug in some drivers
080:
081:                try {
082:                    st.clearBatch();
083:                } catch (SQLException sqle) {
084:                } // Caught to fix bug in some drivers
085:            }
086:
087:            /**
088:             * Overridden to provide caching support.
089:             */
090:            public void close() throws SQLException {
091:                if (!open)
092:                    return;
093:                open = false;
094:                // If listener registered, do callback, otherwise release statement
095:                if (listener != null)
096:                    listener.statementClosed(this );
097:                else
098:                    release();
099:            }
100:
101:            /**
102:             * Overridden to provide caching support.
103:             */
104:            public void release() throws SQLException {
105:                st.close();
106:            }
107:
108:            /**
109:             * Added to provide caching support.
110:             */
111:            void setOpen() {
112:                open = true;
113:            }
114:
115:            /**
116:             * Added to provide caching support.
117:             */
118:            void setStatementListener(StatementListener x) {
119:                this .listener = x;
120:            }
121:
122:            //*****************************
123:            // Statement interface methods
124:            //*****************************
125:
126:            public ResultSet executeQuery(String sql) throws SQLException {
127:                return st.executeQuery(sql);
128:            }
129:
130:            public int executeUpdate(String sql) throws SQLException {
131:                return st.executeUpdate(sql);
132:            }
133:
134:            public int getMaxFieldSize() throws SQLException {
135:                return st.getMaxFieldSize();
136:            }
137:
138:            public void setMaxFieldSize(int max) throws SQLException {
139:                st.setMaxFieldSize(max);
140:            }
141:
142:            public int getMaxRows() throws SQLException {
143:                return st.getMaxRows();
144:            }
145:
146:            public void setMaxRows(int max) throws SQLException {
147:                st.setMaxRows(max);
148:            }
149:
150:            public void setEscapeProcessing(boolean enable) throws SQLException {
151:                st.setEscapeProcessing(enable);
152:            }
153:
154:            public int getQueryTimeout() throws SQLException {
155:                return st.getQueryTimeout();
156:            }
157:
158:            public void setQueryTimeout(int seconds) throws SQLException {
159:                st.setQueryTimeout(seconds);
160:            }
161:
162:            public void cancel() throws SQLException {
163:                st.cancel();
164:            }
165:
166:            public SQLWarning getWarnings() throws SQLException {
167:                return st.getWarnings();
168:            }
169:
170:            public void clearWarnings() throws SQLException {
171:                st.clearWarnings();
172:            }
173:
174:            public void setCursorName(String name) throws SQLException {
175:                st.setCursorName(name);
176:            }
177:
178:            public boolean execute(String sql) throws SQLException {
179:                return st.execute(sql);
180:            }
181:
182:            public ResultSet getResultSet() throws SQLException {
183:                return st.getResultSet();
184:            }
185:
186:            public int getUpdateCount() throws SQLException {
187:                return st.getUpdateCount();
188:            }
189:
190:            public boolean getMoreResults() throws SQLException {
191:                return st.getMoreResults();
192:            }
193:
194:            public void setFetchDirection(int direction) throws SQLException {
195:                st.setFetchDirection(direction);
196:            }
197:
198:            public int getFetchDirection() throws SQLException {
199:                return st.getFetchDirection();
200:            }
201:
202:            public void setFetchSize(int rows) throws SQLException {
203:                st.setFetchSize(rows);
204:            }
205:
206:            public int getFetchSize() throws SQLException {
207:                return st.getFetchSize();
208:            }
209:
210:            public int getResultSetConcurrency() throws SQLException {
211:                return st.getResultSetConcurrency();
212:            }
213:
214:            public int getResultSetType() throws SQLException {
215:                return st.getResultSetType();
216:            }
217:
218:            public void addBatch(String sql) throws SQLException {
219:                st.addBatch(sql);
220:            }
221:
222:            public void clearBatch() throws SQLException {
223:                st.clearBatch();
224:            }
225:
226:            public int[] executeBatch() throws SQLException {
227:                return st.executeBatch();
228:            }
229:
230:            public Connection getConnection() throws SQLException {
231:                return st.getConnection();
232:            }
233:
234:            //**********************************
235:            // Interface methods from JDBC 3.0
236:            //**********************************
237:
238:            public boolean getMoreResults(int current) throws SQLException {
239:                return st.getMoreResults(current);
240:            }
241:
242:            public ResultSet getGeneratedKeys() throws SQLException {
243:                return st.getGeneratedKeys();
244:            }
245:
246:            public int executeUpdate(String sql, int autoGeneratedKeys)
247:                    throws SQLException {
248:                return st.executeUpdate(sql, autoGeneratedKeys);
249:            }
250:
251:            public int executeUpdate(String sql, int[] columnIndexes)
252:                    throws SQLException {
253:                return st.executeUpdate(sql, columnIndexes);
254:            }
255:
256:            public int executeUpdate(String sql, String[] columnNames)
257:                    throws SQLException {
258:                return st.executeUpdate(sql, columnNames);
259:            }
260:
261:            public boolean execute(String sql, int autoGeneratedKeys)
262:                    throws SQLException {
263:                return st.execute(sql, autoGeneratedKeys);
264:            }
265:
266:            public boolean execute(String sql, int[] columnIndexes)
267:                    throws SQLException {
268:                return st.execute(sql, columnIndexes);
269:            }
270:
271:            public boolean execute(String sql, String[] columnNames)
272:                    throws SQLException {
273:                return st.execute(sql, columnNames);
274:            }
275:
276:            public int getResultSetHoldability() throws SQLException {
277:                return st.getResultSetHoldability();
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.