Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / jdbc / AutoloadedDriver.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
new file mode 100644 (file)
index 0000000..2cdc2d2
--- /dev/null
@@ -0,0 +1,229 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.jdbc.AutoloadedDriver\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.jdbc;\r
+\r
+import java.sql.DriverManager;\r
+import java.sql.Driver;\r
+import java.sql.Connection;\r
+import java.sql.DriverPropertyInfo;\r
+import java.sql.SQLException;\r
+import java.sql.SQLFeatureNotSupportedException;\r
+import java.io.PrintStream;\r
+import java.util.Properties;\r
+import java.util.logging.Logger;\r
+\r
+import org.apache.derby.iapi.reference.MessageId;\r
+import org.apache.derby.iapi.reference.Attribute;\r
+import org.apache.derby.iapi.services.i18n.MessageService;\r
+import org.apache.derby.iapi.jdbc.JDBCBoot;\r
+\r
+\r
+/**\r
+   This is the dummy driver which is registered with the DriverManager and\r
+   which is autoloaded by JDBC4. Loading this class will NOT automatically boot the Derby engine.\r
+   Instead, the engine boots lazily when you ask for a\r
+   Connection. Alternatively, you can force the engine to boot as follows:\r
+\r
+        <PRE>\r
+        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();\r
+\r
+        // or\r
+\r
+     new org.apache.derby.jdbc.EmbeddedDriver();\r
+\r
+    \r
+       </PRE>\r
+*/\r
+public class AutoloadedDriver implements Driver\r
+{\r
+       // This flag is set if the engine is forcibly brought down.\r
+       private static  boolean _engineForcedDown = false;\r
+       \r
+       //\r
+       // This is the driver that's specific to the JDBC level we're running at.\r
+       // It's the module which boots the whole Derby engine.\r
+       //\r
+       private static  Driver  _driverModule;\r
+       \r
+       static\r
+       {\r
+               try {\r
+                       DriverManager.registerDriver( new AutoloadedDriver() );\r
+               }\r
+               catch (SQLException se)\r
+               {\r
+                       String  message = MessageService.getTextMessage\r
+                               (MessageId.JDBC_DRIVER_REGISTER_ERROR, se.getMessage() );\r
+\r
+                       throw new IllegalStateException( message );\r
+               }\r
+       }\r
+\r
+       /*\r
+       ** Methods from java.sql.Driver.\r
+       */\r
+       /**\r
+               Accept anything that starts with <CODE>jdbc:derby:</CODE>.\r
+               @exception SQLException if a database-access error occurs.\r
+    @see java.sql.Driver\r
+       */\r
+       public boolean acceptsURL(String url) throws SQLException {\r
+\r
+               //\r
+               // We don't want to accidentally boot the engine just because\r
+               // the application is looking for a connection from some other\r
+               // driver.\r
+               //\r
+               return !_engineForcedDown && InternalDriver.embeddedDriverAcceptsURL(url);\r
+       }\r
+\r
+   \r
+       /**\r
+               Connect to the URL if possible\r
+               @exception SQLException illegal url or problem with connectiong\r
+    @see java.sql.Driver\r
+  */\r
+       public Connection connect(String url, Properties info)\r
+               throws SQLException\r
+       {\r
+               //\r
+               // This pretty piece of logic compensates for the following behavior\r
+               // of the DriverManager: When asked to get a Connection, the\r
+               // DriverManager cycles through all of its autoloaded drivers, looking\r
+               // for one which will return a Connection. Without this pretty logic,\r
+               // the embedded driver module will be booted by any request for\r
+               // a connection which cannot be satisfied by drivers ahead of us\r
+               // in the list.\r
+               if (!InternalDriver.embeddedDriverAcceptsURL(url)) { return null; }\r
+\r
+               return getDriverModule().connect(url, info);\r
+       }\r
+\r
+  /**\r
+   * Returns an array of DriverPropertyInfo objects describing possible properties.\r
+    @exception SQLException if a database-access error occurs.\r
+    @see java.sql.Driver\r
+   */\r
+       public  DriverPropertyInfo[] getPropertyInfo(String url, Properties info)\r
+               throws SQLException\r
+       {\r
+               return getDriverModule().getPropertyInfo(url, info);\r
+       }\r
+\r
+    /**\r
+     * Returns the driver's major version number. \r
+     @see java.sql.Driver\r
+     */\r
+       public int getMajorVersion() {\r
+               try {\r
+                       return (getDriverModule().getMajorVersion());\r
+               }\r
+               catch (SQLException se) {\r
+                       return 0;\r
+               }\r
+       }\r
+    /**\r
+     * Returns the driver's minor version number.\r
+     @see java.sql.Driver\r
+     */\r
+       public int getMinorVersion() {\r
+               try {\r
+                       return (getDriverModule().getMinorVersion());\r
+               }\r
+               catch (SQLException se) {\r
+                       return 0;\r
+               }\r
+       }\r
+\r
+  /**\r
+   * Report whether the Driver is a genuine JDBC COMPLIANT (tm) driver.\r
+     @see java.sql.Driver\r
+   */\r
+       public boolean jdbcCompliant() {\r
+               try {\r
+                       return (getDriverModule().jdbcCompliant());\r
+               }\r
+               catch (SQLException se) {\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       ///////////////////////////////////////////////////////////////////////\r
+       //\r
+       // Support for booting and shutting down the engine.\r
+       //\r
+       ///////////////////////////////////////////////////////////////////////\r
+\r
+       /*\r
+       ** Retrieve the driver which is specific to our JDBC level.\r
+       ** We defer real work to this specific driver.\r
+       */\r
+       static  Driver getDriverModule() throws SQLException {\r
+\r
+               if ( _engineForcedDown )\r
+               {\r
+                       // Driver not registered \r
+                       throw new SQLException\r
+                               (MessageService.getTextMessage(MessageId.CORE_JDBC_DRIVER_UNREGISTERED));\r
+               }\r
+\r
+               if ( !isBooted() ) { EmbeddedDriver.boot(); }\r
+\r
+               return _driverModule;\r
+       }\r
+       \r
+       /*\r
+       ** Record which driver module actually booted.\r
+       */\r
+       static  void    registerDriverModule( Driver driver )\r
+       {\r
+               _driverModule = driver;\r
+               _engineForcedDown = false;\r
+       }\r
+       \r
+       /*\r
+       ** Unregister the driver. This happens when the engine is\r
+       ** forcibly shut down.\r
+       */\r
+       static  void    unregisterDriverModule()\r
+       {\r
+               _driverModule = null;\r
+               _engineForcedDown = true;\r
+       }\r
+       \r
+\r
+       /*\r
+       ** Return true if the engine has been booted.\r
+       */\r
+       private static  boolean isBooted()\r
+       {\r
+               return ( _driverModule != null );\r
+       }\r
+\r
+\r
+       public Logger getParentLogger() throws SQLFeatureNotSupportedException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+       \r
+}\r
+\r