Examples of BitronixTransactionManager


Examples of bitronix.tm.BitronixTransactionManager

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

    public void testJoinAfterSuspend() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.begin();

        if (log.isDebugEnabled()) log.debug("*** get C1");
        Connection c1 = poolingDataSource1.getConnection();
        c1.createStatement();
        c1.close();

        if (log.isDebugEnabled()) log.debug("*** get C2");
        Connection c2 = poolingDataSource2.getConnection();
        c2.createStatement();
        c2.close();

        Transaction tx = tm.suspend();
        tm.resume(tx);

        if (log.isDebugEnabled()) log.debug("*** get C3");
        Connection c3 = poolingDataSource2.getConnection();
        c3.createStatement();
        c3.close();

        if (log.isDebugEnabled()) log.debug("*** get C4");
        Connection c4 = poolingDataSource1.getConnection();
        c4.createStatement();
        c4.close();

        tm.commit();

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());

View Full Code Here

Examples of bitronix.tm.BitronixTransactionManager

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

    public void testReusePreparedStatementAfterSuspendResume() 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();

        Transaction tx = tm.suspend();
        tm.resume(tx);

        connection1.prepareStatement("some sql");

        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

Examples of bitronix.tm.BitronixTransactionManager

        TransactionManagerServices.getTransactionManager().shutdown(); // stop TM
    }

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

        if (log.isDebugEnabled()) log.debug("*** getting connection from CF1");
        Connection connection1 = poolingConnectionFactory1.createConnection();

        if (log.isDebugEnabled()) log.debug("*** creating session 1 on connection 1");
        Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);

        if (log.isDebugEnabled()) log.debug("*** creating queue 1 on session 1");
        Queue queue1 = session1.createQueue("queue");

        if (log.isDebugEnabled()) log.debug("*** creating producer1 on session 1");
        MessageProducer producer1 = session1.createProducer(queue1);

        if (log.isDebugEnabled()) log.debug("*** sending message on producer1");
        producer1.send(session1.createTextMessage("testSimpleWorkingCase"));


        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

Examples of bitronix.tm.BitronixTransactionManager

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


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

        XAPool pool1 = getPool(poolingDataSource1);

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

        assertEquals(POOL_SIZE, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE, pool1.inPoolSize());

        // check flow
View Full Code Here

Examples of bitronix.tm.BitronixTransactionManager

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

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

        // Use DataSource2 because it does not have shared accessible connections
        XAPool pool2 = getPool(poolingDataSource2);

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

        assertEquals(POOL_SIZE, pool2.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool2.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** getting connection 2 from DS1");
        Connection connection2 = poolingDataSource2.getConnection();
        connection2.createStatement();

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

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

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** closing connection 2");
        connection2.close();

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

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

        assertEquals(POOL_SIZE, pool2.inPoolSize());

        // check flow
View Full Code Here

Examples of bitronix.tm.BitronixTransactionManager

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

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

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

        if (log.isDebugEnabled()) log.debug("*** getting connection from DS2");
        Connection connection2 = poolingDataSource2.getConnection();
        connection2.createStatement();

        if (log.isDebugEnabled()) log.debug("*** closing connection 2");
        connection2.close();


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

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


        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

Examples of bitronix.tm.BitronixTransactionManager

    }


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

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

        XAPool pool1 = getPool(poolingDataSource1);

        assertEquals(POOL_SIZE, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** starting 2nd tx");
        tm.begin();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** closing connection 1 too eagerly within another context");
        try {
            // TODO: the ConnectionHandler 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());
        }
        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** committing 2nd tx");
        tm.commit();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

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

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

View Full Code Here

Examples of bitronix.tm.BitronixTransactionManager

        Configuration conf = TransactionManagerServices.getConfiguration();
        log.info(String.format("Started JTA for server ID '%s'.", conf.getServerId()));
  }

  public void stop(BundleContext context) throws Exception {
    BitronixTransactionManager tm = (BitronixTransactionManager) TransactionManagerServices.getTransactionManager();
        tm.shutdown();

        tmRegistration.unregister();
        utRegistration.unregister();

        for (ServiceRegistration reg : dsRegistrations.values()) {
View Full Code Here

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 cmObject = context.remove(EnvironmentName.ENTITY_MANAGER_FACTORY);
            if (cmObject != null) {
                try {
View Full Code Here

Examples of bitronix.tm.BitronixTransactionManager

                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }

            BitronixTransactionManager txm = TransactionManagerServices.getTransactionManager();
            if( txm != null ) {
                txm.shutdown();
            }

        }
       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.