Java Code Examples for javax.transaction.xa.XAResource

The following examples show how to use javax.transaction.xa.XAResource. These examples are extracted from open source projects. 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 Project: gemfirexd-oss   Source File: NetXAConnection.java    License: Apache License 2.0 6 votes vote down vote up
public void readRollback() throws SqlException {
    NetXACallInfo callInfo = netCon.xares_.callInfoArray_
            [netCon.currXACallInfoOffset_];
    callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
    readLocalXARollback_();

    if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
        callInfo.xaFunction_ = NetXAResource.XAFUNC_ROLLBACK;
        netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0);
        callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
        throw netCon.xares_.exceptionsOnXA;
    }


    // for all XA connectiions
    // TODO:KATHEY - Do we need this?
    netCon.setXAState(netCon.XA_T0_NOT_ASSOCIATED);
}
 
Example 2
Source Project: lams   Source File: XAResourceWrapperImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isSameRM(XAResource resource) throws XAException
{
   if (overrideRmValue != null)
   {
      if (log.isTraceEnabled())
      {
         log.trace("Executing isSameRM with override value" + overrideRmValue + " for XAResourceWrapper" + this);
      }
      return overrideRmValue.booleanValue();
   }
   else
   {
      if (resource instanceof org.jboss.jca.core.spi.transaction.xa.XAResourceWrapper)
      {
         org.jboss.jca.core.spi.transaction.xa.XAResourceWrapper other =
            (org.jboss.jca.core.spi.transaction.xa.XAResourceWrapper)resource;
         return xaResource.isSameRM(other.getResource());
      }
      else
      {
         return xaResource.isSameRM(resource);
      }
      
   }
}
 
Example 3
Source Project: reladomo   Source File: TestSingleThreadedLocalTm.java    License: Apache License 2.0 6 votes vote down vote up
public void testCommitOneResource() throws Exception
{
    ExecutionOrder.start();
    this.tm.begin();
    Transaction tx = this.tm.getTransaction();
    ExceptionThrowingXaResource res = new ExceptionThrowingXaResource(false);
    assertTrue(tx.enlistResource(res));
    assertTrue(tx.delistResource(res, XAResource.TMSUCCESS));
    tx.commit();
    ExecutionOrder.verifyForThread(res, "start");
    ExecutionOrder.verifyForThread(res, "end");
    ExecutionOrder.verifyForThread(res, "commit");
    res.verify();
    res.verifyStartEndCommit(XAResource.TMNOFLAGS, XAResource.TMSUCCESS, true);
    postTransactionVerify();
}
 
Example 4
Source Project: ignite   Source File: WebSphereTmFactory.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
        @Override public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException,
            SystemException {
            if (xaRes == null)
                return false;

//            final XAResource res = new IgniteOnePhaseXAResource(xaRes);

            Object ibmProxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                new Class[] {onePhaseXAResourceCls},
                new InvocationHandler() {
                    @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
                        return mtd.invoke(xaRes, args);
                    }
                });

            return tx.enlistResource((XAResource)ibmProxy);
        }
 
Example 5
public Result providerInvoke(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
	String interfaceClazz = RpcContext.getContext().getUrl().getServiceInterface();

	boolean participantFlag = TransactionParticipant.class.getName().equals(interfaceClazz);
	boolean xaResourceFlag = XAResource.class.getName().equals(interfaceClazz);
	boolean coordinatorFlag = RemoteCoordinator.class.getName().equals(interfaceClazz);

	if (participantFlag == false && xaResourceFlag == false && coordinatorFlag == false) {
		return this.providerInvokeForSVC(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_RESOURCE_START)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else {
		return this.providerInvokeForTCC(invoker, invocation);
	}
}
 
Example 6
Source Project: ehcache3   Source File: EhcacheXAResource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Xid[] recover(int flags) throws XAException {
  if (flags != XAResource.TMNOFLAGS && flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != (XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN)) {
    throw new EhcacheXAException("Recover flags not supported : " + xaResourceFlagsToString(flags), XAException.XAER_INVAL);
  }

  if ((flags & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) {
    List<Xid> xids = new ArrayList<>();
    Set<TransactionId> transactionIds = journal.recover().keySet();
    for (TransactionId transactionId : transactionIds) {
      // filter-out in-flight tx
      if (!transactionContextFactory.contains(transactionId)) {
        xids.add(transactionId.getSerializableXid());
      }
    }
    return xids.toArray(new Xid[xids.size()]);
  }
  return new Xid[0];
}
 
Example 7
Source Project: tomee   Source File: JtaTransactionPolicy.java    License: Apache License 2.0 5 votes vote down vote up
public void enlistResource(final XAResource xaResource) throws SystemException {
    final Transaction transaction = getCurrentTransaction();
    if (transaction != null) {
        try {
            if (transaction.enlistResource(xaResource)) {
                return;
            }
        } catch (final Exception e) {
            throw new SystemException("Unable to enlist xa resource in the transaction", e);
        }
    }
    throw new SystemException("Unable to enlist xa resource in the transaction");
}
 
Example 8
Source Project: commons-dbcp   Source File: TestLocalXaResource.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testForgetMissingXid() throws XAException {
    final Xid xid = new TestXid();
    resource.start(xid, XAResource.TMNOFLAGS);
    resource.forget(null);
    assertEquals(xid, resource.getXid());
}
 
Example 9
Source Project: lams   Source File: SuspendableXAConnection.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void start(Xid xid, int arg1) throws XAException {
    switchToXid(xid);

    if (arg1 != XAResource.TMJOIN) {
        this.currentXAResource.start(xid, arg1);

        return;
    }

    //
    // Emulate join, by using resume on the same physical connection
    //

    this.currentXAResource.start(xid, XAResource.TMRESUME);
}
 
Example 10
Source Project: activemq-artemis   Source File: LVQRecoveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleMessagesAfterRecovery() throws Exception {
   Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes());
   ClientProducer producer = clientSessionXa.createProducer(address);
   SimpleString messageId1 = new SimpleString("SMID1");
   SimpleString messageId2 = new SimpleString("SMID2");
   clientSessionXa.start(xid, XAResource.TMNOFLAGS);
   ClientMessage m1 = createTextMessage(clientSession, "m1");
   m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
   ClientMessage m2 = createTextMessage(clientSession, "m2");
   m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
   ClientMessage m3 = createTextMessage(clientSession, "m3");
   m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
   ClientMessage m4 = createTextMessage(clientSession, "m4");
   m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
   producer.send(m1);
   producer.send(m2);
   producer.send(m3);
   producer.send(m4);
   clientSessionXa.end(xid, XAResource.TMSUCCESS);
   clientSessionXa.prepare(xid);

   clientSession.close();
   clientSessionXa.close();
   restartServer();

   clientSessionXa.commit(xid, false);
   ClientConsumer consumer = clientSession.createConsumer(qName1);
   clientSession.start();
   ClientMessage m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
   m = consumer.receive(1000);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}
 
Example 11
Source Project: mdw   Source File: MdwTransactionManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean enlistResource(XAResource arg0)
        throws IllegalStateException, RollbackException,
        SystemException {
    // TODO Auto-generated method stub
    return false;
}
 
Example 12
Source Project: reladomo   Source File: TestSingleThreadedLocalTm.java    License: Apache License 2.0 5 votes vote down vote up
public void testSerializable() throws Exception
{
    ExecutionOrder.start();
    this.tm.begin();
    Transaction tx = this.tm.getTransaction();
    ExceptionThrowingXaResource res = new ExceptionThrowingXaResource(false);
    assertTrue(tx.enlistResource(res));
    assertTrue(tx.delistResource(res, XAResource.TMSUCCESS));
    Xid reconstituted = (Xid) this.deserialize(this.serialize(res.getXid()));
    assertEquals(res.getXid(), reconstituted);
    tx.commit();
    res.verify();
    res.verifyStartEndCommit(XAResource.TMNOFLAGS, XAResource.TMSUCCESS, true);
    postTransactionVerify();
}
 
Example 13
Source Project: FHIR   Source File: RMXAConnectionResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void end(Xid xid, int flag) throws XAException {
    log.entering(this.getClass().getName(), "end");
    // log.fine(FHIRUtilities.getCurrentStacktrace());
    try {
        // Retrieve the XAResource(s) associated with this Xid.
        List<XAResource> resources = getXAResourcesForXid(xid);
        if (resources == null) {
            throw new XAException("end: Unknown Xid");
        }

        String xidString = displayXid(xid);
        log.info("Initiating recovery 'end' processing for Xid:\n" + xidString);

        // Make sure our artificial failures are not triggered during recovery processing :)
        setBypassFailures(Boolean.TRUE);

        // Drive the method calls to each of the XAResource instances.
        for (XAResource resource : resources) {
            resource.end(xid, flag);
        }
        
        log.info("Finished recovery 'end' processing for Xid:\n" + xidString);
    } finally {
        setBypassFailures(Boolean.FALSE);
        log.exiting(this.getClass().getName(), "end");
    }
}
 
Example 14
Source Project: tomee   Source File: LocalXAResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int prepare(final Xid xid) {
    checkLock();

    try {
        if (connection.isReadOnly()) {
            connection.setAutoCommit(originalAutoCommit);
            return XAResource.XA_RDONLY;
        }
    } catch (final SQLException ignored) {
        // no-op
    }

    return XAResource.XA_OK;
}
 
Example 15
Source Project: activemq-artemis   Source File: XaTimeoutTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * In case a timeout happens the server's object may still have the previous XID.
 * for that reason a new start call is supposed to clean it up with a log.warn
 * but it should still succeed
 *
 * @throws Exception
 */
@Test
public void testChangeXID() throws Exception {
   Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
   Xid xid2 = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());

   clientSession.start(xid, XAResource.TMNOFLAGS);
   clientSession.start(xid2, XAResource.TMNOFLAGS);

}
 
Example 16
/**
 * {@inheritDoc}
 */
public XAResourceWrapper createXAResourceWrapper(XAResource xares,
                                                 boolean pad, Boolean override, 
                                                 String productName, String productVersion,
                                                 String jndiName, boolean firstResource,
                                                 XAResourceStatistics xastat)
{
   if (firstResource)
   {
      if (xastat != null && xastat.isEnabled())
      {
         return new FirstResourceXAResourceWrapperStatImpl(xares, pad, override, productName, productVersion,
                                                           jndiName, xastat);
      }
      else
      {
         return new FirstResourceXAResourceWrapperImpl(xares, pad, override, productName, productVersion, jndiName);
      }
   }
   else
   {
      if (xastat != null && xastat.isEnabled())
      {
         return new XAResourceWrapperStatImpl(xares, pad, override, productName, productVersion, jndiName, xastat);
      }
      else
      {
         return new XAResourceWrapperImpl(xares, pad, override, productName, productVersion, jndiName);
      }
   }
}
 
Example 17
Source Project: FHIR   Source File: TestXAResource.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isSameRM(XAResource xares) throws XAException {
    log.entering(this.getClass().getName(), methodLabel("isSameRM"));
    try {
        return delegate.isSameRM(xares);
    } finally {
        log.exiting(this.getClass().getName(), methodLabel("isSameRM"));
    }
}
 
Example 18
Source Project: FHIR   Source File: TestXAConnection.java    License: Apache License 2.0 5 votes vote down vote up
public XAResource getXAResource() throws SQLException {
    log.entering(this.getClass().getName(), methodLabel("getXAResource"));
    try {
        XAResource resource = delegate.getXAResource();
        XAResource result = new TestXAResource(resource, dsLabel, failStep, failCount);
        return result;
    } finally {
        log.exiting(this.getClass().getName(), methodLabel("getXAResource"));
    }
}
 
Example 19
Source Project: ironjacamar   Source File: XAResourceWrapperImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new wrapper instance.
 * @param resource xaresource
 * @param override override
 * @param productName product name
 * @param productVersion product version
 * @param jndiName jndi name
 */   
public XAResourceWrapperImpl(XAResource resource, Boolean override, 
                             String productName, String productVersion,
                             String jndiName)
{
   this.xaResource = resource;
   this.overrideRmValue = override;
   this.productName = productName;
   this.productVersion = productVersion;
   this.jndiName = jndiName;
}
 
Example 20
protected void readXaStartUnitOfWork(NetConnection conn) throws DisconnectException {
    startSameIdChainParse();
    parseSYNCCTLreply(conn);
    // If we are joining or resuming a global transaction, we let the
    // server set the transcation isolation state for us.
    // Otherwise we do a normal reset.
    NetXACallInfo callInfo =
            conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    boolean keep = callInfo.xaFlags_ == XAResource.TMJOIN ||
            callInfo.xaFlags_ == XAResource.TMRESUME;
    conn.xares_.setKeepCurrentIsolationLevel(keep);
    endOfSameIdChainData();
}
 
Example 21
/**
 * Create a new instance of this class. Takes a session as parameter.
 * @param session session. If session is not of type {@link XAResource}, an
 *            <code>IllegalArgumentException</code> is thrown
 */
public JackRabbitUserTransaction(Session session) {
    //        if (session instanceof XASession) {
    //            xares = ((XASession) session).getXAResource();
    if (session instanceof XAResource) {
        xares = (XAResource) session;
    } else {
        throw new IllegalArgumentException("Session not of type XASession");
    }
}
 
Example 22
protected int readXaEndUnitOfWork(NetConnection conn) throws DisconnectException {
    // We have ended the XA unit of work, the next logical connection
    // should be reset using the normal procedure.
    conn.xares_.setKeepCurrentIsolationLevel(false);
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    int xaFlags = callInfo.xaFlags_;

    startSameIdChainParse();
    parseSYNCCTLreply(conn);
    endOfSameIdChainData();
    if (xaFlags == XAResource.TMFAIL) {
        return javax.transaction.xa.XAException.XA_RBROLLBACK;
    }
    return javax.transaction.xa.XAResource.XA_OK;
}
 
Example 23
Source Project: narayana-spring-boot   Source File: GenericRecoveryIT.java    License: Apache License 2.0 5 votes vote down vote up
private void setupXaMocks() throws Exception {
    List<Xid> xids = new LinkedList<>();
    // Save Xid provided during prepare
    when(this.xaResource.prepare(any(Xid.class)))
            .then(i -> {
                xids.add((Xid) i.getArguments()[0]);
                return XAResource.XA_OK;
            });
    // Return Xids when recovering
    when(this.xaResource.recover(anyInt()))
            .then(i -> xids.toArray(new Xid[xids.size()]));
    // Return XAResource when recovering
    when(this.xaResourceRecoveryHelper.getXAResources())
            .thenReturn(new XAResource[]{ this.xaResource });
}
 
Example 24
@Override
public XAResource[] getXAResources() {
    if (connect()) {
        return new XAResource[]{ this };
    }
    return NO_XA_RESOURCES;
}
 
Example 25
public boolean isSameRM(XAResource xares) throws XAException {
	if (XAResourceArchive.class.isInstance(xares)) {
		XAResourceArchive archive = (XAResourceArchive) xares;
		return descriptor.isSameRM(archive.getDescriptor());
	} else {
		return descriptor.isSameRM(xares);
	}
}
 
Example 26
Source Project: reladomo   Source File: MultiThreadedTx.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int preDelistCheck(MultiThreadedTx tx, int incomingFlag)
{
    if (incomingFlag == XAResource.TMFAIL)
    {
        logger.warn("transaction marked for rollback due to TMFAIL");
        tx.status.set(MARKED_ROLLBACK);
    }
    return incomingFlag;
}
 
Example 27
Source Project: gemfirexd-oss   Source File: ResourceAdapterImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Xid[] recover(int flags) throws StandardException {
  XAXactId[] ret_xid_list;

  if ((flags & XAResource.TMSTARTRSCAN) != 0) {
    XAXactId[] xid_list = new XAXactId[connectionTable.size()];
    int num_prepared = 0;

    // Need to hold sync while linear searching the hash table.
    synchronized (connectionTable) {
      int i = 0;

      for (Enumeration e = connectionTable.elements(); e.hasMoreElements(); i++) {
        XATransactionState xaTxnState = (XATransactionState)e.nextElement();

        if (xaTxnState.isPrepared()) {
          xid_list[i] = xaTxnState.getXId();
          num_prepared++;
        }
      }
    }

    // now need to squish the nulls out of the array to return.
    ret_xid_list = new XAXactId[num_prepared];
    int ret_index = 0;
    for (int i = xid_list.length; i-- > 0;) {
      if (xid_list[i] != null)
        ret_xid_list[ret_index++] = xid_list[i];
    }

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(ret_index == num_prepared);
    }
  }
  else {
    ret_xid_list = new XAXactId[0];
  }

  return (ret_xid_list);
}
 
Example 28
Source Project: clearpool   Source File: XAStatementHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void beforeInvoke(String methodName) throws XAException, SystemException {
  if (this.needTransaction(methodName)) {
    Transaction ts = TransactionManagerImpl.getManager().getTransaction();
    if (ts != null) {
      try {
        XAResource xaRes = this.xaCon.getXAResource();
        ts.enlistResource(xaRes);
      } catch (Exception e) {
        throw new ConnectionPoolException(e);
      }
    }
  }
}
 
Example 29
Source Project: gemfirexd-oss   Source File: ClientXAConnection.java    License: Apache License 2.0 5 votes vote down vote up
public XAResource getXAResource() throws SQLException {
    if (logWriter_ != null) {
        logWriter_.traceExit(this, "getXAResource", xares_);
    }

    return xares_;
}
 
Example 30
/**
 * {@inheritDoc}
 */
public boolean isSameRM(XAResource xares) throws XAException
{
   log.tracef("isSameRM(%s)", xares);

   if (this == xares)
      return true;

   return false;
}