Source Code Cross Referenced for PoolStatement.java in  » Database-JDBC-Connection-Pool » Primrose » uk » org » primrose » pool » core » 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 » Primrose » uk.org.primrose.pool.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *	Library name : Primrose - A Java Database Connection Pool.
003:         *	Published by Ben Keeping, http://primrose.org.uk .
004:         *	Copyright (C) 2004 Ben Keeping, primrose.org.uk
005:         *	Email: Use "Contact Us Form" on website
006:         *
007:         *	This library is free software; you can redistribute it and/or
008:         *	modify it under the terms of the GNU Lesser General Public
009:         *	License as published by the Free Software Foundation; either
010:         *	version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *	This library is distributed in the hope that it will be useful,
013:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *	Lesser General Public License for more details.
016:         *
017:         *	You should have received a copy of the GNU Lesser General Public
018:         *	License along with this library; if not, write to the Free Software
019:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */package uk.org.primrose.pool.core;
021:
022:        import java.sql.*;
023:
024:        /**
025:         * 	A wrapper for a vendor specific implementation of Statement.
026:         *	Allows for complete logging of SQL transactions, aswell as identifying
027:         *	unclosed statements before Connection close() calls.
028:         */
029:        public class PoolStatement implements  Statement {
030:            Statement s = null;
031:            ConnectionHolder connHolder = null;
032:
033:            public PoolStatement(Statement s, ConnectionHolder connHolder) {
034:                this .connHolder = connHolder;
035:                this .connHolder.statementObjects.push(this );
036:                this .s = s;
037:            }
038:
039:            public PoolStatement() {
040:            }
041:
042:            protected void closeNoPop() throws SQLException {
043:                s.close();
044:            }
045:
046:            public void close() throws SQLException {
047:                for (int i = 0; i < connHolder.statementObjects.size(); i++) {
048:                    PoolStatement ts = connHolder.statementObjects.get(i);
049:                    if (ts == this ) {
050:                        connHolder.statementObjects.remove(this );
051:                        break;
052:                    }
053:                }
054:
055:                if (this .connHolder.bDumpConnectionOnSQLException) {
056:                    try {
057:                        s.close();
058:                    } catch (SQLException sqle) {
059:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
060:                        this .connHolder.logger
061:                                .warn("Closing connection due to SQLException on close()");
062:                        this .connHolder.myPool.notifyExceptionEvent();
063:                        throw sqle;
064:                    }
065:                } else {
066:                    s.close();
067:                }
068:            }
069:
070:            public ResultSet executeQuery(String sql) throws SQLException {
071:                this .connHolder.sql = sql;
072:                if (this .connHolder.bDumpConnectionOnSQLException) {
073:                    try {
074:                        PoolResultSet prs = new PoolResultSet(s
075:                                .executeQuery(sql), this .connHolder);
076:                        return prs;
077:                    } catch (SQLException sqle) {
078:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
079:                        this .connHolder.logger
080:                                .warn("Closing connection due to SQLException on execute");
081:                        this .connHolder.myPool.notifyExceptionEvent();
082:                        throw sqle;
083:                    }
084:                } else {
085:                    PoolResultSet prs = new PoolResultSet(s.executeQuery(sql),
086:                            this .connHolder);
087:                    return prs;
088:                }
089:            }
090:
091:            public int executeUpdate(String sql) throws SQLException {
092:                this .connHolder.sql = sql;
093:                if (this .connHolder.bDumpConnectionOnSQLException) {
094:                    try {
095:                        return s.executeUpdate(sql);
096:                    } catch (SQLException sqle) {
097:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
098:                        this .connHolder.logger
099:                                .warn("Closing connection due to SQLException on execute");
100:                        this .connHolder.myPool.notifyExceptionEvent();
101:                        throw sqle;
102:                    }
103:                } else {
104:                    return s.executeUpdate(sql);
105:                }
106:            }
107:
108:            public int executeUpdate(String sql, int autoGeneratedKeys)
109:                    throws SQLException {
110:
111:                this .connHolder.sql = sql;
112:                if (this .connHolder.bDumpConnectionOnSQLException) {
113:                    try {
114:                        return s.executeUpdate(sql, autoGeneratedKeys);
115:                    } catch (SQLException sqle) {
116:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
117:                        this .connHolder.logger
118:                                .warn("Closing connection due to SQLException on execute");
119:                        this .connHolder.myPool.notifyExceptionEvent();
120:                        throw sqle;
121:                    }
122:                } else {
123:                    return s.executeUpdate(sql, autoGeneratedKeys);
124:                }
125:            }
126:
127:            public int executeUpdate(String sql, int columnIndexes[])
128:                    throws SQLException {
129:                this .connHolder.sql = sql;
130:                if (this .connHolder.bDumpConnectionOnSQLException) {
131:                    try {
132:                        return s.executeUpdate(sql, columnIndexes);
133:                    } catch (SQLException sqle) {
134:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
135:                        this .connHolder.logger
136:                                .warn("Closing connection due to SQLException on execute");
137:                        this .connHolder.myPool.notifyExceptionEvent();
138:                        throw sqle;
139:                    }
140:                } else {
141:                    return s.executeUpdate(sql, columnIndexes);
142:                }
143:            }
144:
145:            public int executeUpdate(String sql, String columnNames[])
146:                    throws SQLException {
147:                this .connHolder.sql = sql;
148:                if (this .connHolder.bDumpConnectionOnSQLException) {
149:                    try {
150:                        return s.executeUpdate(sql, columnNames);
151:                    } catch (SQLException sqle) {
152:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
153:                        this .connHolder.logger
154:                                .warn("Closing connection due to SQLException on execute");
155:                        this .connHolder.myPool.notifyExceptionEvent();
156:                        throw sqle;
157:                    }
158:                } else {
159:                    return s.executeUpdate(sql, columnNames);
160:                }
161:            }
162:
163:            public boolean execute(String sql, int autoGeneratedKeys)
164:                    throws SQLException {
165:                this .connHolder.sql = sql;
166:                if (this .connHolder.bDumpConnectionOnSQLException) {
167:                    try {
168:                        return s.execute(sql, autoGeneratedKeys);
169:                    } catch (SQLException sqle) {
170:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
171:                        this .connHolder.logger
172:                                .warn("Closing connection due to SQLException on execute");
173:                        this .connHolder.myPool.notifyExceptionEvent();
174:                        throw sqle;
175:                    }
176:                } else {
177:                    return s.execute(sql, autoGeneratedKeys);
178:                }
179:            }
180:
181:            public boolean execute(String sql, int columnIndexes[])
182:                    throws SQLException {
183:                this .connHolder.sql = sql;
184:                if (this .connHolder.bDumpConnectionOnSQLException) {
185:                    try {
186:                        return s.execute(sql, columnIndexes);
187:                    } catch (SQLException sqle) {
188:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
189:                        this .connHolder.logger
190:                                .warn("Closing connection due to SQLException on execute");
191:                        this .connHolder.myPool.notifyExceptionEvent();
192:                        throw sqle;
193:                    }
194:                } else {
195:                    return s.execute(sql, columnIndexes);
196:                }
197:            }
198:
199:            public boolean execute(String sql, String columnNames[])
200:                    throws SQLException {
201:                this .connHolder.sql = sql;
202:                if (this .connHolder.bDumpConnectionOnSQLException) {
203:                    try {
204:                        return s.execute(sql, columnNames);
205:                    } catch (SQLException sqle) {
206:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
207:                        this .connHolder.logger
208:                                .warn("Closing connection due to SQLException on execute");
209:                        this .connHolder.myPool.notifyExceptionEvent();
210:                        throw sqle;
211:                    }
212:                } else {
213:                    return s.execute(sql, columnNames);
214:                }
215:            }
216:
217:            public int[] executeBatch() throws SQLException {
218:                if (this .connHolder.bDumpConnectionOnSQLException) {
219:                    try {
220:                        return s.executeBatch();
221:                    } catch (SQLException sqle) {
222:                        this .connHolder.closeBehaviour = Pool.ON_CLOSE_SHOULD_DIE;
223:                        this .connHolder.logger
224:                                .warn("Closing connection due to SQLException on execute");
225:                        this .connHolder.myPool.notifyExceptionEvent();
226:                        throw sqle;
227:                    }
228:                } else {
229:                    return s.executeBatch();
230:                }
231:            }
232:
233:            public int getMaxFieldSize() throws SQLException {
234:                return s.getMaxFieldSize();
235:            }
236:
237:            public void setMaxFieldSize(int max) throws SQLException {
238:                s.setMaxFieldSize(max);
239:            }
240:
241:            public int getMaxRows() throws SQLException {
242:                return s.getMaxRows();
243:            }
244:
245:            public void setMaxRows(int max) throws SQLException {
246:                s.setMaxRows(max);
247:            }
248:
249:            public void setEscapeProcessing(boolean enable) throws SQLException {
250:                s.setEscapeProcessing(enable);
251:            }
252:
253:            public int getQueryTimeout() throws SQLException {
254:                return s.getQueryTimeout();
255:            }
256:
257:            public void setQueryTimeout(int seconds) throws SQLException {
258:                s.setQueryTimeout(seconds);
259:            }
260:
261:            public void cancel() throws SQLException {
262:                s.cancel();
263:            }
264:
265:            public SQLWarning getWarnings() throws SQLException {
266:                return s.getWarnings();
267:            }
268:
269:            public void clearWarnings() throws SQLException {
270:                s.clearWarnings();
271:            }
272:
273:            public void setCursorName(String name) throws SQLException {
274:                s.setCursorName(name);
275:            }
276:
277:            public boolean execute(String sql) throws SQLException {
278:                this .connHolder.sql = sql;
279:                return s.execute(sql);
280:            }
281:
282:            public ResultSet getResultSet() throws SQLException {
283:                PoolResultSet prs = new PoolResultSet(s.getResultSet(),
284:                        this .connHolder);
285:                return prs;
286:            }
287:
288:            public int getUpdateCount() throws SQLException {
289:                return s.getUpdateCount();
290:            }
291:
292:            public boolean getMoreResults() throws SQLException {
293:                return s.getMoreResults();
294:            }
295:
296:            public void setFetchDirection(int direction) throws SQLException {
297:                s.setFetchDirection(direction);
298:            }
299:
300:            public int getFetchDirection() throws SQLException {
301:                return s.getFetchDirection();
302:            }
303:
304:            public void setFetchSize(int rows) throws SQLException {
305:                s.setFetchSize(rows);
306:            }
307:
308:            public int getFetchSize() throws SQLException {
309:                return s.getFetchSize();
310:            }
311:
312:            public int getResultSetConcurrency() throws SQLException {
313:                return s.getResultSetConcurrency();
314:            }
315:
316:            public int getResultSetType() throws SQLException {
317:                return s.getResultSetType();
318:            }
319:
320:            public void addBatch(String sql) throws SQLException {
321:                s.addBatch(sql);
322:            }
323:
324:            public void clearBatch() throws SQLException {
325:                s.clearBatch();
326:            }
327:
328:            public Connection getConnection() throws SQLException {
329:                return s.getConnection();
330:            }
331:
332:            public boolean getMoreResults(int current) throws SQLException {
333:                return s.getMoreResults(current);
334:            }
335:
336:            public ResultSet getGeneratedKeys() throws SQLException {
337:                PoolResultSet prs = new PoolResultSet(s.getGeneratedKeys(),
338:                        this .connHolder);
339:                return prs;
340:            }
341:
342:            public int getResultSetHoldability() throws SQLException {
343:                return s.getResultSetHoldability();
344:            }
345:
346:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.