Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / jdbc / JDBCBoot.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/jdbc/JDBCBoot.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/jdbc/JDBCBoot.java
new file mode 100644 (file)
index 0000000..4022e36
--- /dev/null
@@ -0,0 +1,92 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.jdbc.JDBCBoot\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.iapi.jdbc;\r
+\r
+import org.apache.derby.iapi.reference.Property;\r
+import org.apache.derby.iapi.reference.MessageId;\r
+import org.apache.derby.iapi.jdbc.AuthenticationService;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.property.PropertyUtil;\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+\r
+import java.util.Properties;\r
+import java.io.PrintStream;\r
+\r
+/**\r
+       A class to boot a Derby system that includes a JDBC driver.\r
+       Should be used indirectly through JDBCDriver or JDBCServletBoot\r
+       or any other useful booting mechanism that comes along.\r
+*/\r
+public class JDBCBoot {\r
+\r
+       private Properties bootProperties;\r
+\r
+    private static final String NETWORK_SERVER_AUTOSTART_CLASS_NAME = "org.apache.derby.iapi.jdbc.DRDAServerStarter";\r
+\r
+       public JDBCBoot() {\r
+               bootProperties = new Properties();\r
+       }\r
+\r
+       void addProperty(String name, String value) {\r
+               bootProperties.put(name, value);\r
+       }\r
+\r
+       /**\r
+               Boot a system requesting a JDBC driver but only if there is\r
+               no current JDBC driver that is handling the required protocol.\r
+\r
+       */\r
+       public void boot(String protocol, PrintStream logging) {\r
+\r
+               if (org.apache.derby.jdbc.InternalDriver.activeDriver() == null)\r
+               {\r
+\r
+                       // request that the InternalDriver (JDBC) service and the\r
+                       // authentication service be started.\r
+                       //\r
+                       addProperty("derby.service.jdbc", "org.apache.derby.jdbc.InternalDriver");\r
+                       addProperty("derby.service.authentication", AuthenticationService.MODULE);\r
+\r
+                       Monitor.startMonitor(bootProperties, logging);\r
+\r
+            /* The network server starter module is started differently from other modules because\r
+             * 1. its start is conditional, depending on a system property, and PropertyUtil.getSystemProperty\r
+             *    does not work until the Monitor has started,\r
+             * 2. we do not want the server to try to field requests before Derby has booted, and\r
+             * 3. if the module fails to start we want to log a message to the error log and continue as\r
+             *    an embedded database.\r
+             */\r
+            if( Boolean.valueOf(PropertyUtil.getSystemProperty(Property.START_DRDA)).booleanValue())\r
+            {\r
+                try\r
+                {\r
+                    Monitor.startSystemModule( NETWORK_SERVER_AUTOSTART_CLASS_NAME);\r
+                }\r
+                catch( StandardException se)\r
+                {\r
+                    Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_START_EXCEPTION,\r
+                                            se.getMessage());\r
+                }\r
+            }\r
+               }\r
+       }\r
+}\r