Package javax.transaction.xa

Examples of javax.transaction.xa.Xid


   private void scheduledDelivery(final boolean tx) throws Exception
   {
      UnitTestCase.forceGC();

      Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

      ClientSessionFactory sessionFactory = locator.createSessionFactory();
      ClientSession session = sessionFactory.createSession(tx, false, false);
      session.createQueue(atestq, atestq, null, true);
      ClientProducer producer = session.createProducer(atestq);
View Full Code Here


         int msgReceived = 0;
         for (int i = 0; i < numberOfTX; i++)
         {
            ClientSession sessionConsumer = sf.createSession(true, false, false);
            Xid xid = newXID();
            xids.add(xid);
            sessionConsumer.start(xid, XAResource.TMNOFLAGS);
            sessionConsumer.start();
            ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
            for (int msgCount = 0; msgCount < messagesPerTX; msgCount++)
            {
               if (msgReceived == numberOfMessages)
               {
                  break;
               }
               msgReceived++;
               ClientMessage msg = consumer.receive(10000);
               assertNotNull(msg);
               msg.acknowledge();
            }
            sessionConsumer.end(xid, XAResource.TMSUCCESS);
            sessionConsumer.prepare(xid);
            sessionConsumer.close();
         }

         ClientSession sessionCheck = sf.createSession(true, true);

         ClientConsumer consumer = sessionCheck.createConsumer(PagingTest.ADDRESS);

         assertNull(consumer.receiveImmediate());

         sessionCheck.close();

         assertEquals(numberOfMessages, queue.getMessageCount());

         sf.close();
         locator.close();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());
         server.start();

         queue = server.locateQueue(ADDRESS);

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

         session = sf.createSession(true, false, false);

         consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         assertEquals(numberOfMessages, queue.getMessageCount());

         ClientMessage msg = consumer.receive(5000);
         if (msg != null)
         {
            System.out.println("Msg " + msg.getIntProperty("id"));

            while (true)
            {
               ClientMessage msg2 = consumer.receive(1000);
               if (msg2 == null)
               {
                  break;
               }
               System.out.println("Msg received again : " + msg2.getIntProperty("id"));

            }
         }
         assertNull(msg);

         for (int i = xids.size() - 1; i >= 0; i--)
         {
            Xid xid = xids.get(i);
            session.rollback(xid);
         }
         System.out.println("msgCount = " + queue.getMessageCount());

         xids.clear();
View Full Code Here

        try {
            XAConnection xac = xads.getXAConnection();

            XAResource xar = xac.getXAResource();

            Xid xid = XATestUtil.getXid(0, 32, 46);

            xar.start(xid, XAResource.TMNOFLAGS);

            Connection conn = xac.getConnection();
           
View Full Code Here

        System.out.println("interleavingTransactions");
        try {
            XAConnection xac = xads.getXAConnection("sku", "testxa");
            XAResource xar = xac.getXAResource();

            Xid xid1 = XATestUtil.getXid(1, 93, 18);
            Xid xid2 = XATestUtil.getXid(2, 45, 77);

            xar.start(xid1, XAResource.TMNOFLAGS);

            Connection conn = xac.getConnection();

            Statement s = conn.createStatement();
            s.executeUpdate("insert into APP.foo values (1)");
            xar.end(xid1, XAResource.TMSUSPEND);

            xar.start(xid2, XAResource.TMNOFLAGS);
            s.executeUpdate("insert into APP.foo values (2)");
            xar.end(xid2, XAResource.TMSUSPEND);

            xar.start(xid1, XAResource.TMRESUME);
            s.executeUpdate("insert into APP.foo values (3)");
            xar.end(xid1, XAResource.TMSUSPEND);

            xar.start(xid2, XAResource.TMRESUME);
            s.executeUpdate("insert into APP.foo values (4)");

            XATestUtil.showXATransactionView(conn);

            // this prepare won't work since
            // transaction 1 has been suspended - XA_PROTO
            try {
                xar.prepare(xid1);
                System.out.println("FAIL - prepare on suspended transaction");
            } catch (XAException e) {
                if (e.errorCode != XAException.XAER_PROTO)
                    XATestUtil.dumpXAException(
                            "FAIL - prepare on suspended transaction", e);

            }

            // check it was not prepared
            XATestUtil.showXATransactionView(conn);

            xar.end(xid2, XAResource.TMSUCCESS);

            xar.end(xid1, XAResource.TMSUCCESS);

            xar.prepare(xid1);
            xar.prepare(xid2);

            // both should be prepared.
            XATestUtil.showXATransactionView(conn);

            Xid[] recoveredStart = xar.recover(XAResource.TMSTARTRSCAN);
            System.out.println("recovered start " + recoveredStart.length);
            Xid[] recovered = xar.recover(XAResource.TMNOFLAGS);
            System.out.println("recovered " + recovered.length);
            Xid[] recoveredEnd = xar.recover(XAResource.TMENDRSCAN);
            System.out.println("recovered end " + recoveredEnd.length);

            for (int i = 0; i < recoveredStart.length; i++) {
                Xid xid = recoveredStart[i];
                if (xid.getFormatId() == 1) {
                    // commit 1 with 2pc
                    xar.commit(xid, false);
                } else if (xid.getFormatId() == 2) {
                    xar.rollback(xid);
                } else {
                    System.out.println("FAIL: unknown xact");
                }
            }

            // check the results
            Xid xid3 = XATestUtil.getXid(3, 2, 101);
            xar.start(xid3, XAResource.TMNOFLAGS);
            XATestUtil.showXATransactionView(conn);
            ResultSet rs = s.executeQuery("select * from APP.foo");
            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
            rs.close();
View Full Code Here

        System.out.println("noTransaction");
        try {
            XAConnection xac = xads.getXAConnection();
            XAResource xar = xac.getXAResource();

            Xid xid11 = XATestUtil.getXid(11, 3, 128);

            try {
                xar.start(xid11, XAResource.TMJOIN);
            } catch (XAException e) {
                if (e.errorCode != XAException.XAER_NOTA)
View Full Code Here

             xa_start xa_noflags 1;
             select * from global_xactTable where gxid is not null order by gxid,username;
             insert into foo values (3);
             */

            Xid xid = XATestUtil.getXid(1001, 66, 13);
            xar.start(xid, XAResource.TMNOFLAGS);
            XATestUtil.showXATransactionView(conn);
            s.executeUpdate("insert into APP.foo values (2003)");

            /*
             -- disallowed
             commit;
             -- disallowed
             rollback;
             -- disallowed
             autocommit on;
             -- OK
             autocommit off;
             */
            try {
                conn.commit();
                System.out.println("FAIL: commit allowed in global xact");
            } catch (SQLException e) {
            }

            try {
                conn.rollback();
                System.out.println("FAIL: roll back allowed in global xact");
            } catch (SQLException e) {
            }
            try {
                conn.setAutoCommit(true);
                System.out
                        .println("FAIL: setAutoCommit(true) allowed "+
         "in global xact");
            } catch (SQLException e) {
            }
            try {
                conn.setSavepoint();
                System.out
                    .println("FAIL: setSavepoint() allowed in global xact");
            } catch (SQLException e) {}
            try {
                conn.setSavepoint("badsavepoint");
                System.out
                    .println("FAIL: setAutoCommit(String) allowed in "+
                             "global xact");
            } catch (SQLException e) {}

            conn.setAutoCommit(false);

            // s was created in local mode so it has holdibilty
            // set, will execute but ResultSet will have close on commit

            if (TestUtil.isDerbyNetClientFramework()) { // DERBY-1158
            s.executeQuery("select * from APP.foo where A >= 2000").close();
            System.out.println("OK: query with holdable statement");
            }
            s.close();
           
           
            s = conn.createStatement();
            boolean holdable = s.getResultSetHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT;
            System.out.println("Statement created in global has holdabilty: "
                    + holdable);

            /*
             select * from foo;
             xa_end xa_success 1;
             xa_prepare 1;
             */
            ResultSet rs = s
                    .executeQuery("select * from APP.foo where A >= 2000");
            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
            rs.close();

            xar.end(xid, XAResource.TMSUCCESS);
            xar.prepare(xid);

            /*
             -- dup id
             xa_start xa_noflags 1;
             */
            try {
                xar.start(xid, XAResource.TMNOFLAGS);
                System.out.println("FAIL - start with duplicate XID");
            } catch (XAException e) {
                if (e.errorCode != XAException.XAER_DUPID)
                    throw e;
            }

            /*
             xa_start xa_noflags 2;
             -- still should disallow autommit;
             autocommit on;
             -- still should disallow commit and rollback
             commit;
             rollback;
             select * from global_xactTable where gxid is not null order by gxid,username;
             xa_end xa_suspend 2;
             */

            Xid xid2 = XATestUtil.getXid(1002, 23, 3);
            xar.start(xid2, XAResource.TMNOFLAGS);
            try {
                conn.commit();
                System.out.println("FAIL: commit allowed in global xact");
            } catch (SQLException e) {
            }
            try {
                conn.rollback();
                System.out.println("FAIL: roll back allowed in global xact");
            } catch (SQLException e) {
            }
            try {
                conn.setAutoCommit(true);
                System.out
                        .println("FAIL: setAutoCommit(true) allowed in global xact");
            } catch (SQLException e) {
            }
            conn.setAutoCommit(false);

            xar.end(xid2, XAResource.TMSUSPEND);

            /*
             -- get local connection again
             xa_getconnection;

             insert into foo values (5);

             -- autocommit should be on by default;
             commit;

             autocommit off;
             insert into foo values (6);

             -- commit and rollback is allowed on local connection
             rollback;

             insert into foo values (6);
             commit;
             */
            conn = xac.getConnection();
            s = conn.createStatement();
            s.executeUpdate("insert into APP.foo values (2005)");
            conn.commit();
            conn.setAutoCommit(false);
            s.executeUpdate("insert into APP.foo values (2006)");
            conn.rollback();
            s.executeUpdate("insert into APP.foo values (2007)");
            conn.commit();

            XATestUtil.showXATransactionView(conn);
            /*
             -- I am still able to commit other global transactions while I am attached to a
             -- local transaction.
             xa_commit xa_2phase 1;
             xa_end xa_success 2;
             xa_rollback 2;
             */
            xar.commit(xid, false);
            xar.end(xid2, XAResource.TMSUCCESS);
            xar.rollback(xid2);

            XATestUtil.showXATransactionView(conn);
            rs = s.executeQuery("select * from APP.foo where A >= 2000");
            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
            rs.close();

            conn.close();

            /*
             xa_getconnection;
             select * from global_xactTable where gxid is not null order by gxid,username;
             select * from foo;
             autocommit off;
             delete from foo;
             */
            conn = xac.getConnection();
            conn.setAutoCommit(false);
            s = conn.createStatement();
            s.executeUpdate("delete from app.foo");
            rs = s.executeQuery("select * from APP.foo");
            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
            rs.close();

            // DERBY-1004
            if (TestUtil.isDerbyNetClientFramework()) {
                System.out.println("DERBY-1004 Call conn.rollback to avoid exception with client");
                conn.rollback();
            }
            /*
             -- yanking a local connection away should rollback the changes
             */
            conn = xac.getConnection();
            conn.setAutoCommit(false);
            s = conn.createStatement();
            rs = s.executeQuery("select * from APP.foo where A >= 2000");
            JDBCDisplayUtil.DisplayResults(System.out, rs, conn);
            rs.close();

            /*
             -- cannot morph it if the local transaction is not idle
             xa_start xa_noflags 3;
             commit;
             -- now morph it to a global transaction
             xa_start xa_noflags 3;
             */
            Xid xid3 = XATestUtil.getXid(1003, 27, 9);
            try {
                xar.start(xid3, XAResource.TMNOFLAGS);
                System.out.println("FAIL XAResource.start on a global transaction with an active local transaction (autocommit false)");
            } catch (XAException xae) {
                if (xae.errorCode != XAException.XAER_OUTSIDE)
View Full Code Here

       
        try {
            XAConnection xac = xads.getXAConnection();
            XAResource xar = xac.getXAResource();

            Xid xid = XATestUtil.getXid(996, 9, 48);
           
            Connection conn = xac.getConnection();
           
            // Obtain Statements and PreparedStatements
            // with all the holdability options.
View Full Code Here

        tm = new TransactionManagerImpl(10 * 1000,
                new XidFactoryImpl("WHAT DO WE CALL IT?".getBytes()), null, null);
    }

    public void testImportXid() throws Exception {
        Xid externalXid = xidFactory.createXid();
        Transaction tx = tm.importXid(externalXid, 0);
        assertNotNull(tx);
        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
    }
View Full Code Here

        assertNotNull(tx);
        assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
    }

    public void testNoResourcesCommitOnePhase() throws Exception {
        Xid externalXid = xidFactory.createXid();
        Transaction tx = tm.importXid(externalXid, 0);
        tm.commit(tx, true);
        assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
    }
View Full Code Here

        tm.commit(tx, true);
        assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
    }

    public void testNoResourcesCommitTwoPhase() throws Exception {
        Xid externalXid = xidFactory.createXid();
        Transaction tx = tm.importXid(externalXid, 0);
        assertEquals(XAResource.XA_RDONLY, tm.prepare(tx));
        assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
    }
View Full Code Here

TOP

Related Classes of javax.transaction.xa.Xid

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.