01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.dbutil;
18:
19: import java.sql.Connection;
20: import java.sql.DriverManager;
21: import java.sql.Statement;
22:
23: import org.hsqldb.Server;
24:
25: /**
26: * @author Sweaver
27: *
28: * To change the template for this generated type comment go to
29: * Window - Preferences - Java - Code Generation - Code and Comments
30: */
31: public class HSQLServer {
32:
33: public static void main(String[] args) {
34: if (args[0].equals("kill")) {
35: kill(Integer.parseInt(args[1]), args[2], args[3]);
36: return;
37: }
38:
39: try {
40: System.out.println("Starting server: " + args[1]);
41: Thread hsql = new HSQLServerThread(args);
42: hsql.start();
43: System.out.println("Exiting HSQL");
44:
45: } catch (Exception e) {
46:
47: }
48: }
49:
50: private static void kill(int port, String user, String password) {
51: try {
52: Class.forName("org.hsqldb.jdbcDriver");
53: String url = "jdbc:hsqldb:hsql://127.0.0.1:" + port;
54: Connection con = DriverManager.getConnection(url, user,
55: password);
56: String sql = "SHUTDOWN";
57: Statement stmt = con.createStatement();
58: stmt.executeUpdate(sql);
59: stmt.close();
60: } catch (Exception e) {
61:
62: }
63:
64: }
65: }
66:
67: class HSQLServerThread extends Thread {
68:
69: private String[] args;
70:
71: HSQLServerThread(String args[]) {
72:
73: this .args = args;
74: setDaemon(true);
75:
76: }
77:
78: /**
79: * @see java.lang.Runnable#run()
80: */
81: public void run() {
82: System.out.println("Starting HSQLDB server");
83: Server.main(args);
84:
85: }
86:
87: }
|