Package org.hsqldb

Examples of org.hsqldb.Server

From the 'server.properties' file, options can be set similarly, using a slightly different format.

Here is an example 'server.properties' file:

 server.port=9001 server.database.0=test server.dbname.0=... ... server.database.n=... server.dbname.n=... server.silent=true 
Starting with 1.7.2, Server has been refactored to become a simple JavaBean with non-blocking start() and stop() service methods. It is possible to configure a Server instance through the JavaBean API as well, but this part of the public interface is still under review and will not be finalized or documented fully until the final 1.7.2 release.

Note:

The 'no_system_exit' property is of particular interest.

If a Server instance is to run embedded in, say, an application server, such as when the jdbcDataSource or HsqlServerFactory classes are used, it is typically necessary to avoid calling System.exit() when the Server instance shuts down.

By default, 'no_system_exit' is set:

  1. true when a Server is started directly from the start() method.

  2. false when a Server is started from the main(String[]) method.

These values are natural to their context because the first case allows the JVM to exit by default on Server shutdown when a Server instance is started from a command line environment, whereas the second case prevents a typically unwanted JVM exit on Server shutdown when a Server intance is started as part of a larger framework.

Replaces original Hypersonic source of the same name. @author fredt@users @version 1.8.0 @since 1.7.2 @jmx.mbean description="HSQLDB Server" extends="org.hsqldb.mx.mbean.RegistrationSupportBaseMBean" @jboss.xmbean


   */
  public static void main(String[] args) {
   
    String dbName = "eCommerceDB";
   
    Server server = new Server();
    System.out.println("Starting the Database server");
    server.setDatabaseName(0, dbName);
    server.setDatabasePath(0, "file:data"+File.separatorChar+"ecommercedb;sql.enforce_strict_size=true");
        //0, "mem:eCommerceDB;sql.enforce_strict_size=true");
    server.setLogWriter(new PrintWriter(System.out));
    server.setErrWriter(new PrintWriter(System.err));
    server.start();
   
   

  }
View Full Code Here


  private static final String DRIVER_CLASS = "org.hsqldb.jdbcDriver";
 
  private Server server;
 
  private void startHsqldbServer() {
    server = new Server();
    server.setDatabasePath(0,
        System.getProperty("test.build.data", "/tmp") + "/URLAccess");
    server.setDatabaseName(0, "URLAccess");
    server.start();
  }
View Full Code Here

    OUT_DIR = System.getProperty("test.build.data", "/tmp") + "/dddbifout";
  }

  private void startHsqldbServer() {
    if (null == server) {
      server = new Server();
      server.setDatabasePath(0,
          System.getProperty("test.build.data", "/tmp") + "/" + DB_NAME);
      server.setDatabaseName(0, DB_NAME);
      server.start();
    }
View Full Code Here

  @Override
  public void setUp() throws IOException
    {
    super.setUp();

    server = new Server();
    server.setDatabasePath( 0, "build/db/testing" );
    server.setDatabaseName( 0, "testing" );
    server.start();
    }
View Full Code Here

  @CmdLine(name = "db_port", help = "Path to the input data set.")
  private static final Arg<Integer> DB_PORT = Arg.create(14001);

  public Database() {
    LOG.info("Starting DB on port " + DB_PORT.get());
    Server db = new Server();
    db.setAddress("localhost");
    db.setPort(DB_PORT.get());
    db.setDatabasePath(0, "mem:" + DB_NAME + ";sql.enforce_strict_size=true;");
    db.setDatabaseName(0, DB_NAME);
    db.start();
    LOG.info("Started DB.");
  }
View Full Code Here

      props.setProperty("server.silent", "true");
      props.setProperty("server.no_system_exit", "true");
      props.setProperty("server.port", 27862);
      props.setProperty("server.address", ipAddressOrHostName);

      hsqldbServer = new Server();
      hsqldbServer.setLogWriter(null);
      hsqldbServer.setProperties(props);
      hsqldbServer.start();

      log.debug("started " + config.getDatabaseName() + " in-VM");
View Full Code Here

      props.setProperty("server.silent", "true");
      props.setProperty("server.no_system_exit", "true");
      props.setProperty("server.port", 27862);
      props.setProperty("server.address", ipAddressOrHostName);

      hsqldbServer = new Server();
      hsqldbServer.setLogWriter(null);
      hsqldbServer.setProperties(props);
      hsqldbServer.start();

      log.debug("started " + config.getDatabaseName() + " in-VM");
View Full Code Here

  @Test
  public void testMultiProcess() throws Exception {
    // create and start a hsql server, a stand-alone (memory backed) db
    // (important: a stand-alone server should be used because simple
    //  file based access i.e. jdbc:hsqldb:file is NOT process-safe.)
    Server server = new Server();
    server.setDaemon(true);
    server.setSilent(true); // disables LOTS of trace
    final String className = getClass().getName();
    String dbName = "test";
    server.setDatabasePath(0, "mem:"+dbName);
    server.setDatabaseName(0, dbName);
    server.start();
   
    //create the store so that the tests can start right away
    StorageUtils.createWebStore(conf, String.class, WebPage.class);
   
    // create a fixed thread pool
    int numThreads = 4;
    ExecutorService pool = Executors.newFixedThreadPool(numThreads);
   
    // spawn multiple processes, each thread spawns own process
    Collection<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
    for (int i = 0; i < numThreads; i++) {
      tasks.add(new Callable<Integer>() {
        @Override
        public Integer call() {
          try {
            String separator = System.getProperty("file.separator");
            String classpath = System.getProperty("java.class.path");
            String pathSeparator = System.getProperty("path.separator");
            // connect local sql service
            classpath = "./src/testprocess" + pathSeparator + classpath;
            String path = System.getProperty("java.home") + separator + "bin"
                + separator + "java";
            ProcessBuilder processBuilder = new ProcessBuilder(path, "-cp",
                classpath, className);
            processBuilder.redirectErrorStream(true);
            Process process = processBuilder.start();
            InputStream in = process.getInputStream();
            int exit = process.waitFor();
            //print the output of the process
            System.out.println("===Process stream for " + Thread.currentThread()
                + "\n" + IOUtils.toString(in) + "===End of process stream.");
            in.close();
            // process should exit with zero code
            return exit;
          } catch (Exception e) {
            e.printStackTrace();
            // this will fail the test
            return 1;
          }
        }
      });
    }

    // submit them at once
    List<Future<Integer>> results = pool.invokeAll(tasks);

    // check results
    for (Future<Integer> result : results) {
      assertEquals(0, (int) result.get());
    }
   
    //stop db
    server.stop();
  }
View Full Code Here

    });
   
   
    if(serverRequired.get()){
     
      server = new Server();
      server.setDaemon(true);
      server.setSilent(false);
      server.setTrace(true);
      server.setNoSystemExit(true);
View Full Code Here

    public static void reinitHsqldbServer() throws InterruptedException, FileNotFoundException
    {
        stopHsqldbServer();
        jqmlogger.debug("Starting HSQLDB");
        s = new Server();
        s.setDatabaseName(0, "testdbengine");
        s.setDatabasePath(0, "mem:testdbengine");
        s.setLogWriter(null);
        s.setSilent(true);
        s.start();
View Full Code Here

TOP

Related Classes of org.hsqldb.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.