Source Code Cross Referenced for Commander.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » dbscript » 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 » proxool » org.logicalcobwebs.dbscript 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.dbscript;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import java.sql.Connection;
012:        import java.sql.SQLException;
013:        import java.sql.Statement;
014:
015:        /**
016:         * A thread that can run a single command many times.
017:         *
018:         * @version $Revision: 1.7 $, $Date: 2006/01/18 14:40:05 $
019:         * @author Bill Horsman (bill@logicalcobwebs.co.uk)
020:         * @author $Author: billhorsman $ (current maintainer)
021:         * @since Proxool 0.5
022:         */
023:        class Commander implements  Runnable {
024:
025:            private static final Log LOG = LogFactory.getLog(Commander.class);
026:
027:            private ConnectionAdapterIF adapter;
028:
029:            private CommandIF command;
030:
031:            private CommandFilterIF commandFilter;
032:
033:            private boolean finished = false;
034:
035:            public Commander(ConnectionAdapterIF adapter, CommandIF commandIF,
036:                    CommandFilterIF commandFilter) {
037:                this .adapter = adapter;
038:                this .command = commandIF;
039:                this .commandFilter = commandFilter;
040:            }
041:
042:            public void run() {
043:
044:                try {
045:                    boolean keepGoing = true;
046:                    for (int i = 0; i < command.getLoops(); i++) {
047:
048:                        Connection connection = null;
049:
050:                        try {
051:                            connection = adapter.getConnection();
052:                            boolean executeCommand = true;
053:                            if (commandFilter != null) {
054:                                executeCommand = commandFilter.beforeCommand(
055:                                        connection, command);
056:                            }
057:
058:                            if (executeCommand) {
059:                                execute(connection, command.getSql());
060:                            }
061:
062:                            if (commandFilter != null) {
063:                                commandFilter.afterCommand(connection, command);
064:                            }
065:
066:                        } catch (SQLException e) {
067:                            if (commandFilter != null
068:                                    && !commandFilter
069:                                            .catchException(command, e)) {
070:                                keepGoing = false;
071:                            }
072:                            if (command.isIgnoreException()) {
073:                                // Silent
074:                            } else if (command.isLogException()) {
075:                                LOG.debug("Ignoring exception in "
076:                                        + command.getName(), e);
077:                            } else {
078:                                LOG.error("Stopping command "
079:                                        + command.getName(), e);
080:                                keepGoing = false;
081:                            }
082:                        } finally {
083:                            try {
084:                                adapter.closeConnection(connection);
085:                            } catch (SQLException e) {
086:                                LOG.error("Closing connection for "
087:                                        + Thread.currentThread().getName(), e);
088:                            }
089:                        }
090:
091:                        if (!keepGoing) {
092:                            break;
093:                        }
094:
095:                        // Give other threads a chance. (Hoping this will increase the chances
096:                        // of some sort of conflict)
097:                        Thread.yield();
098:                    }
099:                } finally {
100:                    finished = true;
101:                }
102:
103:            }
104:
105:            /**
106:             * Is the thread running
107:             * @return true if it's finished, else false
108:             */
109:            protected boolean isFinished() {
110:                return finished;
111:            }
112:
113:            /**
114:             * Execute and SQL statement
115:             * @param connection used to execute statement
116:             * @param sql the SQL to perform
117:             * @throws java.sql.SQLException if anything goes wrong
118:             */
119:            private static final void execute(Connection connection, String sql)
120:                    throws SQLException {
121:                Statement statement = null;
122:                try {
123:                    statement = connection.createStatement();
124:                    statement.execute(sql);
125:                } finally {
126:                    if (statement != null) {
127:                        try {
128:                            if (statement != null) {
129:                                statement.close();
130:                            }
131:                        } catch (SQLException e) {
132:                            LOG.error("Couldn't close statement", e);
133:                        }
134:                    }
135:                }
136:            }
137:
138:        }
139:
140:        /*
141:         Revision history:
142:         $Log: Commander.java,v $
143:         Revision 1.7  2006/01/18 14:40:05  billhorsman
144:         Unbundled Jakarta's Commons Logging.
145:
146:         Revision 1.6  2003/03/03 11:12:03  billhorsman
147:         fixed licence
148:
149:         Revision 1.5  2003/02/19 15:14:20  billhorsman
150:         fixed copyright (copy and paste error,
151:         not copyright change)
152:
153:         Revision 1.4  2003/02/06 17:41:02  billhorsman
154:         now uses imported logging
155:
156:         Revision 1.3  2003/01/15 00:08:15  billhorsman
157:         check for commandFilter existence to avoid unnecessary
158:         log clutter
159:
160:         Revision 1.2  2002/11/09 15:59:18  billhorsman
161:         fix doc
162:
163:         Revision 1.1  2002/11/09 14:45:07  billhorsman
164:         now threaded and better exception handling
165:
166:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.