KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > server > HSqlDBServer


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.test.server;
5
6 import org.hsqldb.HsqlProperties;
7 import org.hsqldb.Server;
8 import org.hsqldb.ServerConfiguration;
9
10
11 public class HSqlDBServer extends AbstractDBServer {
12   private static final Class JavaDoc HSQLDB_MAIN = org.hsqldb.Server.class;
13   private static final String JavaDoc DEFAULT_DB_NAME = "testdb";
14   private static final int DEFAULT_PORT = ServerConfiguration.getDefaultPort(1, false);
15   
16   Server server = null;
17   
18   
19   public HSqlDBServer(String JavaDoc name, int port) {
20     super();
21     
22     this.setDbName(name==null ? this.DEFAULT_DB_NAME : name);
23     this.setServerPort(port==0 ? this.DEFAULT_PORT : port);
24   }
25
26   public void doStart() throws Exception JavaDoc {
27     HsqlProperties hsqlproperties1 = new HsqlProperties();
28     HsqlProperties hsqlproperties2 = HsqlProperties.argArrayToProps(new String JavaDoc[]{
29            "-database.0", "mem:test",
30            "-dbname.0", this.getDbName(),
31            "server.port", "" + this.getServerPort()
32            }, "server");
33     hsqlproperties1.addProperties(hsqlproperties2);
34     ServerConfiguration.translateDefaultDatabaseProperty(hsqlproperties1);
35     server = new Server();
36     server.setProperties(hsqlproperties1);
37     server.start();
38   }
39
40   public void doStop() throws Exception JavaDoc {
41     server.setNoSystemExit(true);
42     server.stop();
43   }
44   
45   public String JavaDoc toString() {
46     return super.toString() + " dbName:" + this.getDbName() + "; serverPort:" + this.getServerPort();
47   }
48 }
49
Popular Tags