Java Code Examples for org.hsqldb.jdbc.JDBCDataSource#setDatabase()

The following examples show how to use org.hsqldb.jdbc.JDBCDataSource#setDatabase() . 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: JqmAsyncTester.java    From jqm with Apache License 2.0 5 votes vote down vote up
public JqmAsyncTester()
{
    // Ext dir
    File extDir = new File("./ext");
    if (!extDir.exists() && !extDir.mkdir())
    {
        throw new RuntimeException(new IOException("./ext directory does not exist and cannot create it"));
    }

    s = Common.createHsqlServer();
    s.start();

    JDBCDataSource ds = new JDBCDataSource();
    ds.setDatabase("jdbc:hsqldb:mem:" + s.getDatabaseName(0, true));
    db = new Db(ds, true);
    cnx = db.getConn();

    Properties p2 = Common.dbProperties(s);
    p2.put("com.enioka.jqm.jdbc.contextobject", db);
    JqmClientFactory.setProperties(p2);
    JqmEngineFactory.setDatasource(db);
    JqmEngineFactory.initializeMetadata();
    cnx.runUpdate("dp_delete_all");
    cnx.runUpdate("q_delete_all");
    cnx.commit();

    // Needed parameters
    addGlobalParameter("defaultConnection", "");
    addGlobalParameter("disableWsApi", "true");
    addGlobalParameter("logFilePerLaunch", "false");

    // Prepare DB

}
 
Example 2
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void testDirectDataSource() throws Exception {

        final Properties properties = new Properties();

        final JDBCDataSource dataSource = new JDBCDataSource();
        dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
        dataSource.setUser("sa");
        dataSource.setPassword("");
        dataSource.getConnection().close();

        properties.put("DataSource", dataSource);
        properties.put("UseDatabaseLock", "false");
        properties.put("StartupTimeout", "10000");

        ActiveMQFactory.setThreadProperties(properties);
        BrokerService broker = null;
        try {
            broker = BrokerFactory.createBroker(new URI(getBrokerUri(
                "broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
            assertNotNull("broker is null", broker);

            final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
            assertNotNull("persistenceAdapter is null", persistenceAdapter);

            assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter",
                persistenceAdapter instanceof JDBCPersistenceAdapter);
            final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;

            assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
        } finally {
            stopBroker(broker);
            ActiveMQFactory.setThreadProperties(null);
        }
    }
 
Example 3
Source File: JqmTester.java    From jqm with Apache License 2.0 4 votes vote down vote up
private JqmTester(String className)
{
    s = Common.createHsqlServer();
    s.start();

    JDBCDataSource ds = new JDBCDataSource();
    ds.setDatabase("jdbc:hsqldb:mem:" + s.getDatabaseName(0, true));
    db = new Db(ds, true);
    cnx = db.getConn();

    JqmSingleRunner.setConnection(db);

    Properties p2 = new Properties();
    p2.put("com.enioka.jqm.jdbc.contextobject", db);
    JqmClientFactory.setProperties(p2);

    // Needed parameters
    GlobalParameter.setParameter(cnx, "defaultConnection", "");
    cnx.commit();

    // Ext dir
    File extDir = new File("./ext");
    if (!extDir.exists() && !extDir.mkdir())
    {
        throw new RuntimeException(new IOException("./ext directory does not exist and cannot create it"));
    }

    // Create node
    resDirectoryPath = Common.createTempDirectory();
    node = Node.create(cnx, "testtempnode", 12, resDirectoryPath.getAbsolutePath(), resDirectoryPath.getAbsolutePath(),
            resDirectoryPath.getAbsolutePath(), "test", "INFO");

    q = Queue.create(cnx, "default", "default test queue", true); // Only useful because JobDef.queue is non-null

    jd = JobDef.create(cnx, "test application", className, null, "/dev/null", q, 0, "TestApplication", null, null, null, null, null,
            false, null, PathType.MEMORY);

    ji = JobInstance.enqueue(cnx, State.SUBMITTED, q, jd, null, null, null, null, null, null, null, null, null, false, false, null, 0,
            Instruction.RUN, null);
    cnx.runUpdate("ji_update_status_by_id", node.getId(), ji);

    cnx.commit();
}
 
Example 4
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void testLookupDataSource() throws Exception {

        final Properties properties = new Properties();

        final JDBCDataSource dataSource = new JDBCDataSource();
        dataSource.setDatabase("jdbc:hsqldb:mem:testdb" + System.currentTimeMillis());
        dataSource.setUser("sa");
        dataSource.setPassword("");
        dataSource.getConnection().close();

        MockInitialContextFactory.install(Collections.singletonMap("openejb/Resource/TestDs", dataSource));
        assertSame(dataSource, new InitialContext().lookup("openejb/Resource/TestDs"));

        final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
        containerSystem.getJNDIContext().bind("openejb/Resource/TestDs", dataSource);
        SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);

        properties.put("DataSource", "TestDs");
        properties.put("UseDatabaseLock", "false");
        properties.put("StartupTimeout", "10000");

        ActiveMQFactory.setThreadProperties(properties);
        BrokerService broker = null;
        try {
            broker = BrokerFactory.createBroker(new URI(getBrokerUri(
                "broker:(tcp://localhost:" + brokerPort + ")?useJmx=false")));
            assertNotNull("broker is null", broker);

            final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
            assertNotNull("persistenceAdapter is null", persistenceAdapter);

            assertTrue("persistenceAdapter should be an instance of JDBCPersistenceAdapter",
                persistenceAdapter instanceof JDBCPersistenceAdapter);
            final JDBCPersistenceAdapter jdbcPersistenceAdapter = (JDBCPersistenceAdapter) persistenceAdapter;

            assertSame(dataSource, jdbcPersistenceAdapter.getDataSource());
        } finally {
            stopBroker(broker);
            ActiveMQFactory.setThreadProperties(null);
        }
    }