Source Code Cross Referenced for StatementProxy.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » jdbcx » proxy » 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 » jTDS » net.sourceforge.jtds.jdbcx.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002:        // Copyright (C) 2004 The jTDS Project
003:        //
004:        // This library is free software; you can redistribute it and/or
005:        // modify it under the terms of the GNU Lesser General Public
006:        // License as published by the Free Software Foundation; either
007:        // version 2.1 of the License, or (at your option) any later version.
008:        //
009:        // This library is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:        // Lesser General Public License for more details.
013:        //
014:        // You should have received a copy of the GNU Lesser General Public
015:        // License along with this library; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:        //
018:        package net.sourceforge.jtds.jdbcx.proxy;
019:
020:        import java.sql.*;
021:
022:        import net.sourceforge.jtds.jdbc.*;
023:
024:        /**
025:         * This class would be better implemented as a java.lang.reflect.Proxy.  However, this
026:         * feature was not added until 1.3 and reflection performance was not improved until 1.4.
027:         * Since the driver still needs to be compatible with 1.2 and 1.3 this class is used
028:         * to delegate the calls to a statement with minimal overhead.
029:         *
030:         * @version $Id: StatementProxy.java,v 1.4 2004/08/24 17:45:08 bheineman Exp $
031:         */
032:        public class StatementProxy implements  Statement {
033:            private ConnectionProxy _connection;
034:            private JtdsStatement _statement;
035:
036:            StatementProxy(ConnectionProxy connection, JtdsStatement statement) {
037:                _connection = connection;
038:                _statement = statement;
039:            }
040:
041:            /**
042:             * Delgates calls to the statement; SQLExceptions thrown from the statement
043:             * will cause an event to be fired on the connection pool listeners.
044:             *
045:             * @throws SQLException if an error occurs
046:             */
047:            public ResultSet executeQuery(String sql) throws SQLException {
048:                validateConnection();
049:
050:                try {
051:                    return _statement.executeQuery(sql);
052:                } catch (SQLException sqlException) {
053:                    processSQLException(sqlException);
054:                }
055:
056:                return null;
057:            }
058:
059:            /**
060:             * Delgates calls to the statement; SQLExceptions thrown from the statement
061:             * will cause an event to be fired on the connection pool listeners.
062:             *
063:             * @throws SQLException if an error occurs
064:             */
065:            public int executeUpdate(String sql) throws SQLException {
066:                validateConnection();
067:
068:                try {
069:                    return _statement.executeUpdate(sql);
070:                } catch (SQLException sqlException) {
071:                    processSQLException(sqlException);
072:                }
073:
074:                return Integer.MIN_VALUE;
075:            }
076:
077:            /**
078:             * Delgates calls to the statement; SQLExceptions thrown from the statement
079:             * will cause an event to be fired on the connection pool listeners.
080:             *
081:             * @throws SQLException if an error occurs
082:             */
083:            public void close() throws SQLException {
084:                validateConnection();
085:
086:                try {
087:                    _statement.close();
088:                } catch (SQLException sqlException) {
089:                    processSQLException(sqlException);
090:                }
091:            }
092:
093:            /**
094:             * Delgates calls to the statement; SQLExceptions thrown from the statement
095:             * will cause an event to be fired on the connection pool listeners.
096:             *
097:             * @throws SQLException if an error occurs
098:             */
099:            public int getMaxFieldSize() throws SQLException {
100:                validateConnection();
101:
102:                try {
103:                    return _statement.getMaxFieldSize();
104:                } catch (SQLException sqlException) {
105:                    processSQLException(sqlException);
106:                }
107:
108:                return Integer.MIN_VALUE;
109:            }
110:
111:            /**
112:             * Delgates calls to the statement; SQLExceptions thrown from the statement
113:             * will cause an event to be fired on the connection pool listeners.
114:             *
115:             * @throws SQLException if an error occurs
116:             */
117:            public void setMaxFieldSize(int max) throws SQLException {
118:                validateConnection();
119:
120:                try {
121:                    _statement.setMaxFieldSize(max);
122:                } catch (SQLException sqlException) {
123:                    processSQLException(sqlException);
124:                }
125:            }
126:
127:            /**
128:             * Delgates calls to the statement; SQLExceptions thrown from the statement
129:             * will cause an event to be fired on the connection pool listeners.
130:             *
131:             * @throws SQLException if an error occurs
132:             */
133:            public int getMaxRows() throws SQLException {
134:                validateConnection();
135:
136:                try {
137:                    return _statement.getMaxRows();
138:                } catch (SQLException sqlException) {
139:                    processSQLException(sqlException);
140:                }
141:
142:                return Integer.MIN_VALUE;
143:            }
144:
145:            /**
146:             * Delgates calls to the statement; SQLExceptions thrown from the statement
147:             * will cause an event to be fired on the connection pool listeners.
148:             *
149:             * @throws SQLException if an error occurs
150:             */
151:            public void setMaxRows(int max) throws SQLException {
152:                validateConnection();
153:
154:                try {
155:                    _statement.setMaxRows(max);
156:                } catch (SQLException sqlException) {
157:                    processSQLException(sqlException);
158:                }
159:            }
160:
161:            /**
162:             * Delgates calls to the statement; SQLExceptions thrown from the statement
163:             * will cause an event to be fired on the connection pool listeners.
164:             *
165:             * @throws SQLException if an error occurs
166:             */
167:            public void setEscapeProcessing(boolean enable) throws SQLException {
168:                validateConnection();
169:
170:                try {
171:                    _statement.setEscapeProcessing(enable);
172:                } catch (SQLException sqlException) {
173:                    processSQLException(sqlException);
174:                }
175:            }
176:
177:            /**
178:             * Delgates calls to the statement; SQLExceptions thrown from the statement
179:             * will cause an event to be fired on the connection pool listeners.
180:             *
181:             * @throws SQLException if an error occurs
182:             */
183:            public int getQueryTimeout() throws SQLException {
184:                validateConnection();
185:
186:                try {
187:                    return _statement.getQueryTimeout();
188:                } catch (SQLException sqlException) {
189:                    processSQLException(sqlException);
190:                }
191:
192:                return Integer.MIN_VALUE;
193:            }
194:
195:            /**
196:             * Delgates calls to the statement; SQLExceptions thrown from the statement
197:             * will cause an event to be fired on the connection pool listeners.
198:             *
199:             * @throws SQLException if an error occurs
200:             */
201:            public void setQueryTimeout(int seconds) throws SQLException {
202:                validateConnection();
203:
204:                try {
205:                    _statement.setQueryTimeout(seconds);
206:                } catch (SQLException sqlException) {
207:                    processSQLException(sqlException);
208:                }
209:            }
210:
211:            /**
212:             * Delgates calls to the statement; SQLExceptions thrown from the statement
213:             * will cause an event to be fired on the connection pool listeners.
214:             *
215:             * @throws SQLException if an error occurs
216:             */
217:            public void cancel() throws SQLException {
218:                validateConnection();
219:
220:                try {
221:                    _statement.cancel();
222:                } catch (SQLException sqlException) {
223:                    processSQLException(sqlException);
224:                }
225:            }
226:
227:            /**
228:             * Delgates calls to the statement; SQLExceptions thrown from the statement
229:             * will cause an event to be fired on the connection pool listeners.
230:             *
231:             * @throws SQLException if an error occurs
232:             */
233:            public SQLWarning getWarnings() throws SQLException {
234:                validateConnection();
235:
236:                try {
237:                    return _statement.getWarnings();
238:                } catch (SQLException sqlException) {
239:                    processSQLException(sqlException);
240:                }
241:
242:                return null;
243:            }
244:
245:            /**
246:             * Delgates calls to the statement; SQLExceptions thrown from the statement
247:             * will cause an event to be fired on the connection pool listeners.
248:             *
249:             * @throws SQLException if an error occurs
250:             */
251:            public void clearWarnings() throws SQLException {
252:                validateConnection();
253:
254:                try {
255:                    _statement.clearWarnings();
256:                } catch (SQLException sqlException) {
257:                    processSQLException(sqlException);
258:                }
259:            }
260:
261:            /**
262:             * Delgates calls to the statement; SQLExceptions thrown from the statement
263:             * will cause an event to be fired on the connection pool listeners.
264:             *
265:             * @throws SQLException if an error occurs
266:             */
267:            public void setCursorName(String name) throws SQLException {
268:                validateConnection();
269:
270:                try {
271:                    _statement.setCursorName(name);
272:                } catch (SQLException sqlException) {
273:                    processSQLException(sqlException);
274:                }
275:            }
276:
277:            /**
278:             * Delgates calls to the statement; SQLExceptions thrown from the statement
279:             * will cause an event to be fired on the connection pool listeners.
280:             *
281:             * @throws SQLException if an error occurs
282:             */
283:            public boolean execute(String sql) throws SQLException {
284:                validateConnection();
285:
286:                try {
287:                    return _statement.execute(sql);
288:                } catch (SQLException sqlException) {
289:                    processSQLException(sqlException);
290:                }
291:
292:                return false;
293:            }
294:
295:            /**
296:             * Delgates calls to the statement; SQLExceptions thrown from the statement
297:             * will cause an event to be fired on the connection pool listeners.
298:             *
299:             * @throws SQLException if an error occurs
300:             */
301:            public ResultSet getResultSet() throws SQLException {
302:                validateConnection();
303:
304:                try {
305:                    return _statement.getResultSet();
306:                } catch (SQLException sqlException) {
307:                    processSQLException(sqlException);
308:                }
309:
310:                return null;
311:            }
312:
313:            /**
314:             * Delgates calls to the statement; SQLExceptions thrown from the statement
315:             * will cause an event to be fired on the connection pool listeners.
316:             *
317:             * @throws SQLException if an error occurs
318:             */
319:            public int getUpdateCount() throws SQLException {
320:                validateConnection();
321:
322:                try {
323:                    return _statement.getUpdateCount();
324:                } catch (SQLException sqlException) {
325:                    processSQLException(sqlException);
326:                }
327:
328:                return Integer.MIN_VALUE;
329:            }
330:
331:            /**
332:             * Delgates calls to the statement; SQLExceptions thrown from the statement
333:             * will cause an event to be fired on the connection pool listeners.
334:             *
335:             * @throws SQLException if an error occurs
336:             */
337:            public boolean getMoreResults() throws SQLException {
338:                validateConnection();
339:
340:                try {
341:                    return _statement.getMoreResults();
342:                } catch (SQLException sqlException) {
343:                    processSQLException(sqlException);
344:                }
345:
346:                return false;
347:            }
348:
349:            /**
350:             * Delgates calls to the statement; SQLExceptions thrown from the statement
351:             * will cause an event to be fired on the connection pool listeners.
352:             *
353:             * @throws SQLException if an error occurs
354:             */
355:            public void setFetchDirection(int direction) throws SQLException {
356:                validateConnection();
357:
358:                try {
359:                    _statement.setFetchDirection(direction);
360:                } catch (SQLException sqlException) {
361:                    processSQLException(sqlException);
362:                }
363:            }
364:
365:            /**
366:             * Delgates calls to the statement; SQLExceptions thrown from the statement
367:             * will cause an event to be fired on the connection pool listeners.
368:             *
369:             * @throws SQLException if an error occurs
370:             */
371:            public int getFetchDirection() throws SQLException {
372:                validateConnection();
373:
374:                try {
375:                    return _statement.getFetchDirection();
376:                } catch (SQLException sqlException) {
377:                    processSQLException(sqlException);
378:                }
379:
380:                return Integer.MIN_VALUE;
381:            }
382:
383:            /**
384:             * Delgates calls to the statement; SQLExceptions thrown from the statement
385:             * will cause an event to be fired on the connection pool listeners.
386:             *
387:             * @throws SQLException if an error occurs
388:             */
389:            public void setFetchSize(int rows) throws SQLException {
390:                validateConnection();
391:
392:                try {
393:                    _statement.setFetchSize(rows);
394:                } catch (SQLException sqlException) {
395:                    processSQLException(sqlException);
396:                }
397:            }
398:
399:            /**
400:             * Delgates calls to the statement; SQLExceptions thrown from the statement
401:             * will cause an event to be fired on the connection pool listeners.
402:             *
403:             * @throws SQLException if an error occurs
404:             */
405:            public int getFetchSize() throws SQLException {
406:                validateConnection();
407:
408:                try {
409:                    return _statement.getFetchSize();
410:                } catch (SQLException sqlException) {
411:                    processSQLException(sqlException);
412:                }
413:
414:                return Integer.MIN_VALUE;
415:            }
416:
417:            /**
418:             * Delgates calls to the statement; SQLExceptions thrown from the statement
419:             * will cause an event to be fired on the connection pool listeners.
420:             *
421:             * @throws SQLException if an error occurs
422:             */
423:            public int getResultSetConcurrency() throws SQLException {
424:                validateConnection();
425:
426:                try {
427:                    return _statement.getResultSetConcurrency();
428:                } catch (SQLException sqlException) {
429:                    processSQLException(sqlException);
430:                }
431:
432:                return Integer.MIN_VALUE;
433:            }
434:
435:            /**
436:             * Delgates calls to the statement; SQLExceptions thrown from the statement
437:             * will cause an event to be fired on the connection pool listeners.
438:             *
439:             * @throws SQLException if an error occurs
440:             */
441:            public int getResultSetType() throws SQLException {
442:                validateConnection();
443:
444:                try {
445:                    return _statement.getResultSetType();
446:                } catch (SQLException sqlException) {
447:                    processSQLException(sqlException);
448:                }
449:
450:                return Integer.MIN_VALUE;
451:            }
452:
453:            /**
454:             * Delgates calls to the statement; SQLExceptions thrown from the statement
455:             * will cause an event to be fired on the connection pool listeners.
456:             *
457:             * @throws SQLException if an error occurs
458:             */
459:            public void addBatch(String sql) throws SQLException {
460:                validateConnection();
461:
462:                try {
463:                    _statement.addBatch(sql);
464:                } catch (SQLException sqlException) {
465:                    processSQLException(sqlException);
466:                }
467:            }
468:
469:            /**
470:             * Delgates calls to the statement; SQLExceptions thrown from the statement
471:             * will cause an event to be fired on the connection pool listeners.
472:             *
473:             * @throws SQLException if an error occurs
474:             */
475:            public void clearBatch() throws SQLException {
476:                validateConnection();
477:
478:                try {
479:                    _statement.clearBatch();
480:                } catch (SQLException sqlException) {
481:                    processSQLException(sqlException);
482:                }
483:            }
484:
485:            /**
486:             * Delgates calls to the statement; SQLExceptions thrown from the statement
487:             * will cause an event to be fired on the connection pool listeners.
488:             *
489:             * @throws SQLException if an error occurs
490:             */
491:            public int[] executeBatch() throws SQLException {
492:                validateConnection();
493:
494:                try {
495:                    return _statement.executeBatch();
496:                } catch (SQLException sqlException) {
497:                    processSQLException(sqlException);
498:                }
499:
500:                return null;
501:            }
502:
503:            /**
504:             * Delgates calls to the statement; SQLExceptions thrown from the statement
505:             * will cause an event to be fired on the connection pool listeners.
506:             *
507:             * @throws SQLException if an error occurs
508:             */
509:            public Connection getConnection() throws SQLException {
510:                validateConnection();
511:
512:                try {
513:                    return _statement.getConnection();
514:                } catch (SQLException sqlException) {
515:                    processSQLException(sqlException);
516:                }
517:
518:                return null;
519:            }
520:
521:            /**
522:             * Delgates calls to the statement; SQLExceptions thrown from the statement
523:             * will cause an event to be fired on the connection pool listeners.
524:             *
525:             * @throws SQLException if an error occurs
526:             */
527:            public boolean getMoreResults(int current) throws SQLException {
528:                validateConnection();
529:
530:                try {
531:                    return _statement.getMoreResults(current);
532:                } catch (SQLException sqlException) {
533:                    processSQLException(sqlException);
534:                }
535:
536:                return false;
537:            }
538:
539:            /**
540:             * Delgates calls to the statement; SQLExceptions thrown from the statement
541:             * will cause an event to be fired on the connection pool listeners.
542:             *
543:             * @throws SQLException if an error occurs
544:             */
545:            public ResultSet getGeneratedKeys() throws SQLException {
546:                validateConnection();
547:
548:                try {
549:                    return _statement.getGeneratedKeys();
550:                } catch (SQLException sqlException) {
551:                    processSQLException(sqlException);
552:                }
553:
554:                return null;
555:            }
556:
557:            /**
558:             * Delgates calls to the statement; SQLExceptions thrown from the statement
559:             * will cause an event to be fired on the connection pool listeners.
560:             *
561:             * @throws SQLException if an error occurs
562:             */
563:            public int executeUpdate(String sql, int autoGeneratedKeys)
564:                    throws SQLException {
565:                validateConnection();
566:
567:                try {
568:                    return _statement.executeUpdate(sql, autoGeneratedKeys);
569:                } catch (SQLException sqlException) {
570:                    processSQLException(sqlException);
571:                }
572:
573:                return Integer.MIN_VALUE;
574:            }
575:
576:            /**
577:             * Delgates calls to the statement; SQLExceptions thrown from the statement
578:             * will cause an event to be fired on the connection pool listeners.
579:             *
580:             * @throws SQLException if an error occurs
581:             */
582:            public int executeUpdate(String sql, int[] columnIndexes)
583:                    throws SQLException {
584:                validateConnection();
585:
586:                try {
587:                    return _statement.executeUpdate(sql, columnIndexes);
588:                } catch (SQLException sqlException) {
589:                    processSQLException(sqlException);
590:                }
591:
592:                return Integer.MIN_VALUE;
593:            }
594:
595:            /**
596:             * Delgates calls to the statement; SQLExceptions thrown from the statement
597:             * will cause an event to be fired on the connection pool listeners.
598:             *
599:             * @throws SQLException if an error occurs
600:             */
601:            public int executeUpdate(String sql, String[] columnNames)
602:                    throws SQLException {
603:                validateConnection();
604:
605:                try {
606:                    return _statement.executeUpdate(sql, columnNames);
607:                } catch (SQLException sqlException) {
608:                    processSQLException(sqlException);
609:                }
610:
611:                return Integer.MIN_VALUE;
612:            }
613:
614:            /**
615:             * Delgates calls to the statement; SQLExceptions thrown from the statement
616:             * will cause an event to be fired on the connection pool listeners.
617:             *
618:             * @throws SQLException if an error occurs
619:             */
620:            public boolean execute(String sql, int autoGeneratedKeys)
621:                    throws SQLException {
622:                validateConnection();
623:
624:                try {
625:                    return _statement.execute(sql, autoGeneratedKeys);
626:                } catch (SQLException sqlException) {
627:                    processSQLException(sqlException);
628:                }
629:
630:                return false;
631:            }
632:
633:            /**
634:             * Delgates calls to the statement; SQLExceptions thrown from the statement
635:             * will cause an event to be fired on the connection pool listeners.
636:             *
637:             * @throws SQLException if an error occurs
638:             */
639:            public boolean execute(String sql, int[] columnIndexes)
640:                    throws SQLException {
641:                validateConnection();
642:
643:                try {
644:                    return _statement.execute(sql, columnIndexes);
645:                } catch (SQLException sqlException) {
646:                    processSQLException(sqlException);
647:                }
648:
649:                return false;
650:            }
651:
652:            /**
653:             * Delgates calls to the statement; SQLExceptions thrown from the statement
654:             * will cause an event to be fired on the connection pool listeners.
655:             *
656:             * @throws SQLException if an error occurs
657:             */
658:            public boolean execute(String sql, String[] columnNames)
659:                    throws SQLException {
660:                validateConnection();
661:
662:                try {
663:                    return _statement.execute(sql, columnNames);
664:                } catch (SQLException sqlException) {
665:                    processSQLException(sqlException);
666:                }
667:
668:                return false;
669:            }
670:
671:            /**
672:             * Delgates calls to the statement; SQLExceptions thrown from the statement
673:             * will cause an event to be fired on the connection pool listeners.
674:             *
675:             * @throws SQLException if an error occurs
676:             */
677:            public int getResultSetHoldability() throws SQLException {
678:                validateConnection();
679:
680:                try {
681:                    return _statement.getResultSetHoldability();
682:                } catch (SQLException sqlException) {
683:                    processSQLException(sqlException);
684:                }
685:
686:                return Integer.MIN_VALUE;
687:            }
688:
689:            /**
690:             * Validates the connection state.
691:             */
692:            protected void validateConnection() throws SQLException {
693:                if (_connection.isClosed()) {
694:                    throw new SQLException(Messages
695:                            .get("error.conproxy.noconn"), "HY010");
696:                }
697:            }
698:
699:            /**
700:             * Processes SQLExceptions.
701:             */
702:            protected void processSQLException(SQLException sqlException)
703:                    throws SQLException {
704:                _connection.processSQLException(sqlException);
705:
706:                throw sqlException;
707:            }
708:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.