Package javax.sql

Examples of javax.sql.XAConnection


        new XATransactionTester().run(args);
    }

    public void run(String[] args) throws Exception {
        ds = getDataSource(args);
        XAConnection xaConn = ds.getXAConnection("test", "test");
        XAResource xaRes = xaConn.getXAResource();
        manager = new TransactionManagerImpl(10,
                new XidFactoryImpl("WHAT DO WE CALL IT?".getBytes()),
                new DummyLog(), null);
        Connection c = xaConn.getConnection();
        Statement s = c.createStatement();

        manager.begin();
        manager.getTransaction().enlistResource(xaRes);
        s.execute("UPDATE XA_TEST SET X=X+1");
View Full Code Here


         * @return a <code>Connection</code> value
         * @exception SQLException if an error occurs
         */
        protected Connection newConnection_() throws SQLException {
            XADataSource ds = TestDataSourceFactory.getXADataSource();
            XAConnection xac = ds.getXAConnection(TestConfiguration.getCurrent().getUserName(),
                    TestConfiguration.getCurrent().getUserPassword());
            return xac.getConnection();
        }
View Full Code Here

        else
          xaHelper.setDataSourceProperty(currentXADataSource,
                           "createDatabase", "create");

        /* do a getXAConnection to create it */
        XAConnection conn = currentXADataSource.getXAConnection();
        conn.close();
       
        xaHelper.setDataSourceProperty(currentXADataSource, "createDatabase", null);
      }
    }
    catch (Throwable t)
View Full Code Here

      Properties attrs = new Properties();
      attrs.setProperty("databaseName", "wombat");
      attrs.setProperty("connectionAttributes", "create=true");
      XADataSource dscsx =  TestUtil.getXADataSource(attrs);
   
      XAConnection xac = dscsx.getXAConnection("fred", "wilma");
      XAResource xr = xac.getXAResource();
      Xid xid = getXid(25, (byte) 21, (byte) 01);
      Connection conn1 = xac.getConnection();
      System.out.println("By default, autocommit is " + conn1.getAutoCommit() + " for a connection");
      System.out.println("Default holdability for a connection is HOLD_CURSORS_OVER_COMMIT");
      System.out.println("CONNECTION(not in xa transaction yet) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
      //start a global transaction and default holdability and autocommit will be switched to match Derby XA restrictions
      xr.start(xid, XAResource.TMNOFLAGS);
      System.out.println("Notice that autocommit now is " + conn1.getAutoCommit() + " for connection because it is part of the global transaction");
      System.out.println("Notice that connection's holdability at this point is CLOSE_CURSORS_AT_COMMIT because it is part of the global transaction");
      System.out.println("CONNECTION(in xa transaction) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
      xr.end(xid, XAResource.TMSUCCESS);
      conn1.commit();
      conn1.close();

      xid = getXid(27, (byte) 21, (byte) 01);
      xr.start(xid, XAResource.TMNOFLAGS);
      conn1 = xac.getConnection();
      System.out.println("CONNECTION(in xa transaction) HOLDABILITY " + (conn1.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));
      System.out.println("Autocommit on Connection inside global transaction has been set correctly to " + conn1.getAutoCommit());
      xr.end(xid, XAResource.TMSUCCESS);
      conn1.rollback();

      Connection conn = xac.getConnection();
      conn.setAutoCommit(false);
      conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
      System.out.println("CONNECTION(non-xa) HOLDABILITY " + (conn.getHoldability() == ResultSet.HOLD_CURSORS_OVER_COMMIT));

      Statement s = conn.createStatement();
View Full Code Here

    testPooledConnIso("PooledConnection" , pc1);  
        pc1.close();
      
        // Test xa connection isolation
    XADataSource xds = TestUtil.getXADataSource(p);
      XAConnection xpc1 = xds.getXAConnection();       
        testPooledConnIso("XAConnection", xpc1);                
        xpc1.close();
      }
View Full Code Here

    @Override
    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
        if (method.getName().equals("getConnection") && method.getParameterTypes().length == 0 && delegate instanceof XADataSource) {
            final XADataSource xa = (XADataSource) delegate;
            final XAConnection xaConn = xa.getXAConnection();
            final Object transactionKey = synchronizationRegistry.getTransactionKey();
            if (!registeredTransactions.contains(transactionKey)) {
                if (transactionManager.getTransaction() != null && transactionActive(transactionManager.getTransaction().getStatus())) {
                    transactionManager.getTransaction().enlistResource(xaConn.getXAResource());
                    synchronizationRegistry.registerInterposedSynchronization(new Sync(transactionKey));
                    registeredTransactions.add(transactionKey);
                }
            }
            return xaConn.getConnection();
        } else {
            final Object ret = method.invoke(delegate, args);
            return ret;
        }
    }
View Full Code Here

        // Create the database and a table
        xads = new EmbeddedXADataSource();
        xads.setDatabaseName("target/test");
        xads.setCreateDatabase("create");

        XAConnection xaconn = xads.getXAConnection();
        Connection conn = xaconn.getConnection();
        PreparedStatement ps =
            conn.prepareStatement("create table SavingsAccounts(accountNumber char(100), balance float)");
        try {
            ps.execute();
        } catch (SQLException ex) {
View Full Code Here

    }

    @Override
    protected float load(String accountNumber) throws AccountNotFoundException {
        try {
            XAConnection xaconn = xads.getXAConnection();

            Connection conn = xaconn.getConnection();
            PreparedStatement ps = conn.prepareStatement("select balance from SavingsAccounts where accountNumber=?");
            ps.setString(1, accountNumber);
            ResultSet rs1 = ps.executeQuery();
            boolean found = rs1.next();
            if (found) {
View Full Code Here

    }

    @Override
    protected void save(String accountNumber, float balance) throws AccountNotFoundException {
        try {
            XAConnection xaconn = xads.getXAConnection();

            Connection conn = xaconn.getConnection();
            PreparedStatement ps = conn.prepareStatement("update SavingsAccounts set balance=? where accountNumber=?");
            ps.setFloat(1, balance);
            ps.setString(2, accountNumber);
            int rows = ps.executeUpdate();
            conn.commit();
View Full Code Here

        }
    }

    @Destroy
    public void destroy() throws SQLException {
        XAConnection xaconn = xads.getXAConnection();
        Connection conn = xaconn.getConnection();
        PreparedStatement ps = conn.prepareStatement("drop table SavingsAccounts");
        ps.execute();
        conn.commit();
        conn.close();
    }
View Full Code Here

TOP

Related Classes of javax.sql.XAConnection

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.