Source Code Cross Referenced for ScriptFacade.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.xml.sax.ErrorHandler;
009:        import org.xml.sax.SAXParseException;
010:        import org.xml.sax.SAXException;
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:        import org.logicalcobwebs.proxool.ProxoolException;
014:
015:        import javax.xml.parsers.SAXParserFactory;
016:        import javax.xml.parsers.SAXParser;
017:        import javax.xml.parsers.FactoryConfigurationError;
018:        import javax.xml.parsers.ParserConfigurationException;
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.sql.SQLException;
022:
023:        /**
024:         * Allows you to run scripts from file.
025:         *
026:         * @version $Revision: 1.12 $, $Date: 2006/01/18 14:40:05 $
027:         * @author Bill Horsman (bill@logicalcobwebs.co.uk)
028:         * @author $Author: billhorsman $ (current maintainer)
029:         * @since Proxool 0.5
030:         */
031:        public class ScriptFacade {
032:
033:            private static final Log LOG = LogFactory
034:                    .getLog(ScriptFacade.class);
035:
036:            /**
037:             * Run the script using the appropriate handler
038:             * @param scriptLocation the path to the file that contains the script XML
039:             * @param adapter so we know where to get {@link java.sql.Connection connections} from.
040:             */
041:            public static void runScript(String scriptLocation,
042:                    ConnectionAdapterIF adapter) {
043:                runScript(scriptLocation, adapter, null);
044:            }
045:
046:            /**
047:             * Run the script using the appropriate handler
048:             * @param scriptLocation the path to the file that contains the script XML
049:             * @param adapter so we know where to get {@link java.sql.Connection connections} from.
050:             * @param commandFilter allows you to filter which commands get run and do things to the {@link java.sql.Connection}
051:             */
052:            public static void runScript(String scriptLocation,
053:                    ConnectionAdapterIF adapter, CommandFilterIF commandFilter) {
054:
055:                File scriptFile = new File(scriptLocation);
056:                if (!scriptFile.canRead()) {
057:                    throw new RuntimeException("Can't read from file at "
058:                            + scriptFile.getAbsolutePath());
059:                }
060:
061:                try {
062:                    SAXParserFactory saxParserFactory = SAXParserFactory
063:                            .newInstance();
064:                    saxParserFactory.setValidating(false);
065:                    saxParserFactory.setNamespaceAware(true);
066:                    SAXParser saxParser = saxParserFactory.newSAXParser();
067:                    saxParser.getXMLReader().setFeature(
068:                            "http://xml.org/sax/features/namespaces", true);
069:                    saxParser.getXMLReader().setErrorHandler(
070:                            new ErrorHandler() {
071:                                public void warning(SAXParseException exception)
072:                                        throws SAXException {
073:                                    LOG.warn(exception.getLineNumber() + ":"
074:                                            + exception.getColumnNumber(),
075:                                            exception);
076:                                }
077:
078:                                public void error(SAXParseException exception)
079:                                        throws SAXException {
080:                                    LOG.error(exception.getLineNumber() + ":"
081:                                            + exception.getColumnNumber(),
082:                                            exception);
083:                                }
084:
085:                                public void fatalError(
086:                                        SAXParseException exception)
087:                                        throws SAXException {
088:                                    LOG.error(exception.getLineNumber() + ":"
089:                                            + exception.getColumnNumber(),
090:                                            exception);
091:                                }
092:                            });
093:
094:                    ScriptBuilder scriptBuilder = new ScriptBuilder();
095:                    saxParser.parse(scriptFile, scriptBuilder);
096:                    Script script = scriptBuilder.getScript();
097:
098:                    ScriptRunner.runScript(script, adapter, commandFilter);
099:
100:                } catch (FactoryConfigurationError factoryConfigurationError) {
101:                    LOG.error(factoryConfigurationError);
102:                } catch (ParserConfigurationException e) {
103:                    LOG.error("Problem running script " + scriptLocation, e);
104:                } catch (SAXException e) {
105:                    LOG.error("Problem running script " + scriptLocation, e);
106:                } catch (IOException e) {
107:                    LOG.error("Problem running script " + scriptLocation, e);
108:                } catch (SQLException e) {
109:                    LOG.error("Problem running script " + scriptLocation, e);
110:                } catch (ProxoolException e) {
111:                    LOG.error("Problem running script " + scriptLocation, e);
112:                }
113:
114:            }
115:
116:        }
117:
118:        /*
119:         Revision history:
120:         $Log: ScriptFacade.java,v $
121:         Revision 1.12  2006/01/18 14:40:05  billhorsman
122:         Unbundled Jakarta's Commons Logging.
123:
124:         Revision 1.11  2003/03/03 11:12:03  billhorsman
125:         fixed licence
126:
127:         Revision 1.10  2003/02/19 15:14:21  billhorsman
128:         fixed copyright (copy and paste error,
129:         not copyright change)
130:
131:         Revision 1.9  2003/02/06 17:41:02  billhorsman
132:         now uses imported logging
133:
134:         Revision 1.8  2003/01/17 00:38:12  billhorsman
135:         wide ranging changes to clarify use of alias and url -
136:         this has led to some signature changes (new exceptions
137:         thrown) on the ProxoolFacade API.
138:
139:         Revision 1.7  2002/11/13 20:23:35  billhorsman
140:         change method name, throw exceptions differently, trivial changes
141:
142:         Revision 1.6  2002/11/09 16:00:21  billhorsman
143:         fix doc
144:
145:         Revision 1.5  2002/11/07 19:08:54  billhorsman
146:         Fixed up tests a bit
147:
148:         Revision 1.4  2002/11/06 21:06:21  billhorsman
149:         Support for CommandFilterIF
150:
151:         Revision 1.3  2002/11/02 14:22:16  billhorsman
152:         Documentation
153:
154:         Revision 1.2  2002/11/02 13:57:34  billhorsman
155:         checkstyle
156:
157:         Revision 1.1  2002/11/02 11:29:53  billhorsman
158:         new script runner for testing
159:
160:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.