List of usage examples for javax.transaction.xa Xid getBranchQualifier
byte[] getBranchQualifier();
From source file:com.taobao.metamorphosis.transaction.XATransactionId.java
public XATransactionId(final Xid xid, final String uniqueQualifier) { this.formatId = xid.getFormatId(); this.globalTransactionId = xid.getGlobalTransactionId(); this.branchQualifier = xid.getBranchQualifier(); this.uniqueQualifier = uniqueQualifier; if (StringUtils.isBlank(uniqueQualifier)) { throw new IllegalArgumentException("Blank uniqueQualifier"); }//from w w w .j a v a2s .c om }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
private boolean equals(final Xid xid1, final Xid xid2) { if (xid1 == xid2) { return true; }//from w ww .ja v a2 s .co m if (xid1 == null || xid2 == null) { return false; } return xid1.getFormatId() == xid2.getFormatId() && Arrays.equals(xid1.getBranchQualifier(), xid2.getBranchQualifier()) && Arrays.equals(xid1.getGlobalTransactionId(), xid2.getGlobalTransactionId()); }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public void recoverable(Xid xid) throws XAException { byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); String identifier = this.getIdentifier(globalTransactionId, branchQualifier); Connection conn = null;/*from ww w .ja va 2s. com*/ PreparedStatement stmt = null; ResultSet rs = null; try { conn = this.dataSource.getConnection(); stmt = conn.prepareStatement("select gxid, bxid from bytejta where xid = ?"); stmt.setString(1, identifier); rs = stmt.executeQuery(); if (rs.next() == false) { throw new XAException(XAException.XAER_NOTA); } } catch (SQLException ex) { try { this.isTableExists(conn); } catch (SQLException sqlEx) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } catch (RuntimeException rex) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } throw new XAException(XAException.XAER_RMERR); } catch (RuntimeException ex) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMERR); } finally { this.closeQuietly(rs); this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public synchronized void forget(Xid[] xids) throws XAException { if (xids == null || xids.length == 0) { return;// w ww . j a v a 2 s.c o m } String[] xidArray = new String[xids.length]; for (int i = 0; i < xids.length; i++) { Xid xid = xids[i]; byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); xidArray[i] = this.getIdentifier(globalTransactionId, branchQualifier); } Connection conn = null; PreparedStatement stmt = null; Boolean autoCommit = null; try { conn = this.dataSource.getConnection(); autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); stmt = conn.prepareStatement("delete from bytejta where xid = ?"); for (int i = 0; i < xids.length; i++) { stmt.setString(1, xidArray[i]); stmt.addBatch(); } stmt.executeBatch(); conn.commit(); } catch (Exception ex) { logger.error("Error occurred while forgetting resources."); try { conn.rollback(); } catch (Exception sqlEx) { logger.error("Error occurred while rolling back local resources.", sqlEx); } boolean tableExists = false; try { tableExists = this.isTableExists(conn); } catch (Exception sqlEx) { logger.warn("Error occurred while forgeting local resources.", ex); throw new XAException(XAException.XAER_RMFAIL); } if (tableExists) { throw new XAException(XAException.XAER_RMERR); } } finally { if (autoCommit != null) { try { conn.setAutoCommit(autoCommit); } catch (SQLException sqlEx) { logger.error("Error occurred while configuring attribute 'autoCommit'.", sqlEx); } } this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public synchronized void forget(Xid xid) throws XAException { if (xid == null) { logger.warn("Error occurred while forgeting local-xa-resource: invalid xid."); return;//w w w .j av a 2 s .c o m } byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); String identifier = this.getIdentifier(globalTransactionId, branchQualifier); Connection conn = null; PreparedStatement stmt = null; try { conn = this.dataSource.getConnection(); stmt = conn.prepareStatement("delete from bytejta where xid = ?"); stmt.setString(1, identifier); stmt.executeUpdate(); } catch (Exception ex) { boolean tableExists = false; try { tableExists = this.isTableExists(conn); } catch (Exception sqlEx) { logger.warn("Error occurred while forgeting local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } if (tableExists) { throw new XAException(XAException.XAER_RMERR); } } finally { this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytetcc.work.CleanupWork.java
public void forget(Xid xid, String resourceId) throws RuntimeException { byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); byte[] keyByteArray = resourceId.getBytes(); byte sizeOfkeyByteArray = (byte) keyByteArray.length; if (sizeOfkeyByteArray > CONSTANTS_RES_ID_MAX_SIZE) { throw new IllegalStateException("The resource name is too long!"); }/*from w ww.j a v a 2 s .c o m*/ byte[] resourceByteArray = new byte[CONSTANTS_RES_ID_MAX_SIZE]; System.arraycopy(keyByteArray, 0, resourceByteArray, 0, keyByteArray.length); ByteBuffer buffer = ByteBuffer.allocate(1 + CONSTANTS_RECORD_SIZE); buffer.put((byte) 0x1); buffer.put(globalTransactionId); buffer.put(branchQualifier); buffer.put(resourceByteArray); buffer.flip(); this.invokeForget(xid, resourceId, buffer); }
From source file:org.mule.util.xa.MuleXid.java
public MuleXid(Xid txId) { this.formatId = txId.getFormatId(); this.globalTransactionId = txId.getGlobalTransactionId(); this.branchQualifier = txId.getBranchQualifier(); }
From source file:org.mule.util.xa.MuleXid.java
@Override public boolean equals(Object obj) { if (!(obj instanceof Xid)) { return false; }/* w w w .j a va2s . c o m*/ Xid other = (Xid) obj; return Arrays.equals(getGlobalTransactionId(), other.getGlobalTransactionId()) && Arrays.equals(getBranchQualifier(), other.getBranchQualifier()) && getFormatId() == other.getFormatId(); }
From source file:org.mule.util.xa.MuleXid.java
@Override public int compareTo(Xid o) { if (formatId == o.getFormatId() && Arrays.equals(globalTransactionId, o.getGlobalTransactionId()) && Arrays.equals(branchQualifier, o.getBranchQualifier())) { return 0; }//from www . j a va 2 s.c o m return this.hashCode() > o.hashCode() ? 1 : -1; }
From source file:org.wso2.andes.client.XASession_9_1.java
/** * Send startDtx command to server/*from w w w . j av a 2s . c o m*/ * * @param xid q global transaction identifier to be associated with the resource * @param flag one of TMNOFLAGS, TMJOIN, or TMRESUME * @return XaStatus returned by server * @throws FailoverException when a connection issue is detected * @throws AMQException when an error is detected in AMQ state manager */ XaStatus startDtx(Xid xid, int flag) throws FailoverException, AMQException, XAException { throwErrorIfClosed(); DtxStartBody dtxStartBody = methodRegistry.createDtxStartBody(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier(), flag == XAResource.TMJOIN, flag == XAResource.TMRESUME); AMQMethodEvent amqMethodEvent = _connection._protocolHandler .syncWrite(dtxStartBody.generateFrame(_channelId), DtxStartOkBody.class); DtxStartOkBodyImpl response = (DtxStartOkBodyImpl) amqMethodEvent.getMethod(); return XaStatus.valueOf(response.getXaResult()); }