KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > DatabaseCommand


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import com.sun.enterprise.util.SystemPropertyConstants;
28 import com.sun.enterprise.util.OS;
29 import com.sun.enterprise.util.io.FileUtils;
30 import java.io.File JavaDoc;
31
32
33 /**
34  * This is an abstract class to be inherited by
35  * StartDatabaseCommand and StopDatabaseCommand.
36  * This classes prepares the variables that is used to
37  * to invoke DerbyControl. It also contains a pingDatabase
38  * method that is used by both start/stop database command.
39  * @author <a HREF="mailto:jane.young@sun.com">Jane Young</a>
40  * @version $Revision: 1.2 $
41  */

42 public abstract class DatabaseCommand extends S1ASCommand
43 {
44     private final static String JavaDoc DB_HOST = "dbhost";
45     private final static String JavaDoc DB_PORT = "dbport";
46     
47     protected String JavaDoc dbHost;
48     protected String JavaDoc dbPort;
49     protected String JavaDoc dbLocation;
50     protected String JavaDoc sJavaHome;
51     protected String JavaDoc sInstallRoot;
52     protected String JavaDoc sClasspath;
53     protected String JavaDoc sDatabaseClasspath;
54
55     /**
56      * Prepare variables to invoke start/ping database command
57      * DatabaseCommand.
58      */

59     protected void prepareProcessExecutor() throws Exception JavaDoc
60     {
61         dbHost = getOption(DB_HOST);
62         dbPort = getOption(DB_PORT);
63     checkIfPortIsValid(dbPort);
64         dbLocation = System.getProperty(SystemPropertyConstants.DERBY_ROOT_PROPERTY);
65         sJavaHome = System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY);
66         sInstallRoot = System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY);
67     // sClasspath = System.getProperty("java.class.path");
68
sClasspath = sInstallRoot+File.separator+"lib"+File.separator+
69                      "appserv-rt.jar"+File.pathSeparator+sInstallRoot+
70                  File.separator+"lib"+File.separator+"admin-cli.jar";
71         sDatabaseClasspath = dbLocation+File.separator+"lib"+
72                                        File.separator+"derby.jar"+
73                                        File.pathSeparator+dbLocation+
74                                        File.separator+"lib"+File.separator+
75                                        "derbytools.jar"+File.pathSeparator+
76                                        dbLocation+File.separator+"lib"+
77                                        File.separator+"derbynet.jar"+
78                                        File.pathSeparator+dbLocation+File.separator+
79                                        "lib"+File.separator+"derbyclient.jar";
80     }
81
82
83   /** check if database port is valid.
84    * Derby does not check this so need to add code to check the port number.
85    */

86     private void checkIfPortIsValid(final String JavaDoc port) throws CommandValidationException
87     {
88         try
89         {
90             Integer.parseInt(port);
91         }
92         catch(Exception JavaDoc e)
93         {
94             throw new CommandValidationException(getLocalizedString("InvalidPortNumber", new Object JavaDoc[] {port}));
95         }
96     }
97     
98
99
100     /**
101        defines the command to ping the derby database
102        Note that when using Darwin (Mac), the property,
103        "-Dderby.storage.fileSyncTransactionLog=True" is defined.
104     */

105     protected String JavaDoc[] pingDatabaseCmd(boolean bRedirect) throws Exception JavaDoc
106     {
107         if (OS.isDarwin()) {
108             return new String JavaDoc [] {
109                     sJavaHome+File.separator+"bin"+File.separator+"java",
110                     "-Djava.library.path="+sInstallRoot+File.separator+"lib",
111                     "-Dderby.storage.fileSyncTransactionLog=True",
112                     "-cp",
113                     sClasspath + File.pathSeparator + sDatabaseClasspath,
114                     "com.sun.enterprise.cli.commands.DerbyControl",
115                     "ping", dbHost, dbPort, new Boolean JavaDoc(bRedirect).toString()
116             };
117         }
118         else {
119             return new String JavaDoc [] {
120                 sJavaHome+File.separator+"bin"+File.separator+"java",
121                 "-Djava.library.path="+sInstallRoot+File.separator+"lib",
122                 "-cp",
123                 sClasspath + File.pathSeparator + sDatabaseClasspath,
124                 "com.sun.enterprise.cli.commands.DerbyControl",
125                 "ping", dbHost, dbPort, new Boolean JavaDoc(bRedirect).toString()
126             };
127         }
128     }
129 }
130
Popular Tags