Java Code Examples for org.hsqldb.Server#setDatabaseName()

The following examples show how to use org.hsqldb.Server#setDatabaseName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JqmBaseTest.java    From jqm with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void testInit() throws Exception
{
    if (db == null)
    {
        JndiContext.createJndiContext();

        // If needed, create an HSQLDB server.
        String dbName = System.getenv("DB");
        if (dbName == null || "hsqldb".equals(dbName))
        {
            s = new Server();
            s.setDatabaseName(0, "testdbengine");
            s.setDatabasePath(0, "mem:testdbengine");
            s.setLogWriter(null);
            s.setSilent(true);
            s.start();
        }

        // In all cases load the datasource. (the helper itself will load the property file if any).
        db = Helpers.getDb();
    }
}
 
Example 2
Source File: HsqldbListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 处理context初始化事件.
 * 
 * @param sce
 *            ServletContextEvent
 */
public void contextInitialized(ServletContextEvent sce) {
    if (!enabled) {
        logger.info("skip hsqldb server");

        return;
    }

    try {
        String databasePath = path + "/" + databaseName;
        url = "jdbc:hsqldb:hsql://localhost:" + port + "/" + databaseName;

        Server server = new Server();
        server.setDatabaseName(0, databaseName);

        server.setDatabasePath(0, databasePath);
        server.setPort(port);
        server.setSilent(true);
        server.start();
        Thread.sleep(WAIT_TIME);
    } catch (InterruptedException ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example 3
Source File: HsqldbServer.java    From lemon with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    if (!enabled) {
        logger.info("skip hsqldb server");

        return;
    }

    try {
        String databasePath = path + "/" + databaseName;
        url = "jdbc:hsqldb:hsql://localhost:" + port + "/" + databaseName;

        Server server = new Server();
        server.setDatabaseName(0, databaseName);

        server.setDatabasePath(0, databasePath);
        server.setPort(port);
        server.setSilent(true);
        server.start();
        Thread.sleep(WAIT_TIME);
    } catch (InterruptedException ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example 4
Source File: HerokuDatabasePropertiesProviderResourceTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            final int port = NetworkUtil.getNextAvailablePort();
            final Server server = new Server();
            server.setAddress("localhost");
            server.setPort(port);
            server.setDatabaseName(0, "adb");
            server.setDatabasePath(0, Files.mkdirs(new File("target/HerokuDatabasePropertiesProviderResourceTest")).getAbsolutePath());
            server.start();
            System.setProperty("hsqldb", Integer.toString(port));
            try {
                base.evaluate();
            } finally {
                server.stop();
            }
        }
    };
}
 
Example 5
Source File: AbstractHsqldbMojo.java    From hsqldb-maven-plugin with Apache License 2.0 5 votes vote down vote up
protected void setup() throws MojoExecutionException {
    if (getLog().isDebugEnabled()) {
        getLog().debug("Setting up HSQLDB server with :");
        getLog().debug("\taddress : " + address);
        getLog().debug("\tport : " + (port == 0 ? "default" : port));
        getLog().debug("\tname : " + name);
        getLog().debug("\tpath : " + path);
        getLog().debug("\tconnection URI : " + getConnectionURI());
        getLog().debug("\tdriver : " + driver);
        getLog().debug("\tvalidation query : " + validationQuery);
        getLog().debug("\tskip : " + skip);
    }
    try {
        server = new Server();

        // TODO : user Maven logger
        server.setLogWriter(null);
        server.setSilent(true);
        
        server.setAddress(address);
        if (port > 0) {
            server.setPort(port);
        }
        server.setDatabaseName(0, name);
        server.setDatabasePath(0, path);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
 
Example 6
Source File: TestDBStorage.java    From spork with Apache License 2.0 5 votes vote down vote up
public TestDBStorage() throws ExecException, IOException {
    // Initialise Pig server
    cluster = MiniCluster.buildCluster();
    pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
    pigServer.getPigContext().getProperties()
            .setProperty(MRConfiguration.MAP_MAX_ATTEMPTS, "1");
    pigServer.getPigContext().getProperties()
            .setProperty(MRConfiguration.REDUCE_MAX_ATTEMPTS, "1");
    System.out.println("Pig server initialized successfully");
    TMP_DIR = System.getProperty("user.dir") + "/build/test/";
    dblocation = TMP_DIR + "batchtest";
    url = "jdbc:hsqldb:file:" + dblocation
           + ";hsqldb.default_table_type=cached;hsqldb.cache_rows=100";
    // Initialise DBServer
    dbServer = new Server();
    dbServer.setDatabaseName(0, "batchtest");
    // dbServer.setDatabasePath(0, "mem:test;sql.enforce_strict_size=true");
    dbServer.setDatabasePath(0,
                        "file:" + TMP_DIR + "batchtest;sql.enforce_strict_size=true");
    dbServer.setLogWriter(null);
    dbServer.setErrWriter(null);
    dbServer.start();
    System.out.println("Database URL: " + dbUrl);
    try {
        Class.forName(driver);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(this + ".setUp() error: " + e.getMessage());
    }
    System.out.println("Database server started on port: " + dbServer.getPort());
}
 
Example 7
Source File: DBCountPageView.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private void startHsqldbServer() {
  server = new Server();
  server.setDatabasePath(0, 
      System.getProperty("test.build.data",".") + "/URLAccess");
  server.setDatabaseName(0, "URLAccess");
  server.start();
}
 
Example 8
Source File: Common.java    From jqm with Apache License 2.0 5 votes vote down vote up
static Server createHsqlServer()
{
    Server s = new Server();
    String dbName = "testdb_" + Math.random();
    s.setDatabaseName(0, dbName);
    s.setDatabasePath(0, "mem:" + dbName);
    s.setLogWriter(null);
    s.setSilent(true);
    return s;
}
 
Example 9
Source File: DBCountPageView.java    From hadoop-book with Apache License 2.0 5 votes vote down vote up
private void startHsqldbServer() {
    server = new Server();
    server.setDatabasePath(0,
            System.getProperty("test.build.data", ".") + "/URLAccess");
    server.setDatabaseName(0, "URLAccess");
    server.start();
}
 
Example 10
Source File: DBCountPageView.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private void startHsqldbServer() {
  server = new Server();
  server.setDatabasePath(0, 
      System.getProperty("test.build.data",".") + "/URLAccess");
  server.setDatabaseName(0, "URLAccess");
  server.start();
}
 
Example 11
Source File: DbTest.java    From netcrusher-java with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    reactor = new NioReactor();

    crusher = TcpCrusherBuilder.builder()
            .withReactor(reactor)
            .withBindAddress("127.0.0.1", CRUSHER_PORT)
            .withConnectAddress("127.0.0.1", DB_PORT)
            .buildAndOpen();

    hsqlServer = new Server();
    hsqlServer.setAddress("127.0.0.1");
    hsqlServer.setPort(DB_PORT);
    hsqlServer.setDaemon(true);
    hsqlServer.setErrWriter(new PrintWriter(System.err));
    hsqlServer.setLogWriter(new PrintWriter(System.out));
    hsqlServer.setNoSystemExit(true);
    hsqlServer.setDatabasePath(0, "mem:testdb");
    hsqlServer.setDatabaseName(0, "testdb");
    hsqlServer.start();

    Class.forName("org.hsqldb.jdbc.JDBCDriver");

    BoneCPConfig config = new BoneCPConfig();
    config.setJdbcUrl(String.format("jdbc:hsqldb:hsql://127.0.0.1:%d/testdb", CRUSHER_PORT));
    config.setUsername("sa");
    config.setPassword("");
    config.setInitSQL(SQL_CHECK);
    config.setConnectionTestStatement(SQL_CHECK);
    config.setAcquireIncrement(1);
    config.setAcquireRetryAttempts(1);
    config.setAcquireRetryDelayInMs(1000);
    config.setConnectionTimeoutInMs(1000);
    config.setQueryExecuteTimeLimitInMs(1000);
    config.setDefaultAutoCommit(false);
    config.setDefaultReadOnly(true);
    config.setDefaultTransactionIsolation("NONE");
    config.setPartitionCount(1);
    config.setMinConnectionsPerPartition(1);
    config.setMaxConnectionsPerPartition(1);
    config.setLazyInit(true);
    config.setDetectUnclosedStatements(true);

    connectionPool = new BoneCP(config);
}