KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > test > StartHypersonic


1 package com.genimen.djeneric.test;
2
3 import junit.framework.Assert;
4
5 import com.genimen.djeneric.util.DjLogger;
6
7 /**
8  * @author Wido Riezebos
9  */

10 public class StartHypersonic
11 {
12   public static String JavaDoc port = "9876";
13   public static DbRunner runner = null;
14
15   public static void main(String JavaDoc args[])
16   {
17     try
18     {
19       String JavaDoc dbFile = Util.resource2FileName(StartHypersonic.class.getResource("db"), "test");
20
21       System.out.println("Starting Hypersonic Database " + dbFile);
22       runner = new DbRunner(dbFile);
23       runner.start();
24
25       // Wait for the database to be started before we continue..
26
// 2 seconds should be enough. I know this is kind of dirty but hey,
27
// it works for me
28

29       try
30       {
31         Thread.sleep(2000);
32       }
33       catch (InterruptedException JavaDoc e)
34       {
35         DjLogger.log(e);
36       }
37     }
38     catch (Exception JavaDoc x)
39     {
40       DjLogger.log(x);
41       Assert.assertTrue(false);
42     }
43   }
44
45   public static boolean isRunning()
46   {
47     if (runner == null) return false;
48     return runner.isRunning();
49   }
50 }
51
52 class DbRunner extends Thread JavaDoc
53 {
54   String JavaDoc _dbloc;
55   boolean _isRunning = false;
56
57   public DbRunner(String JavaDoc dbloc)
58   {
59     _dbloc = dbloc;
60   }
61
62   public void run()
63   {
64     _isRunning = true;
65     org.hsqldb.Server.main(new String JavaDoc[]{"-no_system_exit", "true", "-port", StartHypersonic.port, "-database", _dbloc});
66     _isRunning = false;
67   }
68
69   public boolean isRunning()
70   {
71     return _isRunning;
72   }
73
74 }
Popular Tags