org.apache.geronimo.transaction.manager.TransactionManagerImpl Java Examples

The following examples show how to use org.apache.geronimo.transaction.manager.TransactionManagerImpl. 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: GeronimoTransactionManagerFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void destroyResource() {
    // try to clean up
    try {
        final Field f = TransactionManagerImpl.class.getDeclaredField("retryScheduler");
        f.setAccessible(true);
        final ExponentialtIntervalRetryScheduler rs = ExponentialtIntervalRetryScheduler.class.cast(f.get(this));

        final Field t = ExponentialtIntervalRetryScheduler.class.getDeclaredField("timer");
        t.setAccessible(true);

        final Timer timer = Timer.class.cast(t.get(rs));
        timer.cancel();
    } catch (final Throwable notImportant) {
        // no-op
    }
    if (txLog != null) {
        try {
            HOWLLog.class.cast(txLog).doStop();
        } catch (final Throwable /*Exception + NoClassDefFoundError*/ e) {
            Logger.getInstance(LogCategory.OPENEJB, DestroyableTransactionManager.class).error(e.getMessage(), e);
        }
    }
}
 
Example #2
Source File: GeronimoConnectionManagerFactoryTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test // ensure we don't have an exception TOMEE-1806
public void eviction() throws Exception {
    final MyMcf mcf = new MyMcf();

    final GeronimoConnectionManagerFactory factory = new GeronimoConnectionManagerFactory();
    factory.setValidationInterval(new Duration("1 second"));
    factory.setTransactionSupport("local");
    factory.setMcf(mcf);
    factory.setPooling(true);
    factory.setPartitionStrategy("none");
    factory.setTransactionManager(new TransactionManagerImpl());
    factory.setPoolMinSize(1);
    factory.setAllConnectionsEqual(true);
    final GenericConnectionManager mgr = factory.create();
    mgr.doStart();
    try {
        mgr.allocateConnection(mcf, new ConnectionRequestInfo() { // just to use it
        });
        sleep(2500);
        assertTrue(mcf.evicted.get());
        assertTrue(mcf.destroyed.get());
    } finally {
        mgr.doStop();
    }
}
 
Example #3
Source File: GeronimoConnectionManagerFactoryTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
public void evictionNotAllEquals() throws Exception {
    final MyMcf mcf = new MyMcf();

    final GeronimoConnectionManagerFactory factory = new GeronimoConnectionManagerFactory();
    factory.setValidationInterval(new Duration("1 second"));
    factory.setTransactionSupport("local");
    factory.setMcf(mcf);
    factory.setPooling(true);
    factory.setPartitionStrategy("none");
    factory.setTransactionManager(new TransactionManagerImpl());
    factory.setPoolMinSize(1);
    factory.setAllConnectionsEqual(false);
    final GenericConnectionManager mgr = factory.create();
    mgr.doStart();
    try {
        mgr.allocateConnection(mcf, new ConnectionRequestInfo() { // just to use it
        });
        sleep(2500);
        assertTrue(mcf.evicted.get());
        assertTrue(mcf.destroyed.get());
    } finally {
        mgr.doStop();
    }
}
 
Example #4
Source File: TestTransactionContext.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * JIRA: DBCP-428
 */
@Test
public void testSetSharedConnectionEnlistFailure() throws Exception {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setUsername("userName");
        basicManagedDataSource.setPassword("password");
        basicManagedDataSource.setMaxIdle(1);
        try (final ManagedConnection<?> conn = (ManagedConnection<?>) basicManagedDataSource.getConnection()) {
            final UncooperativeTransaction transaction = new UncooperativeTransaction();
            final TransactionContext transactionContext = new TransactionContext(
                    basicManagedDataSource.getTransactionRegistry(), transaction);
            assertThrows(SQLException.class, () -> transactionContext.setSharedConnection(conn));
        }
    }
}
 
Example #5
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * JIRA: DBCP-294
 * Verify that PoolableConnections created by BasicManagedDataSource unregister themselves
 * when reallyClosed.
 */
@Test
public void testReallyClose() throws Exception {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setUsername("userName");
        basicManagedDataSource.setPassword("password");
        basicManagedDataSource.setMaxIdle(1);
        // Create two connections
        final ManagedConnection<?> conn = (ManagedConnection<?>) basicManagedDataSource.getConnection();
        assertNotNull(basicManagedDataSource.getTransactionRegistry().getXAResource(conn));
        final ManagedConnection<?> conn2 = (ManagedConnection<?>) basicManagedDataSource.getConnection();
        conn2.close(); // Return one connection to the pool
        conn.close(); // No room at the inn - this will trigger reallyClose(), which should unregister
        try {
            basicManagedDataSource.getTransactionRegistry().getXAResource(conn);
            fail("Expecting SQLException - XAResources orphaned");
        } catch (final SQLException ex) {
            // expected
        }
        conn2.close();
    }
}
 
Example #6
Source File: TestPersistence.java    From development with Apache License 2.0 5 votes vote down vote up
public TestPersistence() {
    try {
        this.transactionManager = new TransactionManagerImpl();
    } catch (XAException e) {
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: TestManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    final Properties properties = new Properties();
    properties.setProperty("user", "userName");
    properties.setProperty("password", "password");
    final ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

    // wrap it with a LocalXAConnectionFactory
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(transactionManager, connectionFactory);

    // create the pool object factory
    final PoolableConnectionFactory factory =
        new PoolableConnectionFactory(xaConnectionFactory, null);
    factory.setValidationQuery("SELECT DUMMY FROM DUAL");
    factory.setDefaultReadOnly(Boolean.TRUE);
    factory.setDefaultAutoCommit(Boolean.TRUE);

    // create the pool
    pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setMaxTotal(getMaxTotal());
    pool.setMaxWaitMillis(getMaxWaitMillis());

    // finally create the datasource
    ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry());
    ds.setAccessToUnderlyingConnectionAllowed(true);
}
 
Example #8
Source File: TestManagedConnection.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp()
    throws Exception {
    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    final Properties properties = new Properties();
    properties.setProperty("user", "userName");
    properties.setProperty("password", "password");
    final ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

    // wrap it with a LocalXAConnectionFactory
    final XAConnectionFactory xaConnectionFactory = new UncooperativeLocalXAConnectionFactory(transactionManager, connectionFactory);

    // create the pool object factory
    final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null);
    factory.setValidationQuery("SELECT DUMMY FROM DUAL");
    factory.setDefaultReadOnly(Boolean.TRUE);
    factory.setDefaultAutoCommit(Boolean.TRUE);

    // create the pool
    pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setMaxTotal(10);
    pool.setMaxWaitMillis(100);

    // finally create the datasource
    ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry());
    ds.setAccessToUnderlyingConnectionAllowed(true);
}
 
Example #9
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Override
protected BasicDataSource createDataSource() throws Exception {
    final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource();
    TransactionManagerImpl transactionManager = new TransactionManagerImpl();
    basicManagedDataSource.setTransactionManager(transactionManager);
    basicManagedDataSource.setTransactionSynchronizationRegistry(transactionManager);
    return basicManagedDataSource;
}
 
Example #10
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateXaDataSourceNewInstance() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setXADataSource(JdbcDataSource.class.getCanonicalName());
        basicManagedDataSource.setDriverClassName(Driver.class.getName());
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        assertNotNull(basicManagedDataSource.createConnectionFactory());
    }
}
 
Example #11
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateXaDataSourceNoInstanceSetAndNoDataSource() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        assertNotNull(basicManagedDataSource.createConnectionFactory());
    }
}
 
Example #12
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuntimeExceptionsAreRethrown() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setUsername("userName");
        basicManagedDataSource.setPassword("password");
        basicManagedDataSource.setMaxIdle(1);
        // results in a NPE
        assertThrows(NullPointerException.class, () -> basicManagedDataSource.createPoolableConnectionFactory(null));
    }
}
 
Example #13
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetXaDataSourceInstance() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setUsername("userName");
        basicManagedDataSource.setPassword("password");
        basicManagedDataSource.setMaxIdle(1);
        basicManagedDataSource.setXaDataSourceInstance(new JdbcDataSource());
        assertNotNull(basicManagedDataSource.createConnectionFactory());
    }
}
 
Example #14
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetNullXaDataSourceInstance() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver");
        basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver");
        basicManagedDataSource.setUsername("userName");
        basicManagedDataSource.setPassword("password");
        basicManagedDataSource.setMaxIdle(1);
        basicManagedDataSource.setXaDataSourceInstance(null);
        assertNull(basicManagedDataSource.getXaDataSourceInstance());
    }
}
 
Example #15
Source File: TestPoolableManagedConnection.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    final Properties properties = new Properties();
    properties.setProperty("user", "userName");
    properties.setProperty("password", "password");
    final ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

    // wrap it with a LocalXAConnectionFactory
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(transactionManager, connectionFactory);

    // create transaction registry
    transactionRegistry = xaConnectionFactory.getTransactionRegistry();

    // create the pool object factory
    final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null);
    factory.setValidationQuery("SELECT DUMMY FROM DUAL");
    factory.setDefaultReadOnly(Boolean.TRUE);
    factory.setDefaultAutoCommit(Boolean.TRUE);

    // create the pool
    pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setMaxTotal(10);
    pool.setMaxWaitMillis(100);
}
 
Example #16
Source File: TestDataSourceXAConnectionFactory.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeEach
public void setUp() throws Exception {
    super.setUp();
    bmds = new BasicManagedDataSource();
    bmds.setTransactionManager(new TransactionManagerImpl());
    bmds.setXADataSource("notnull");
    final XADataSourceHandle handle = new XADataSourceHandle();
    final XADataSource xads = (XADataSource) Proxy.newProxyInstance(
            XADataSourceHandle.class.getClassLoader(),
            new Class[] { XADataSource.class }, handle);
    bmds.setXaDataSourceInstance(xads);
}