org.hsqldb.jdbc.JDBCDataSource Java Examples

The following examples show how to use org.hsqldb.jdbc.JDBCDataSource. 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: TestDatabase.java    From sis with Apache License 2.0 8 votes vote down vote up
/**
 * Creates a in-memory database on HSQLDB. The database can optionally use a connection pool.
 * The test method can set {@code pooled} to {@code true} if it needs the data to survive when
 * the connection is closed and re-opened.
 *
 * @param  name    the database name (without {@code "jdbc:hsqldb:mem:"} prefix).
 * @param  pooled  whether the database should use a connection pool.
 * @return connection to the test database.
 * @throws SQLException if an error occurred while creating the database.
 *
 * @see <a href="http://hsqldb.org/doc/apidocs/org/hsqldb/jdbc/JDBCDataSource.html">JDBC data source for HSQL</a>
 *
 * @since 1.0
 */
public static TestDatabase createOnHSQLDB(final String name, final boolean pooled) throws SQLException {
    final DataSource ds;
    final JDBCPool pool;
    final String url = "jdbc:hsqldb:mem:".concat(name);
    if (pooled) {
        pool = new JDBCPool();
        pool.setURL(url);
        ds = pool;
    } else {
        final JDBCDataSource simple = new JDBCDataSource();
        simple.setURL(url);
        ds = simple;
        pool = null;
    }
    return new TestDatabase(ds) {
        @Override public void close() throws SQLException {
            try (Connection c = ds.getConnection(); Statement s = c.createStatement()) {
                s.execute("SHUTDOWN");
            }
            if (pool != null) {
                pool.close(2);
            }
        }
    };
}
 
Example #2
Source File: TransactionIsolationExternalDataSourceExternalconfgiurationConnectionProviderTest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
protected ProxyDataSource newDataSource() {
    JDBCDataSource actualDataSource = new JDBCDataSource();
    actualDataSource.setUrl("jdbc:hsqldb:mem:test");
    actualDataSource.setUser("sa");
    actualDataSource.setPassword("");
    Properties properties = new Properties();
    properties.setProperty("hsqldb.tx_level", "SERIALIZABLE");
    actualDataSource.setProperties(properties);
    ProxyDataSource proxyDataSource = new ProxyDataSource();
    proxyDataSource.setDataSource(actualDataSource);
    proxyDataSource.setListener(new SLF4JQueryLoggingListener());
    return proxyDataSource;
}
 
Example #3
Source File: DataSourceDefinitionPlaceHolderTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void check(final DataSource ds) throws NoSuchFieldException, IllegalAccessException {
    assertNotNull(ds);
    assertThat(ds, instanceOf(BasicDataSource.class));

    final BasicDataSource bds = (BasicDataSource) ds;
    assertEquals("sa", bds.getUsername());
    assertEquals("", bds.getPassword());

    final Field fieldDs = bds.getClass().getDeclaredField("ds");
    fieldDs.setAccessible(true);
    final JDBCDataSource realDs = (JDBCDataSource) fieldDs.get(bds);
    assertEquals("jdbc:hsqldb:mem:superDS", realDs.getUrl());
    assertEquals("sa", realDs.getUser());
}
 
Example #4
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 #5
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 #6
Source File: AbstractJPATest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
private ProxyDataSource newDataSource() {
    JDBCDataSource actualDataSource = new JDBCDataSource();
    actualDataSource.setUrl("jdbc:hsqldb:mem:test");
    actualDataSource.setUser("sa");
    actualDataSource.setPassword("");
    ProxyDataSource proxyDataSource = new ProxyDataSource();
    proxyDataSource.setDataSource(actualDataSource);
    proxyDataSource.setListener(new SLF4JQueryLoggingListener());
    return proxyDataSource;
}
 
Example #7
Source File: ExternalDataSourceConnectionProviderTest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
protected ProxyDataSource newDataSource() {
    JDBCDataSource actualDataSource = new JDBCDataSource();
    actualDataSource.setUrl("jdbc:hsqldb:mem:test");
    actualDataSource.setUser("sa");
    actualDataSource.setPassword("");
    ProxyDataSource proxyDataSource = new ProxyDataSource();
    proxyDataSource.setDataSource(actualDataSource);
    proxyDataSource.setListener(new SLF4JQueryLoggingListener());
    return proxyDataSource;
}
 
Example #8
Source File: DatabaseTableMetricsTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() throws SQLException {
    registry = new SimpleMeterRegistry();

    ds = new JDBCDataSource();
    ds.setURL("jdbc:hsqldb:mem:test");

    try (Connection conn = ds.getConnection()) {
        conn.prepareStatement("CREATE TABLE foo (id int)").execute();
        conn.prepareStatement("INSERT INTO foo VALUES (1)").executeUpdate();
    }
}
 
Example #9
Source File: JPATest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test /index.html.
 *
 * @throws Exception
 */
@Test
public void testIndexHtml() throws Exception {
    System.getProperties().put("java.naming.factory.initial", 
            "cloud.piranha.jndi.memory.DefaultInitialContextFactory");
    InitialContext initialContext = new InitialContext();
    JDBCDataSource ds = new JDBCDataSource();
    ds.setUrl("jdbc:hsqldb:mem:demo");
    ds.setUser("sa");
    initialContext.bind("jdbc/demo", ds);
    EmbeddedPiranha piranha = new EmbeddedPiranhaBuilder()
            .directoryResource("src/main/webapp")
            .aliasedDirectoryResource("target/classes", "/WEB-INF/classes")
            .initializer(WeldInitializer.class.getName())
            .initializer(MojarraInitializer.class.getName())
            .build()
            .start();
    EmbeddedRequest request = new EmbeddedRequestBuilder()
            .contextPath("")
            .servletPath("/index.html")
            .build();
    EmbeddedResponse response = new EmbeddedResponse();
    piranha.service(request, response);
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getResponseAsString().contains("Count: 0"));
    piranha.stop()
            .destroy();
}
 
Example #10
Source File: HSQLDBDataSourceProvider.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #11
Source File: HSQLDBDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #12
Source File: HSQLDBDataSourceProvider.java    From hypersistence-optimizer with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #13
Source File: AbstractTest.java    From hibernate-master-class with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #14
Source File: HSQLDBDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #15
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 #16
Source File: HSQLDBDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #17
Source File: HSQLDBDataSourceProvider.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends DataSource> dataSourceClassName() {
    return JDBCDataSource.class;
}
 
Example #18
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);
        }
    }