01: /*
02:
03: Derby - Class org.apache.derby.iapi.jdbc.JDBCBoot
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.iapi.jdbc;
23:
24: import org.apache.derby.iapi.reference.Property;
25: import org.apache.derby.iapi.reference.MessageId;
26: import org.apache.derby.iapi.jdbc.AuthenticationService;
27: import org.apache.derby.iapi.error.StandardException;
28: import org.apache.derby.iapi.services.property.PropertyUtil;
29: import org.apache.derby.iapi.services.monitor.Monitor;
30:
31: import java.util.Properties;
32: import java.io.PrintStream;
33:
34: /**
35: A class to boot a cloudscape system that includes a JDBC driver.
36: Should be used indirectly through JDBCDriver or JDBCServletBoot
37: or any other useful booting mechanism that comes along.
38: */
39: public class JDBCBoot {
40:
41: private Properties bootProperties;
42:
43: private static final String NETWORK_SERVER_AUTOSTART_CLASS_NAME = "org.apache.derby.iapi.jdbc.DRDAServerStarter";
44:
45: public JDBCBoot() {
46: bootProperties = new Properties();
47: }
48:
49: void addProperty(String name, String value) {
50: bootProperties.put(name, value);
51: }
52:
53: /**
54: Boot a system requesting a JDBC driver but only if there is
55: no current JDBC driver that is handling the required protocol.
56:
57: */
58: public void boot(String protocol, PrintStream logging) {
59:
60: if (org.apache.derby.jdbc.InternalDriver.activeDriver() == null) {
61:
62: // request that the InternalDriver (JDBC) service and the
63: // authentication service be started.
64: //
65: addProperty("derby.service.jdbc",
66: "org.apache.derby.jdbc.InternalDriver");
67: addProperty("derby.service.authentication",
68: AuthenticationService.MODULE);
69:
70: Monitor.startMonitor(bootProperties, logging);
71:
72: /* The network server starter module is started differently from other modules because
73: * 1. its start is conditional, depending on a system property, and PropertyUtil.getSystemProperty
74: * does not work until the Monitor has started,
75: * 2. we do not want the server to try to field requests before Cloudscape has booted, and
76: * 3. if the module fails to start we want to log a message to the error log and continue as
77: * an embedded database.
78: */
79: if (Boolean
80: .valueOf(
81: PropertyUtil
82: .getSystemProperty(Property.START_DRDA))
83: .booleanValue()) {
84: try {
85: Monitor
86: .startSystemModule(NETWORK_SERVER_AUTOSTART_CLASS_NAME);
87: } catch (StandardException se) {
88: Monitor
89: .logTextMessage(
90: MessageId.CONN_NETWORK_SERVER_START_EXCEPTION,
91: se.getMessage());
92: }
93: }
94: }
95: }
96: }
|