Search in sources :

Example 16 with JdbcDataSource

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

the class TestXA method testRollbackWithoutPrepare.

private void testRollbackWithoutPrepare() throws Exception {
    if (config.memory) {
        return;
    }
    Xid xid = new Xid() {

        @Override
        public int getFormatId() {
            return 3145;
        }

        @Override
        public byte[] getGlobalTransactionId() {
            return new byte[] { 1, 2, 3, 4, 5, 6, 6, 7, 8 };
        }

        @Override
        public byte[] getBranchQualifier() {
            return new byte[] { 34, 43, 33, 3, 3, 3, 33, 33, 3 };
        }
    };
    deleteDb("xa");
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(getURL("xa", true));
    ds.setPassword(getPassword());
    Connection dm = ds.getConnection();
    Statement stat = dm.createStatement();
    stat.execute("CREATE TABLE IF NOT EXISTS TEST(ID INT PRIMARY KEY, VAL INT)");
    stat.execute("INSERT INTO TEST(ID,VAL) VALUES (1,1)");
    dm.close();
    XAConnection c = ds.getXAConnection();
    XAResource xa = c.getXAResource();
    Connection connection = c.getConnection();
    xa.start(xid, XAResource.TMJOIN);
    PreparedStatement ps = connection.prepareStatement("UPDATE TEST SET VAL=? WHERE ID=?");
    ps.setInt(1, new Random().nextInt());
    ps.setInt(2, 1);
    ps.close();
    xa.rollback(xid);
    connection.close();
    c.close();
    deleteDb("xa");
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) Random(java.util.Random) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PreparedStatement(java.sql.PreparedStatement) XAConnection(javax.sql.XAConnection)

Example 17 with JdbcDataSource

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

the class TestMixinInterfaces method setUp.

@Before
public void setUp() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
    db = Jdbi.create(ds);
    db.installPlugin(new SqlObjectPlugin());
    handle = db.open();
    handle.execute("create table something (id int primary key, name varchar(100))");
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Before(org.junit.Before)

Example 18 with JdbcDataSource

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

the class TestOnDemandObjectMethodBehavior method setUp.

@Before
public void setUp() throws Exception {
    final JdbcDataSource ds = new JdbcDataSource() {

        private static final long serialVersionUID = 1L;

        @Override
        public Connection getConnection() throws SQLException {
            throw new UnsupportedOperationException();
        }
    };
    db = Jdbi.create(ds);
    db.installPlugin(new SqlObjectPlugin());
    dao = db.onDemand(UselessDao.class);
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Before(org.junit.Before)

Example 19 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project tutorials by eugenp.

the class PersistenceContextIntegrationTest method dataSource.

@Bean
public DataSource dataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setUrl(environment.getRequiredProperty("db.url"));
    dataSource.setUser(environment.getRequiredProperty("db.username"));
    dataSource.setPassword(environment.getRequiredProperty("db.password"));
    return dataSource;
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Bean(org.springframework.context.annotation.Bean)

Example 20 with JdbcDataSource

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

the class AbstractJdbcRepositoryIT method registerDataSource.

protected void registerDataSource() throws Exception {
    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");
    dataSource.setUser("sa");
    dataSource.setPassword("sa");
    setField(jdbcRepository, "datasource", dataSource);
    initDatabase();
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource)

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