Java Code Examples for javax.transaction.xa.XAResource#TMSUCCESS
The following examples show how to use
javax.transaction.xa.XAResource#TMSUCCESS .
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 xaEnd(Xid xid, int flags) throws XAException, ActiveMQException { Packet packet; if (flags == XAResource.TMSUSPEND) { packet = new PacketImpl(PacketImpl.SESS_XA_SUSPEND); } else if (flags == XAResource.TMSUCCESS) { packet = new SessionXAEndMessage(xid, false); } else if (flags == XAResource.TMFAIL) { packet = new SessionXAEndMessage(xid, true); } else { throw new XAException(XAException.XAER_INVAL); } SessionXAResponseMessage response = (SessionXAResponseMessage) sessionChannel.sendBlocking(packet, PacketImpl.SESS_XA_RESP); if (response.isError()) { 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: FBManagedConnection.java From jaybird with GNU Lesser General Public License v2.1 | 6 votes |
/** * Dissociates a resource from a global transaction. * * @throws XAException * Occurs when the state was not correct (end called twice), or the transaction ID is wrong. */ private void end(Xid id, int flags) throws XAException { if (flags != XAResource.TMSUCCESS && flags != XAResource.TMFAIL && flags != XAResource.TMSUSPEND) throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMSUCCESS, TMFAIL, TMSUSPEND", XAException.XAER_PROTO); internalEnd(id, flags); mcf.notifyEnd(this, id); inDistributedTransaction = false; try { // This will reset the managed environment of the associated connections and set the transaction coordinator to local // TODO This is a bit of a hack; need to find a better way setManagedEnvironment(isManagedEnvironment()); } catch (SQLException ex) { throw new FBXAException("Reset of managed state failed", XAException.XAER_RMERR, ex); } }
Example 4
Source File: LocalXAResource.java From ByteJTA with GNU Lesser General Public License v3.0 | 6 votes |
public synchronized void end(Xid xid, int flags) throws XAException { if (xid == null) { throw new XAException(XAException.XAER_INVAL); } else if (this.currentXid == null) { throw new XAException(XAException.XAER_PROTO); } else if (!this.currentXid.equals(xid)) { throw new XAException(XAException.XAER_PROTO); } else if (flags == XAResource.TMSUSPEND) { this.suspendXid = xid; this.suspendAutoCommit = this.originalAutoCommit; this.currentXid = null; this.originalAutoCommit = true; } else if (flags == XAResource.TMSUCCESS) { // delay the logging operation to the commit phase. // this.createTransactionLogIfNecessary(xid); } else if (flags == XAResource.TMFAIL) { logger.debug("Error occurred while ending local-xa-resource."); } else { throw new XAException(XAException.XAER_PROTO); } }
Example 5
Source File: TxLogManagedConnection.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ public void end(Xid xid, int flags) throws XAException { log.tracef("end(%s, %d)", xid, flags); if (flags == XAResource.TMSUCCESS) { addTxState(TX_XA_END_TMSUCCESS); } else if (flags == XAResource.TMFAIL) { addTxState(TX_XA_END_TMFAIL); } else if (flags == XAResource.TMSUSPEND) { addTxState(TX_XA_END_TMSUSPEND); } else { addTxState(TX_XA_END_UNKNOWN); } }
Example 6
Source File: CloudSpannerXAConnection.java From spanner-jdbc with MIT License | 5 votes |
/** * Preconditions: 1. Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND 2. xid != null 3. Connection is * associated with transaction xid * * Implementation deficiency preconditions: 1. Flags is not TMSUSPEND * * Postconditions: 1. connection is disassociated from the transaction. * * @see XAResource#end(Xid, int) */ @Override public void end(Xid xid, int flags) throws XAException { if (logger.logDebug()) { debug("ending transaction xid = " + xid); } // Check preconditions if (flags != XAResource.TMSUSPEND && flags != XAResource.TMFAIL && flags != XAResource.TMSUCCESS) { throw new CloudSpannerXAException(CloudSpannerXAException.INVALID_FLAGS, Code.INVALID_ARGUMENT, XAException.XAER_INVAL); } if (xid == null) { throw new CloudSpannerXAException(CloudSpannerXAException.XID_NOT_NULL, Code.INVALID_ARGUMENT, XAException.XAER_INVAL); } if (state != STATE_ACTIVE || !currentXid.equals(xid)) { throw new CloudSpannerXAException(CloudSpannerXAException.END_WITHOUT_START, Code.FAILED_PRECONDITION, XAException.XAER_PROTO); } // Check implementation deficiency preconditions if (flags == XAResource.TMSUSPEND) { throw new CloudSpannerXAException(CloudSpannerXAException.SUSPEND_NOT_IMPLEMENTED, Code.UNIMPLEMENTED, XAException.XAER_RMERR); } // We ignore TMFAIL. It's just a hint to the RM. We could roll back // immediately // if TMFAIL was given. // All clear. We don't have any real work to do. state = STATE_ENDED; }
Example 7
Source File: AtomikosTransactionAssistantImplTest.java From genericconnector with Apache License 2.0 | 5 votes |
private void testCloseDelistsResource(final int result) throws Exception { final UserTransactionManager tm = mock(UserTransactionManager.class); final Transaction tx = mock(Transaction.class); when(tm.getTransaction()).thenReturn(tx); MicroserviceXAResource ms = getMs(); final AtomicInteger count = new AtomicInteger(); ms.start(getXid(), 0); AtomikosTransactionAssistantImpl impl = new AtomikosTransactionAssistantImpl(ms){ @Override protected UserTransactionManager getTransactionManager() { return tm; } }; try{ //TEST impl.executeInActiveTransaction(new ExecuteCallback<Void>() { @Override public Void execute(String txid) throws Exception { count.incrementAndGet(); if(result == XAResource.TMSUCCESS){ return null; //no exception => TMSUCCESS }else{ throw new Exception(); // => TMFAIL } } }); if(result == XAResource.TMFAIL) fail("no exception"); }catch(Exception e){ if(result == XAResource.TMSUCCESS) fail("exception not expected"); } //TEST impl.close(); assertEquals(1, count.get()); verify(tx, times(1)).delistResource(eq(ms), eq(result)); }
Example 8
Source File: FBManagedConnection.java From jaybird with GNU Lesser General Public License v2.1 | 5 votes |
/** * The {@code internalEnd} method ends the xid as requested if appropriate and throws a XAException including the * appropriate XA error code and a message if not. The caller can decode the exception as necessary. * * @param xid * a {@code Xid} value * @param flags * an {@code int} value * @throws XAException * if an error occurs */ void internalEnd(Xid xid, int flags) throws XAException { if (log.isDebugEnabled()) log.debug("End called: " + xid); FbTransaction endingTr = xidMap.get(xid); if (endingTr == null) { throw new FBXAException("Unrecognized transaction", XAException.XAER_NOTA); } if (flags == XAResource.TMFAIL) { try { endingTr.rollback(); getGDSHelper().setCurrentTransaction(null); } catch (SQLException ex) { throw new FBXAException("can't rollback transaction", XAException.XAER_RMFAIL, ex); } } else if (flags == XAResource.TMSUCCESS) { if (gdsHelper != null && endingTr == gdsHelper.getCurrentTransaction()) { gdsHelper.setCurrentTransaction(null); } else { throw new FBXAException("You are trying to end a transaction that is not the current transaction", XAException.XAER_INVAL); } } else if (flags == XAResource.TMSUSPEND) { if (gdsHelper != null && endingTr == gdsHelper.getCurrentTransaction()) { gdsHelper.setCurrentTransaction(null); } else { throw new FBXAException("You are trying to suspend a transaction that is not the current transaction", XAException.XAER_INVAL); } } }
Example 9
Source File: EhcacheXAResource.java From ehcache3 with Apache License 2.0 | 5 votes |
@Override public void end(Xid xid, int flag) throws XAException { if (flag != XAResource.TMSUCCESS && flag != XAResource.TMFAIL) { throw new EhcacheXAException("End flag not supported : " + xaResourceFlagsToString(flag), XAException.XAER_INVAL); } if (currentXid == null) { throw new EhcacheXAException("Not started on : " + xid, XAException.XAER_PROTO); } TransactionId transactionId = new TransactionId(currentXid); XATransactionContext<K, V> transactionContext = transactionContextFactory.get(transactionId); if (transactionContext == null) { throw new EhcacheXAException("Cannot end unknown XID : " + xid, XAException.XAER_NOTA); } boolean destroyContext = false; if (flag == XAResource.TMFAIL) { destroyContext = true; } currentXid = null; try { if (transactionContext.hasTimedOut()) { destroyContext = true; throw new EhcacheXAException("Transaction timeout for XID : " + xid, XAException.XA_RBTIMEOUT); } } finally { if (destroyContext) { transactionContextFactory.destroy(transactionId); } } }
Example 10
Source File: LocalTx.java From reladomo with Apache License 2.0 | 4 votes |
@Override public int getEndFlag() { return XAResource.TMSUCCESS; }
Example 11
Source File: MultiThreadedTx.java From reladomo with Apache License 2.0 | 4 votes |
@Override public int getEndFlag() { return XAResource.TMSUCCESS; }
Example 12
Source File: TransactionImpl.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
private boolean delistResource(XAResourceArchive archive, int flag) throws SystemException { try { Xid branchXid = archive.getXid(); logger.info("{}> delist: xares= {}, branch= {}, flags= {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), archive, ByteUtils.byteArrayToString(branchXid.getBranchQualifier()), flag); switch (flag) { case XAResource.TMSUSPEND: archive.end(branchXid, flag); archive.setDelisted(true); archive.setSuspended(true); return true; case XAResource.TMFAIL: this.setRollbackOnlyQuietly(); case XAResource.TMSUCCESS: archive.end(branchXid, flag); archive.setDelisted(true); return true; default: return false; } } catch (XAException xae) { logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", xae); // Possible XAException values are XAER_RMERR, XAER_RMFAIL, // XAER_NOTA, XAER_INVAL, XAER_PROTO, or XA_RB*. switch (xae.errorCode) { case XAException.XAER_NOTA: // 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 false; case XAException.XAER_RMFAIL: // An error occurred that makes the resource manager unavailable. case XAException.XAER_RMERR: // An error occurred in dissociating the transaction branch from the thread of control. return false; // throw new SystemException(); default /* XA_RB* */ : return false; // throw new RollbackRequiredException(); } } catch (RuntimeException ex) { logger.error("XATerminatorImpl.delistResource(XAResourceArchive, int)", ex); throw new SystemException(); } }
Example 13
Source File: XASupport.java From jTDS with GNU Lesser General Public License v2.1 | 4 votes |
/** * Invoke the xa_end routine on the SQL Server. * * @param connection JDBC Connection enlisted in the transaction * @param xaConId the connection ID allocated by the server * @param xid the XA Transaction ID object * @param flags XA Flags for start command * @exception javax.transaction.xa.XAException * if an error condition occurs */ public static void xa_end(Connection connection, int xaConId, Xid xid, int flags) throws XAException { JtdsConnection con = (JtdsConnection)connection; if (con.isXaEmulation()) { // // Emulate xa_end method // JtdsXid lxid = new JtdsXid(xid); if (con.getXaState() != XA_START) { // Connection not started raiseXAException(XAException.XAER_PROTO); } JtdsXid tran = (JtdsXid)con.getXid(); if (tran == null || !tran.equals(lxid)) { raiseXAException(XAException.XAER_NOTA); } if (flags != XAResource.TMSUCCESS && flags != XAResource.TMFAIL) { // TMSUSPEND and TMMIGRATE cannot be supported raiseXAException(XAException.XAER_INVAL); } con.setXaState(XA_END); return; } // // Execute xa_end via MSDTC // int args[] = new int[5]; args[1] = XA_END; args[2] = xaConId; args[3] = XA_RMID; args[4] = flags; try { ((JtdsConnection) connection).sendXaPacket(args, toBytesXid(xid)); ((JtdsConnection) connection).enlistConnection(null); } catch (SQLException e) { raiseXAException(e); } if (args[0] != XAResource.XA_OK) { raiseXAException(args[0]); } }
Example 14
Source File: JDBCXAResource.java From evosql with Apache License 2.0 | 3 votes |
public void end(Xid xid, int flags) throws XAException { validateXid(xid); if (state != XA_STATE_STARTED) { throw new XAException("Invalid XAResource state"); } /** @todo - probably all flags can be ignored */ if (flags == XAResource.TMSUCCESS) {} state = XA_STATE_ENDED; }