Search in sources :

Example 1 with BasicManagedDataSource

use of org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource in project tomee by apache.

the class DefaultDataSourceCreator method poolManaged.

@Override
public DataSource poolManaged(final String name, final String driver, final Properties properties) {
    final BasicManagedDataSource ds = new BasicManagedDataSource(name);
    ds.setDriverClassName(driver);
    build(BasicManagedDataSource.class, ds, properties);
    return ds;
}
Also used : BasicManagedDataSource(org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource)

Example 2 with BasicManagedDataSource

use of org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource in project tomee by apache.

the class DataSourceDefinitionGlobalJPATest method check.

private void check(final DataSource ds, final String name) throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    // the first "cast part" is not important, we just want to check the jdbc url is ok
    assertThat(ds, instanceOf(BasicManagedDataSource.class));
    final BasicManagedDataSource dbcp = (BasicManagedDataSource) ds;
    final Connection connection = dbcp.getConnection();
    assertThat(connection, instanceOf(ManagedConnection.class));
    final ManagedConnection mc = (ManagedConnection) connection;
    final Method getInnermostDelegateInternal = DelegatingConnection.class.getDeclaredMethod("getInnermostDelegateInternal");
    getInnermostDelegateInternal.setAccessible(true);
    final Connection delegate = (Connection) getInnermostDelegateInternal.invoke(mc);
    assertThat(delegate, instanceOf(JDBCConnection.class));
    final Method getURL = JDBCConnection.class.getDeclaredMethod("getURL");
    getURL.setAccessible(true);
    assertEquals("jdbc:hsqldb:mem:" + name, getURL.invoke(delegate));
}
Also used : Connection(java.sql.Connection) ManagedConnection(org.apache.commons.dbcp2.managed.ManagedConnection) JDBCConnection(org.hsqldb.jdbc.JDBCConnection) DelegatingConnection(org.apache.commons.dbcp2.DelegatingConnection) ManagedConnection(org.apache.commons.dbcp2.managed.ManagedConnection) Method(java.lang.reflect.Method) BasicManagedDataSource(org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource) JDBCConnection(org.hsqldb.jdbc.JDBCConnection)

Example 3 with BasicManagedDataSource

use of org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource in project tomee by apache.

the class DefaultDataSourceCreator method poolManagedWithRecovery.

@Override
public DataSource poolManagedWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper, final String driver, final Properties properties) {
    final BasicManagedDataSource ds = new ManagedDataSourceWithRecovery(name, xaResourceWrapper);
    ds.setDriverClassName(driver);
    build(BasicManagedDataSource.class, ds, properties);
    return ds;
}
Also used : ManagedDataSourceWithRecovery(org.apache.openejb.resource.jdbc.dbcp.ManagedDataSourceWithRecovery) BasicManagedDataSource(org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource)

Example 4 with BasicManagedDataSource

use of org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource in project tomee by apache.

the class UnenhancedTest method createJtaDataSource.

private DataSource createJtaDataSource(final TransactionManager transactionManager) throws Exception {
    final BasicManagedDataSource ds = new BasicManagedDataSource(getClass().getName() + ".createJtaDs");
    ds.setTransactionManager(transactionManager);
    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUrl("jdbc:hsqldb:mem:JpaTest");
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setMaxTotal(100);
    ds.setMaxWait(10000);
    ds.setTestOnBorrow(true);
    return ds;
}
Also used : BasicManagedDataSource(org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource)

Example 5 with BasicManagedDataSource

use of org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource in project tomee by apache.

the class JpaTest method createJtaDataSource.

private DataSource createJtaDataSource(final TransactionManager transactionManager) throws Exception {
    final BasicManagedDataSource ds = new BasicManagedDataSource(getClass().getName() + "createJtaDs");
    ds.setTransactionManager(transactionManager);
    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUrl("jdbc:hsqldb:mem:JpaTest");
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setMaxTotal(100);
    ds.setMaxWait(10000);
    ds.setTestOnBorrow(true);
    return ds;
}
Also used : BasicManagedDataSource(org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource)

Aggregations

BasicManagedDataSource (org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource)5 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 DelegatingConnection (org.apache.commons.dbcp2.DelegatingConnection)1 ManagedConnection (org.apache.commons.dbcp2.managed.ManagedConnection)1 ManagedDataSourceWithRecovery (org.apache.openejb.resource.jdbc.dbcp.ManagedDataSourceWithRecovery)1 JDBCConnection (org.hsqldb.jdbc.JDBCConnection)1