Java Code Examples for javax.transaction.xa.XAResource#TMRESUME
The following examples show how to use
javax.transaction.xa.XAResource#TMRESUME .
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 File: ActiveMQSessionContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void xaStart(Xid xid, int flags) throws XAException, ActiveMQException { Packet packet; if (flags == XAResource.TMJOIN) { packet = new SessionXAJoinMessage(xid); } else if (flags == XAResource.TMRESUME) { packet = new SessionXAResumeMessage(xid); } else if (flags == XAResource.TMNOFLAGS) { // Don't need to flush since the previous end will have done this packet = new SessionXAStartMessage(xid); } else { throw new XAException(XAException.XAER_INVAL); } SessionXAResponseMessage response = (SessionXAResponseMessage) sessionChannel.sendBlocking(packet, PacketImpl.SESS_XA_RESP); if (response.isError()) { ActiveMQClientLogger.LOGGER.errorCallingStart(response.getMessage(), response.getResponseCode()); throw new XAException(response.getResponseCode()); } }
Example 2
Source File: ClientSessionImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
private String convertTXFlag(final int flags) { if (flags == XAResource.TMSUSPEND) { return "SESS_XA_SUSPEND"; } else if (flags == XAResource.TMSUCCESS) { return "TMSUCCESS"; } else if (flags == XAResource.TMFAIL) { return "TMFAIL"; } else if (flags == XAResource.TMJOIN) { return "TMJOIN"; } else if (flags == XAResource.TMRESUME) { return "TMRESUME"; } else if (flags == XAResource.TMNOFLAGS) { // Don't need to flush since the previous end will have done this return "TMNOFLAGS"; } else { return "XAER_INVAL(" + flags + ")"; } }
Example 3
Source File: TxLogManagedConnection.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ public void start(Xid xid, int flags) throws XAException { log.tracef("start(%s, %d)", xid, flags); if (flags == XAResource.TMNOFLAGS) { addTxState(TX_XA_START_TMNOFLAGS); } else if (flags == XAResource.TMJOIN) { addTxState(TX_XA_START_TMJOIN); } else if (flags == XAResource.TMRESUME) { addTxState(TX_XA_START_TMRESUME); } else { addTxState(TX_XA_START_UNKNOWN); } }
Example 4
Source File: NetXAConnectionReply.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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 5
Source File: NetXAConnectionReply.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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 6
Source File: FBManagedConnection.java From jaybird with GNU Lesser General Public License v2.1 | 5 votes |
/** * Associates a JDBC connection with a global transaction. We assume that * end will be called followed by prepare, commit, or rollback. If start is * called after end but before commit or rollback, there is no way to * distinguish work done by different transactions on the same connection). * If start is called more than once before end, either it's a duplicate * transaction ID or illegal transaction ID (since you can't have two * transactions associated with one DB connection). * * @param id * A global transaction identifier to be associated with the resource * @param flags * One of TMNOFLAGS, TMJOIN, or TMRESUME * @throws XAException * Occurs when the state was not correct (start called twice), the transaction ID is wrong, or the instance * has already been closed. */ private void start(Xid id, int flags) throws XAException { if (flags != XAResource.TMNOFLAGS && flags != XAResource.TMJOIN && flags != XAResource.TMRESUME) { throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMNOFLAGS, TMJOIN, TMRESUME", XAException.XAER_PROTO); } if (flags == XAResource.TMJOIN) { throw new FBXAException("Joining two transactions is not supported", XAException.XAER_RMFAIL); } try { // reset the transaction parameters for the managed scenario setTransactionIsolation(mcf.getDefaultTransactionIsolation()); internalStart(id, flags); mcf.notifyStart(this, id); inDistributedTransaction = true; // This will reset the managed environment of the associated connections and set the transaction coordinator to managed // TODO This is a bit of a hack; need to find a better way setManagedEnvironment(isManagedEnvironment()); } catch (SQLException e) { throw new FBXAException(XAException.XAER_RMERR, e); } }
Example 7
Source File: FBManagedConnection.java From jaybird with GNU Lesser General Public License v2.1 | 5 votes |
private void findIscTrHandle(Xid xid, int flags) throws SQLException, XAException { // FIXME return old tr handle if it is still valid before proceeding getGDSHelper().setCurrentTransaction(null); if (flags == XAResource.TMRESUME) { FbTransaction trHandle = xidMap.get(xid); if (trHandle == null) { throw new FBXAException( "You are trying to resume a transaction that is not attached to this XAResource", XAException.XAER_INVAL); } getGDSHelper().setCurrentTransaction(trHandle); return; } for (Xid knownXid : xidMap.keySet()) { boolean sameFormatId = knownXid.getFormatId() == xid.getFormatId(); boolean sameGtrid = Arrays.equals(knownXid.getGlobalTransactionId(), xid.getGlobalTransactionId()); boolean sameBqual = Arrays.equals(knownXid.getBranchQualifier(), xid.getBranchQualifier()); if (sameFormatId && sameGtrid && sameBqual) throw new FBXAException( "A transaction with the same XID has already been started", XAException.XAER_DUPID); } // new xid for us try { FbTransaction transaction = getGDSHelper().startTransaction(tpb.getTransactionParameterBuffer()); xidMap.put(xid, transaction); } catch (SQLException e) { throw new FBXAException(e.getMessage(), XAException.XAER_RMERR, e); } }
Example 8
Source File: TransactionCoordinator.java From ByteJTA with GNU Lesser General Public License v3.0 | 5 votes |
/** supports resume only, for tcc transaction manager. */ public void start(Xid xid, int flags) throws XAException { if (XAResource.TMRESUME != flags) { throw new XAException(XAException.XAER_INVAL); } TransactionManager transactionManager = this.beanFactory.getTransactionManager(); XidFactory xidFactory = this.beanFactory.getXidFactory(); Transaction current = transactionManager.getTransactionQuietly(); if (current != null) { throw new XAException(XAException.XAER_PROTO); } TransactionRepository transactionRepository = this.beanFactory.getTransactionRepository(); TransactionXid branchXid = (TransactionXid) xid; TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId()); Transaction transaction = null; try { transaction = transactionRepository.getTransaction(globalXid); } catch (TransactionException tex) { throw new XAException(XAException.XAER_RMERR); } if (transaction == null) { throw new XAException(XAException.XAER_NOTA); } transactionManager.associateThread(transaction); }
Example 9
Source File: LocalXAConnectionFactory.java From commons-dbcp with Apache License 2.0 | 5 votes |
/** * Signals that a the connection has been enrolled in a transaction. This method saves off the current auto * commit flag, and then disables auto commit. The original auto commit setting is restored when the transaction * completes. * * @param xid * the id of the transaction branch for this connection * @param flag * either XAResource.TMNOFLAGS or XAResource.TMRESUME * @throws XAException * if the connection is already enlisted in another transaction, or if auto-commit could not be * disabled */ @Override public synchronized void start(final Xid xid, final int flag) throws XAException { if (flag == XAResource.TMNOFLAGS) { // first time in this transaction // make sure we aren't already in another tx if (this.currentXid != null) { throw new XAException("Already enlisted in another transaction with xid " + xid); } // save off the current auto commit flag so it can be restored after the transaction completes try { originalAutoCommit = connection.getAutoCommit(); } catch (final SQLException ignored) { // no big deal, just assume it was off originalAutoCommit = true; } // update the auto commit flag try { connection.setAutoCommit(false); } catch (final SQLException e) { throw (XAException) new XAException("Count not turn off auto commit for a XA transaction") .initCause(e); } this.currentXid = xid; } else if (flag == XAResource.TMRESUME) { if (!xid.equals(this.currentXid)) { throw new XAException("Attempting to resume in different transaction: expected " + this.currentXid + ", but was " + xid); } } else { throw new XAException("Unknown start flag " + flag); } }
Example 10
Source File: NetXAConnectionReply.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
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 11
Source File: AbstractLuceneIndexerAndSearcherFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void start(Xid xid, int flag) throws XAException { Map<StoreRef, LuceneIndexer> active = activeIndexersInGlobalTx.get(xid); Map<StoreRef, LuceneIndexer> suspended = suspendedIndexersInGlobalTx.get(xid); if (flag == XAResource.TMJOIN) { // must be active if ((active != null) && (suspended == null)) { return; } else { throw new XAException("Trying to rejoin transaction in an invalid state"); } } else if (flag == XAResource.TMRESUME) { // must be suspended if ((active == null) && (suspended != null)) { suspendedIndexersInGlobalTx.remove(xid); activeIndexersInGlobalTx.put(xid, suspended); return; } else { throw new XAException("Trying to rejoin transaction in an invalid state"); } } else if (flag == XAResource.TMNOFLAGS) { if ((active == null) && (suspended == null)) { return; } else { throw new XAException("Trying to start an existing or suspended transaction"); } } else { throw new XAException("Unkown flags for start " + flag); } }
Example 12
Source File: XATransactionState.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
void start(EmbedXAResource resource, int flags) throws XAException { synchronized (this) { if (associationState == XATransactionState.TRO_FAIL) throw new XAException(rollbackOnlyCode); boolean isSuspendedByResource = (suspendedList != null) && (suspendedList.get(resource) != null); if (flags == XAResource.TMRESUME) { if (!isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } else { // cannot join a transaction we have suspended. if (isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } while (associationState == XATransactionState.T1_ASSOCIATED) { try { wait(); } catch (InterruptedException ie) { throw new XAException(XAException.XA_RETRY); } } switch (associationState) { case XATransactionState.T0_NOT_ASSOCIATED: break; case XATransactionState.TRO_DEADLOCK: case XATransactionState.TRO_TIMEOUT: case XATransactionState.TRO_FAIL: throw new XAException(rollbackOnlyCode); default: throw new XAException(XAException.XAER_NOTA); } if (isPrepared) throw new XAException(XAException.XAER_PROTO); if (isSuspendedByResource) { suspendedList.remove(resource); } associationState = XATransactionState.T1_ASSOCIATED; associatedResource = resource; } }
Example 13
Source File: XATransactionState.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
void start(EmbedXAResource resource, int flags) throws XAException { synchronized (this) { if (associationState == XATransactionState.TRO_FAIL) throw new XAException(rollbackOnlyCode); boolean isSuspendedByResource = (suspendedList != null) && (suspendedList.get(resource) != null); if (flags == XAResource.TMRESUME) { if (!isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } else { // cannot join a transaction we have suspended. if (isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } while (associationState == XATransactionState.T1_ASSOCIATED) { try { wait(); } catch (InterruptedException ie) { throw new XAException(XAException.XA_RETRY); } } switch (associationState) { case XATransactionState.T0_NOT_ASSOCIATED: break; case XATransactionState.TRO_DEADLOCK: case XATransactionState.TRO_TIMEOUT: case XATransactionState.TRO_FAIL: throw new XAException(rollbackOnlyCode); default: throw new XAException(XAException.XAER_NOTA); } if (isPrepared) throw new XAException(XAException.XAER_PROTO); if (isSuspendedByResource) { suspendedList.remove(resource); } associationState = XATransactionState.T1_ASSOCIATED; associatedResource = resource; } }
Example 14
Source File: TransactionImpl.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
private Boolean enlistResource(XAResourceArchive archive, int flag) throws SystemException { try { Xid branchXid = archive.getXid(); logger.info("{}> enlist: xares= {}, branch= {}, flags: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), archive, ByteUtils.byteArrayToString(branchXid.getBranchQualifier()), flag); switch (flag) { case XAResource.TMNOFLAGS: long expired = this.transactionContext.getExpiredTime(); long current = System.currentTimeMillis(); long remains = expired - current; int timeout = (int) (remains / 1000L); archive.setTransactionTimeout(timeout); archive.start(branchXid, flag); return true; case XAResource.TMJOIN: archive.start(branchXid, flag); archive.setDelisted(false); return false; case XAResource.TMRESUME: archive.start(branchXid, flag); archive.setDelisted(false); archive.setSuspended(false); return false; default: return null; } } catch (XAException xae) { logger.error("XATerminatorImpl.enlistResource(XAResourceArchive, int)", xae); // Possible exceptions are XA_RB*, XAER_RMERR, XAER_RMFAIL, // XAER_DUPID, XAER_OUTSIDE, XAER_NOTA, XAER_INVAL, or XAER_PROTO. switch (xae.errorCode) { case XAException.XAER_DUPID: // * If neither TMJOIN nor TMRESUME is specified and the transaction // * specified by xid has previously been seen by the resource manager, // * the resource manager throws the XAException exception with XAER_DUPID error code. return null; case XAException.XAER_OUTSIDE: // The resource manager is doing work outside any global transaction // on behalf of the application. case XAException.XAER_NOTA: // Either TMRESUME or TMJOIN was set inflags, and the specified XID is not // known by the resource manager. case XAException.XAER_INVAL: // Invalid arguments were specified. case XAException.XAER_PROTO: // The routine was invoked in an improper context. return null; case XAException.XAER_RMFAIL: // An error occurred that makes the resource manager unavailable case XAException.XAER_RMERR: // An error occurred in associating the transaction branch with the thread of control return null; default /* XA_RB **/ : // When a RollbackException is received, DBCP treats the state as STATUS_ROLLEDBACK, // but the actual state is still STATUS_MARKED_ROLLBACK. return null; // throw new RollbackException(); } } catch (RuntimeException ex) { logger.error("XATerminatorImpl.enlistResource(XAResourceArchive, int)", ex); throw new SystemException(); } }
Example 15
Source File: LocalXAResource.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
public synchronized void start(Xid xid, int flags) throws XAException { if (xid == null) { throw new XAException(XAException.XAER_INVAL); } else if (flags == XAResource.TMRESUME && this.suspendXid != null) { if (this.suspendXid.equals(xid)) { this.suspendXid = null; this.currentXid = xid; this.originalAutoCommit = this.suspendAutoCommit; this.suspendAutoCommit = true; return; } else { throw new XAException(XAException.XAER_PROTO); } } else if (flags == XAResource.TMJOIN) { if (this.currentXid == null) { throw new XAException(XAException.XAER_PROTO); } } else if (flags != XAResource.TMNOFLAGS) { throw new XAException(XAException.XAER_PROTO); } else if (this.currentXid != null) { throw new XAException(XAException.XAER_PROTO); } else { Connection connection = this.managedConnection.getPhysicalConnection(); try { originalAutoCommit = connection.getAutoCommit(); } catch (Exception ignored) { originalAutoCommit = true; } try { connection.setAutoCommit(false); } catch (Exception ex) { XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(ex); throw xae; } this.currentXid = xid; } }
Example 16
Source File: XATransactionState.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
void start(EmbedXAResource resource, int flags) throws XAException { synchronized (this) { if (associationState == XATransactionState.TRO_FAIL) throw new XAException(rollbackOnlyCode); boolean isSuspendedByResource = (suspendedList != null) && (suspendedList.get(resource) != null); if (flags == XAResource.TMRESUME) { if (!isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } else { // cannot join a transaction we have suspended. if (isSuspendedByResource) throw new XAException(XAException.XAER_PROTO); } while (associationState == XATransactionState.T1_ASSOCIATED) { try { wait(); } catch (InterruptedException ie) { throw new XAException(XAException.XA_RETRY); } } switch (associationState) { case XATransactionState.T0_NOT_ASSOCIATED: break; case XATransactionState.TRO_DEADLOCK: case XATransactionState.TRO_TIMEOUT: case XATransactionState.TRO_FAIL: throw new XAException(rollbackOnlyCode); default: throw new XAException(XAException.XAER_NOTA); } if (isPrepared) throw new XAException(XAException.XAER_PROTO); if (isSuspendedByResource) { suspendedList.remove(resource); } associationState = XATransactionState.T1_ASSOCIATED; associatedResource = resource; } }