KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > jdbc > JDBCBoot


1 /*
2
3    Derby - Class org.apache.derby.iapi.jdbc.JDBCBoot
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 JavaDoc;
32 import java.io.PrintStream JavaDoc;
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 JavaDoc bootProperties;
42
43     private static final String JavaDoc NETWORK_SERVER_AUTOSTART_CLASS_NAME = "org.apache.derby.iapi.jdbc.DRDAServerStarter";
44
45     public JDBCBoot() {
46         bootProperties = new Properties JavaDoc();
47     }
48
49     void addProperty(String JavaDoc name, String JavaDoc 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 JavaDoc protocol, PrintStream JavaDoc logging) {
59
60         if (org.apache.derby.jdbc.InternalDriver.activeDriver() == null)
61         {
62
63             // request that the InternalDriver (JDBC) service and the
64
// authentication service be started.
65
//
66
addProperty("derby.service.jdbc", "org.apache.derby.jdbc.InternalDriver");
67             addProperty("derby.service.authentication", AuthenticationService.MODULE);
68
69             Monitor.startMonitor(bootProperties, logging);
70
71             /* The network server starter module is started differently from other modules because
72              * 1. its start is conditional, depending on a system property, and PropertyUtil.getSystemProperty
73              * does not work until the Monitor has started,
74              * 2. we do not want the server to try to field requests before Cloudscape has booted, and
75              * 3. if the module fails to start we want to log a message to the error log and continue as
76              * an embedded database.
77              */

78             if( Boolean.valueOf(PropertyUtil.getSystemProperty(Property.START_DRDA)).booleanValue())
79             {
80                 try
81                 {
82                     Monitor.startSystemModule( NETWORK_SERVER_AUTOSTART_CLASS_NAME);
83                 }
84                 catch( StandardException se)
85                 {
86                     Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_START_EXCEPTION,
87                                             se.getMessage());
88                 }
89             }
90         }
91     }
92 }
93
Popular Tags