--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.jdbc.EmbeddedDriver\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
+ The embedded JDBC driver (Type 4) for Derby.\r
+ <P>\r
+ The driver automatically supports the correct JDBC specification version\r
+ for the Java Virtual Machine's environment.\r
+ <UL>\r
+ <LI> JDBC 4.0 - Java SE 6\r
+ <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0\r
+ </UL>\r
+\r
+ <P>\r
+ Loading this JDBC driver boots the database engine\r
+ within the same Java virtual machine.\r
+ <P>\r
+ The correct code to load the Derby engine using this driver is\r
+ (with approriate try/catch blocks):\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
+ When loaded in this way, the class boots the actual JDBC driver indirectly.\r
+ The JDBC specification recommends the Class.ForName method without the .newInstance()\r
+ method call, but adding the newInstance() guarantees\r
+ that Derby will be booted on any Java Virtual Machine.\r
+\r
+ <P>\r
+ Note that you do not need to manually load the driver this way if you are\r
+ running on Jave SE 6 or later. In that environment, the driver will be\r
+ automatically loaded for you when your application requests a connection to\r
+ a Derby database.\r
+ <P>\r
+ Any initial error messages are placed in the PrintStream\r
+ supplied by the DriverManager. If the PrintStream is null error messages are\r
+ sent to System.err. Once the Derby engine has set up an error\r
+ logging facility (by default to derby.log) all subsequent messages are sent to it.\r
+ <P>\r
+ By convention, the class used in the Class.forName() method to\r
+ boot a JDBC driver implements java.sql.Driver.\r
+\r
+ This class is not the actual JDBC driver that gets registered with\r
+ the Driver Manager. It proxies requests to the registered Derby JDBC driver.\r
+\r
+ @see java.sql.DriverManager\r
+ @see java.sql.DriverManager#getLogStream\r
+ @see java.sql.Driver\r
+ @see java.sql.SQLException\r
+*/\r
+\r
+public class EmbeddedDriver implements Driver {\r
+\r
+ static {\r
+\r
+ EmbeddedDriver.boot();\r
+ }\r
+\r
+ private AutoloadedDriver _autoloadedDriver;\r
+ \r
+ // Boot from the constructor as well to ensure that\r
+ // Class.forName(...).newInstance() reboots Derby \r
+ // after a shutdown inside the same JVM.\r
+ public EmbeddedDriver() {\r
+ EmbeddedDriver.boot();\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
+ return getDriverModule().acceptsURL(url);\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
+ 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
+ /**\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
+ * Lookup the booted driver module appropriate to our JDBC level.\r
+ */\r
+ private Driver getDriverModule()\r
+ throws SQLException\r
+ {\r
+ return AutoloadedDriver.getDriverModule();\r
+ }\r
+\r
+\r
+ /*\r
+ ** Find the appropriate driver for our JDBC level and boot it.\r
+ * This is package protected so that AutoloadedDriver can call it.\r
+ */\r
+ static void boot() {\r
+ PrintStream ps = DriverManager.getLogStream();\r
+\r
+ if (ps == null)\r
+ ps = System.err;\r
+\r
+ new JDBCBoot().boot(Attribute.PROTOCOL, ps);\r
+ }\r
+\r
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+\r
+ \r
+}\r