Search in sources :

Example 36 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project spring-boot by spring-projects.

the class DataSourceBuilderTests method buildWhenH2TypeSpecifiedReturnsExpectedDataSource.

@Test
void buildWhenH2TypeSpecifiedReturnsExpectedDataSource() {
    this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").type(JdbcDataSource.class).username("test").password("secret").build();
    assertThat(this.dataSource).isInstanceOf(JdbcDataSource.class);
    JdbcDataSource h2DataSource = (JdbcDataSource) this.dataSource;
    assertThat(h2DataSource.getUser()).isEqualTo("test");
    assertThat(h2DataSource.getPassword()).isEqualTo("secret");
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.jupiter.api.Test)

Example 37 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project java-design-patterns by iluwatar.

the class HotelTest method createDataSource.

public static DataSource createDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setUrl(H2_DB_URL);
    return dataSource;
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 38 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project ignite by apache.

the class HibernateL2CacheTransactionalSelfTest method registryBuilder.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
    // JTA-aware data source.
    BasicManagedDataSource dataSrc = new BasicManagedDataSource();
    dataSrc.setTransactionManager(jotm.getTransactionManager());
    dataSrc.setDefaultAutoCommit(false);
    JdbcDataSource h2DataSrc = new JdbcDataSource();
    h2DataSrc.setURL(CONNECTION_URL);
    dataSrc.setXaDataSourceInstance(h2DataSrc);
    connProvider.setDataSource(dataSrc);
    connProvider.configure(Collections.emptyMap());
    builder.addService(ConnectionProvider.class, connProvider);
    builder.addService(JtaPlatform.class, new TestJtaPlatform());
    builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
    return builder;
}
Also used : JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DatasourceConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) BasicManagedDataSource(org.apache.commons.dbcp.managed.BasicManagedDataSource) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project sql2o by aaberg.

the class H2Tests method testIssue172NPEWhenCreatingBasicDataSourceInline.

@Test
public void testIssue172NPEWhenCreatingBasicDataSourceInline() {
    DataSource ds = new JdbcDataSource() {

        {
            setURL(url);
            setUser(user);
            setPassword(pass);
        }
    };
    Sql2o sql2o = new Sql2o(ds);
    assertThat(sql2o.getQuirks(), is(instanceOf(H2Quirks.class)));
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Sql2o(org.sql2o.Sql2o) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 40 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project spf4j by zolyfarkas.

the class JdbcSemaphoreTest method testPerformance.

@Test
@Ignore
public void testPerformance() throws SQLException, IOException, InterruptedException, ExecutionException, TimeoutException {
    int port = PORT.getAndIncrement();
    Server server = Server.createTcpServer(new String[] { "-tcpPort", Integer.toString(port), "-ifNotExists" }).start();
    try {
        File tempDB = File.createTempFile("test", "h2db");
        tempDB.deleteOnExit();
        String connStr = "jdbc:h2:tcp://localhost:" + port + "/nio:" + tempDB.getAbsolutePath() + ";AUTO_SERVER=TRUE";
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(connStr);
        ds.setUser("sa");
        ds.setPassword("sa");
        createSchemaObjects(ds);
        JdbcSemaphore semaphore = new JdbcSemaphore(ds, "test_sem2", 1, true);
        Sampler s = new Sampler(5, 5000);
        s.registerJmx();
        s.start();
        LOG.info("started sampling");
        long deadline = TimeSource.nanoTime() + TimeUnit.SECONDS.toNanos(10);
        do {
            semaphore.acquire(1, 1, TimeUnit.SECONDS);
            semaphore.release();
        } while (deadline > TimeSource.nanoTime());
        semaphore.close();
        s.stop();
        LOG.debug("dumped samples to {}", s.dumpToFile());
    } finally {
        JdbcHeartBeat.stopHeartBeats();
        server.shutdown();
    }
}
Also used : Server(org.h2.tools.Server) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Sampler(org.spf4j.stackmonitor.Sampler) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JdbcDataSource (org.h2.jdbcx.JdbcDataSource)81 Connection (java.sql.Connection)24 Test (org.junit.Test)24 Before (org.junit.Before)15 XAResource (javax.transaction.xa.XAResource)13 DataSource (javax.sql.DataSource)9 Xid (javax.transaction.xa.Xid)9 SQLException (java.sql.SQLException)8 InitialContext (javax.naming.InitialContext)8 XAConnection (javax.sql.XAConnection)8 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)7 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)7 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)7 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)7 Statement (java.sql.Statement)7 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)7 File (java.io.File)6 Enumeration (java.util.Enumeration)6 Properties (java.util.Properties)6 Vector (java.util.Vector)6