Search in sources :

Example 46 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project che by eclipse.

the class H2DBTestServer method start.

@Override
public void start() {
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setUrl(getUrl() + ";DB_CLOSE_DELAY=-1");
    try (Connection conn = dataSource.getConnection()) {
        RunScript.execute(conn, new StringReader("SELECT 1"));
    } catch (SQLException x) {
        throw new RuntimeException(x);
    }
}
Also used : SQLException(java.sql.SQLException) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) StringReader(java.io.StringReader)

Example 47 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project ratpack by ratpack.

the class Example method main.

public static void main(String[] args) throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:transactionExamples;DB_CLOSE_DELAY=-1");
    txDs = Transaction.dataSource(ds);
    tx = Transaction.create(ds::getConnection);
    try (Connection connection = txDs.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate("CREATE TABLE tbl (value VARCHAR(50)) ");
        }
    }
    List<Block> examples = Arrays.asList(Example::singleTransactionExample, Example::singleTransactionRollbackExample, Example::nestedTransactionExample, Example::nestedTransactionRollbackExample, () -> manualTransactionExample(true), () -> manualTransactionExample(false));
    try (ExecHarness harness = ExecHarness.harness()) {
        for (Block example : examples) {
            harness.execute(Operation.of(example));
            reset();
        }
    }
}
Also used : Statement(java.sql.Statement) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) Block(ratpack.func.Block) ExecHarness(ratpack.test.exec.ExecHarness)

Example 48 with JdbcDataSource

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

the class H2Activator method start.

@Override
public void start(BundleContext context) throws Exception {
    ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put("dataSourceName", "test");
    context.registerService(DataSource.class.getName(), ds, props);
    loadData(ds);
    // Register the H2 console servlet
    Dictionary<String, String> servletProps = new Hashtable<String, String>();
    servletProps.put("alias", "/h2");
    servletProps.put("init.webAllowOthers", "true");
    context.registerService(Servlet.class.getName(), new WebServlet(), servletProps);
}
Also used : WebServlet(org.h2.server.web.WebServlet) Hashtable(java.util.Hashtable) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Servlet(javax.servlet.Servlet) WebServlet(org.h2.server.web.WebServlet) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 49 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project microservice_framework by CJSCommonPlatform.

the class TestDataSourceFactory method createDataSource.

public JdbcDataSource createDataSource() throws LiquibaseException, SQLException {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:test;MV_STORE=FALSE;MVCC=FALSE;DB_CLOSE_ON_EXIT=TRUE");
    dataSource.setUser("sa");
    dataSource.setPassword("sa");
    initDatabase();
    return dataSource;
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

Example 50 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project h2database by h2database.

the class OsgiDataSourceFactory method createXADataSource.

/**
 * Creates a pooled XA data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public XADataSource createXADataSource(Properties properties) throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }
    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);
    // The integrated connection pool is H2 is not configurable
    rejectPoolingOptions(propertiesCopy);
    JdbcDataSource dataSource = new JdbcDataSource();
    setupH2DataSource(dataSource, propertiesCopy);
    return dataSource;
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Properties(java.util.Properties)

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