package basic;

import uk.ac.ic.doc.automed.DSR;
import uk.ac.ic.doc.automed.DSRConfiguration;
import uk.ac.ic.doc.automed.DSRException;
import uk.ac.ic.doc.automed.util.Debugger;

/**
 * HsqldbServer.java
 * 
 * @author Duc M Le  <a href="mailto:dmle@doc.ic.ac.uk"><i>dmle@doc.ic.ac.uk</i></a>
 * @version 1.0
 * Department of Computing, Imperial College
 */

public class HsqldbServer {
  
  /**
   * Creates a new instance of HsqldbServer
   */
  public HsqldbServer() {
  }
  
  public static void main(String[] args) {
    // Start a HSQLDB server
    String cfgfile = null, debug = null;
    
    if (args.length > 0) {
      for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-c")) {
          i++;
          cfgfile = args[i];
        }
        if (args[i].equals("-d")) {
          i++;
          debug = args[i];
        }
      }
    }
    
    try {
      
      if (cfgfile != null && !cfgfile.equals(""))
        DSRConfiguration.setDefaultConfigFileName(cfgfile);
      
      if (debug != null && !debug.equals(""))
        Debugger.setSectionDebugLevel(new String[] {"-d", debug});
      
      DSR.testDataSource();
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(-1);
    }
    
    //loop forever
    while (true) {
      try {
        Thread.sleep(1000000000);
      } catch (InterruptedException ex) {
        //
      }
    }
  }
}
