Source Code Cross Referenced for AutoloadedDriver.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » jdbc » 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 DBMS » db derby 10.2 » org.apache.derby.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.jdbc.AutoloadedDriver
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.jdbc;
023:
024:        import java.sql.DriverManager;
025:        import java.sql.Driver;
026:        import java.sql.Connection;
027:        import java.sql.DriverPropertyInfo;
028:        import java.sql.SQLException;
029:
030:        import java.io.PrintStream;
031:        import java.util.Properties;
032:
033:        import org.apache.derby.iapi.reference.MessageId;
034:        import org.apache.derby.iapi.reference.Attribute;
035:        import org.apache.derby.iapi.services.i18n.MessageService;
036:        import org.apache.derby.iapi.jdbc.JDBCBoot;
037:
038:        /**
039:         This is the dummy driver which is autoloaded under JDBC4 and registered with
040:         the DriverManager. Loading this class will NOT automatically boot the Derby engine.
041:         Instead, the engine boots lazily when you ask for a
042:         Connection. Alternatively, you can force the engine to boot as follows:
043:
044:         <PRE>
045:         Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
046:
047:         // or
048:
049:         new org.apache.derby.jdbc.EmbeddedDriver();
050:
051:        
052:         </PRE>
053:         */
054:        public class AutoloadedDriver implements  Driver {
055:            // This flag is set if the engine is forcibly brought down.
056:            private static boolean _engineForcedDown = false;
057:
058:            //
059:            // This is the driver that's specific to the JDBC level we're running at.
060:            // It's the module which boots the whole Derby engine.
061:            //
062:            private static Driver _driverModule;
063:
064:            static {
065:                try {
066:                    DriverManager.registerDriver(new AutoloadedDriver());
067:                } catch (SQLException se) {
068:                    String message = MessageService.getTextMessage(
069:                            MessageId.JDBC_DRIVER_REGISTER_ERROR, se
070:                                    .getMessage());
071:
072:                    throw new IllegalStateException(message);
073:                }
074:            }
075:
076:            /*
077:             ** Methods from java.sql.Driver.
078:             */
079:            /**
080:            	Accept anything that starts with <CODE>jdbc:derby:</CODE>.
081:            	@exception SQLException if a database-access error occurs.
082:            @see java.sql.Driver
083:             */
084:            public boolean acceptsURL(String url) throws SQLException {
085:
086:                //
087:                // We don't want to accidentally boot the engine just because
088:                // the application is looking for a connection from some other
089:                // driver.
090:                //
091:                return (isBooted() && InternalDriver
092:                        .embeddedDriverAcceptsURL(url));
093:            }
094:
095:            /**
096:            	Connect to the URL if possible
097:            	@exception SQLException illegal url or problem with connectiong
098:            @see java.sql.Driver
099:             */
100:            public Connection connect(String url, Properties info)
101:                    throws SQLException {
102:                //
103:                // This pretty piece of logic compensates for the following behavior
104:                // of the DriverManager: When asked to get a Connection, the
105:                // DriverManager cycles through all of its autoloaded drivers, looking
106:                // for one which will return a Connection. Without this pretty logic,
107:                // the embedded driver module will be booted by any request for
108:                // a connection which cannot be satisfied by drivers ahead of us
109:                // in the list.
110:                if (!InternalDriver.embeddedDriverAcceptsURL(url)) {
111:                    return null;
112:                }
113:
114:                return getDriverModule().connect(url, info);
115:            }
116:
117:            /**
118:             * Returns an array of DriverPropertyInfo objects describing possible properties.
119:              @exception SQLException if a database-access error occurs.
120:              @see java.sql.Driver
121:             */
122:            public DriverPropertyInfo[] getPropertyInfo(String url,
123:                    Properties info) throws SQLException {
124:                return getDriverModule().getPropertyInfo(url, info);
125:            }
126:
127:            /**
128:             * Returns the driver's major version number. 
129:             @see java.sql.Driver
130:             */
131:            public int getMajorVersion() {
132:                try {
133:                    return (getDriverModule().getMajorVersion());
134:                } catch (SQLException se) {
135:                    return 0;
136:                }
137:            }
138:
139:            /**
140:             * Returns the driver's minor version number.
141:             @see java.sql.Driver
142:             */
143:            public int getMinorVersion() {
144:                try {
145:                    return (getDriverModule().getMinorVersion());
146:                } catch (SQLException se) {
147:                    return 0;
148:                }
149:            }
150:
151:            /**
152:             * Report whether the Driver is a genuine JDBC COMPLIANT (tm) driver.
153:               @see java.sql.Driver
154:             */
155:            public boolean jdbcCompliant() {
156:                try {
157:                    return (getDriverModule().jdbcCompliant());
158:                } catch (SQLException se) {
159:                    return false;
160:                }
161:            }
162:
163:            ///////////////////////////////////////////////////////////////////////
164:            //
165:            // Support for booting and shutting down the engine.
166:            //
167:            ///////////////////////////////////////////////////////////////////////
168:
169:            /*
170:             ** Retrieve the driver which is specific to our JDBC level.
171:             ** We defer real work to this specific driver.
172:             */
173:            public static Driver getDriverModule() throws SQLException {
174:
175:                if (_engineForcedDown) {
176:                    // Driver not registered 
177:                    throw new SQLException(
178:                            MessageService
179:                                    .getTextMessage(MessageId.CORE_JDBC_DRIVER_UNREGISTERED));
180:                }
181:
182:                if (!isBooted()) {
183:                    EmbeddedDriver.boot();
184:                }
185:
186:                return _driverModule;
187:            }
188:
189:            /*
190:             ** Record which driver module actually booted.
191:             */
192:            protected static void registerDriverModule(Driver driver) {
193:                _driverModule = driver;
194:                _engineForcedDown = false;
195:            }
196:
197:            /*
198:             ** Unregister the driver. This happens when the engine is
199:             ** forcibly shut down.
200:             */
201:            protected static void unregisterDriverModule() {
202:                _driverModule = null;
203:                _engineForcedDown = true;
204:            }
205:
206:            /*
207:             ** Return true if the engine has been booted.
208:             */
209:            private static boolean isBooted() {
210:                return (_driverModule != null);
211:            }
212:
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.