KickJava   Java API By Example, From Geeks To Geeks.

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


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.CLILogger;
27 import com.sun.enterprise.cli.framework.CommandException;
28 import com.sun.enterprise.cli.framework.CommandValidationException;
29 import com.sun.enterprise.util.SystemPropertyConstants;
30 import com.sun.enterprise.util.OS;
31 import java.io.File JavaDoc;
32
33 /**
34  * stop-database command
35  * This command class will invoke DerbyControl to stop
36  * the database.
37  * @author <a HREF="mailto:jane.young@sun.com">Jane Young</a>
38  * @version $Revision: 1.9.2.1 $
39  */

40 public final class StopDatabaseCommand extends DatabaseCommand
41 {
42     private final static String JavaDoc DB_HOST = "dbhost";
43     private final static String JavaDoc DB_PORT = "dbport";
44
45     /**
46      * An method that validates the options
47      * on the specification in the xml properties file
48      * This method verifies for the correctness of number of
49      * operands and if all the required options are supplied by the client.
50      * @return boolean returns true if success else returns false
51      */

52     public boolean validateOptions() throws CommandValidationException
53     {
54         return super.validateOptions();
55     }
56
57
58     /**
59        defines the command to stop the derby database
60        Note that when using Darwin (Mac), the property,
61        "-Dderby.storage.fileSyncTransactionLog=True" is defined.
62     */

63     public String JavaDoc[] stopDatabaseCmd() throws Exception JavaDoc
64     {
65         if (OS.isDarwin()) {
66             return new String JavaDoc [] {
67                 sJavaHome+File.separator+"bin"+File.separator+"java",
68                 "-Djava.library.path="+sInstallRoot+File.separator+"lib",
69                 "-Dderby.storage.fileSyncTransactionLog=True",
70                 "-cp",
71                 sClasspath + File.pathSeparator + sDatabaseClasspath,
72                 "com.sun.enterprise.cli.commands.DerbyControl",
73                 "shutdown",
74                 dbHost, dbPort, "false"
75             };
76         }
77         return new String JavaDoc [] {
78             sJavaHome+File.separator+"bin"+File.separator+"java",
79             "-Djava.library.path="+sInstallRoot+File.separator+"lib",
80             "-cp",
81             sClasspath + File.pathSeparator + sDatabaseClasspath,
82             "com.sun.enterprise.cli.commands.DerbyControl",
83             "shutdown",
84             dbHost, dbPort, "false"
85        };
86     }
87     
88
89     
90     /**
91      * Method that Executes the command
92      * @throws CommandException
93      */

94     public void runCommand() throws CommandException, CommandValidationException
95     {
96         if (!validateOptions())
97             throw new CommandValidationException("Validation is false");
98
99         try {
100             prepareProcessExecutor();
101             CLIProcessExecutor cpe = new CLIProcessExecutor();
102             cpe.execute(pingDatabaseCmd(false), true);
103             if (cpe.exitValue() > 0) {
104                     //if ping is unsuccesfull then database is not up and running
105
throw new CommandException(getLocalizedString("StopDatabaseStatus", new Object JavaDoc[]{dbHost, dbPort}));
106             }
107             else if (cpe.exitValue() <0) {
108                     // Something terribly wrong!
109
throw new CommandException(getLocalizedString("CommandUnSuccessful",
110                                                               new Object JavaDoc[] {name} ));
111             }
112             else {
113                     //database is running so go ahead and stop the database
114
cpe.execute(stopDatabaseCmd(), true);
115                 if (cpe.exitValue() > 0) {
116                     throw new CommandException(getLocalizedString("CommandUnSuccessful",
117                                                               new Object JavaDoc[] {name} ));
118                 }
119                 CLILogger.getInstance().printDetailMessage(getLocalizedString(
120                                                            "CommandSuccessful",
121                                                            new Object JavaDoc[] {name}));
122             }
123         }
124         catch (Exception JavaDoc e) {
125             displayExceptionMessage(e);
126         }
127     }
128 }
129
Popular Tags