Package bitronix.tm

Examples of bitronix.tm.BitronixTransactionManager


     *
     */
    public static void cleanUp(HashMap<String, Object> context) {
        if (context != null) {
           
            BitronixTransactionManager txm = TransactionManagerServices.getTransactionManager();
            if( txm != null ) {
                txm.shutdown();
            }
           
            Object emfObject = context.remove(ENTITY_MANAGER_FACTORY);
            if (emfObject != null) {
                try {
View Full Code Here


     *
     */
    public static void tearDown(HashMap<String, Object> context) {
        if (context != null) {
           
            BitronixTransactionManager txm = TransactionManagerServices.getTransactionManager();
            if( txm != null ) {
                txm.shutdown();
            }
           
            Object emfObject = context.remove(ENTITY_MANAGER_FACTORY);
            if (emfObject != null) {
                try {
View Full Code Here

    private final static Logger log = LoggerFactory.getLogger(NewJdbcSuspendResumeMockTest.class);

    public void testSimpleAssertions() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        assertNull(tm.suspend());

        try {
            tm.resume(null);
            fail("expected InvalidTransactionException");
        } catch (InvalidTransactionException ex) {
            assertEquals("resumed transaction cannot be null", ex.getMessage());
        }

        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");
    }
View Full Code Here

        if (log.isDebugEnabled()) log.debug("*** TX is done");
    }

    public void testSimpleWorkingCase() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** suspending");
        Transaction t1 = tm.suspend();

        if (log.isDebugEnabled()) log.debug("*** resuming");
        tm.resume(t1);

        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

    public void testNoTmJoin() throws Exception {
        poolingDataSource1.setUseTmJoin(false);

        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** suspending");
        Transaction t1 = tm.suspend();

        if (log.isDebugEnabled()) log.debug("*** resuming");
        tm.resume(t1);

        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testReEnlistmentAfterSuspend() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** suspending");
        Transaction t1 = tm.suspend();

        if (log.isDebugEnabled()) log.debug("*** before begin2");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin2");
        if (log.isDebugEnabled()) log.debug("*** reusing connection 1");
        connection1.createStatement();
        if (log.isDebugEnabled()) log.debug("*** marking subTX as rollback only");
        tm.setRollbackOnly();
        if (log.isDebugEnabled()) log.debug("*** rolling back");
        tm.rollback();
        if (log.isDebugEnabled()) log.debug("*** rolling back");

        if (log.isDebugEnabled()) log.debug("*** subTX is done");
        tm.resume(t1);

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testClosingSuspendedConnections() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** suspending");
        Transaction t1 = tm.suspend();

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** closing connection 1 too eagerly");
        try {
            // TODO: the TM tries to 'veto' the connection close here like the old pool did.
            // Instead, close the resource immediately or defer its release.
            connection1.close();
            fail("successfully closed a connection participating in a global transaction, this should never be allowed");
        } catch (SQLException ex) {
            assertEquals("cannot close a resource when its XAResource is taking part in an unfinished global transaction", ex.getCause().getMessage());
        }
        assertFalse(connection1.isClosed());

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** resuming");
        tm.resume(t1);

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testInterleavedLocalGlobalTransactions() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** suspending");
        Transaction t1 = tm.suspend();

        Connection connection2 = poolingDataSource1.getConnection();
        assertNull(tm.getTransaction());
        connection2.createStatement();
        connection2.close();

        if (log.isDebugEnabled()) log.debug("*** resuming");
        tm.resume(t1);

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testInterleavedGlobalGlobalTransactionsWithDifferentConnections() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug(" *** suspending transaction");
        Transaction t1 = tm.suspend();
        assertNull(tm.getTransaction());

        if (log.isDebugEnabled()) log.debug(" *** begin interleaved transaction");
        tm.begin();
        Connection connection2 = poolingDataSource1.getConnection();
        connection2.createStatement();
        connection2.close();
        if (log.isDebugEnabled()) log.debug(" *** commit interleaved transaction");
        tm.commit();

        if (log.isDebugEnabled()) log.debug(" *** resuming transaction");
        tm.resume(t1);

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testInterleavedGlobalGlobalTransactionsWithDifferentConnectionsLateSuspend() throws Exception {
        if (log.isDebugEnabled()) log.debug("*** getting TM");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) log.debug("*** before begin");
        tm.begin();
        if (log.isDebugEnabled()) log.debug("*** after begin");

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) log.debug("*** closing connection 1");
        connection1.close();

        if (log.isDebugEnabled()) log.debug(" *** suspending transaction");
        Transaction t1 = tm.suspend();
        assertNull(tm.getTransaction());

        if (log.isDebugEnabled()) log.debug(" *** begin interleaved transaction");
        tm.begin();
        Connection connection2 = poolingDataSource1.getConnection();
        assertEquals(POOL_SIZE -2, getPool(poolingDataSource1).inPoolSize());
        connection2.createStatement();
        connection2.close();
        if (log.isDebugEnabled()) log.debug(" *** commit interleaved transaction");
        tm.commit();
        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) log.debug(" *** resuming transaction");
        tm.resume(t1);

        if (log.isDebugEnabled()) log.debug("*** committing");
        tm.commit();
        if (log.isDebugEnabled()) log.debug("*** TX is done");
        assertEquals(POOL_SIZE, getPool(poolingDataSource1).inPoolSize());

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
View Full Code Here

TOP

Related Classes of bitronix.tm.BitronixTransactionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.