private boolean equals(Xid xid1, Xid xid2) { if (xid1 == xid2) { return true; } if (xid1 == null ^ xid2 == null) { return false; } return xid1.getFormatId() == xid2.getFormatId() && Arrays.equals(xid1.getBranchQualifier(), xid2.getBranchQualifier()) && Arrays.equals(xid1.getGlobalTransactionId(), xid2.getGlobalTransactionId()); }
public static void assertSameXids(final List<Xid> expected, final List<Xid> actual) { Assert.assertNotNull(expected); Assert.assertNotNull(actual); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { Xid expectedXid = expected.get(i); Xid actualXid = actual.get(i); UnitTestCase.assertEqualsByteArrays( expectedXid.getBranchQualifier(), actualXid.getBranchQualifier()); Assert.assertEquals(expectedXid.getFormatId(), actualXid.getFormatId()); UnitTestCase.assertEqualsByteArrays( expectedXid.getGlobalTransactionId(), actualXid.getGlobalTransactionId()); } }
@Override public boolean equals(final Object other) { if (this == other) { return true; } if (!(other instanceof Xid)) { return false; } Xid xother = (Xid) other; if (xother.getFormatId() != formatId) { return false; } if (xother.getBranchQualifier().length != branchQualifier.length) { return false; } if (xother.getGlobalTransactionId().length != globalTransactionId.length) { return false; } for (int i = 0; i < branchQualifier.length; i++) { byte[] otherBQ = xother.getBranchQualifier(); if (branchQualifier[i] != otherBQ[i]) { return false; } } for (int i = 0; i < globalTransactionId.length; i++) { byte[] otherGtx = xother.getGlobalTransactionId(); if (globalTransactionId[i] != otherGtx[i]) { return false; } } return true; }
int doTransaction(Xid xid, int mode, int command) throws XAException { int returnVal = -1; try { try { T4CTTIOtxen otxen = physicalConn.otxen; byte xidxid[] = null; byte gtrid[] = xid.getGlobalTransactionId(); byte bqual[] = xid.getBranchQualifier(); int gtrid_l = 0; int bqual_l = 0; if (gtrid != null && bqual != null) { gtrid_l = Math.min(gtrid.length, 64); bqual_l = Math.min(bqual.length, 64); xidxid = new byte[128]; System.arraycopy(gtrid, 0, xidxid, 0, gtrid_l); System.arraycopy(bqual, 0, xidxid, gtrid_l, bqual_l); } byte txctx[] = context; physicalConn.sendPiggyBackedMessages(); otxen.marshal(mode, txctx, xidxid, xid.getFormatId(), gtrid_l, bqual_l, timeout, command); returnVal = otxen.receive(errorNumber); } catch (IOException ioe) { DatabaseError.throwSqlException(ioe); } } catch (SQLException s) { errorNumber[0] = s.getErrorCode(); } if (errorNumber[0] == 0) { throw new XAException(-6); } if (returnVal == -1) { returnVal = errorNumber[0]; } return returnVal; }
@Override public byte[] serialize(Xid xid) { return ByteBuffer.allocate(this.size()) .putInt(xid.getFormatId()) .put(xid.getGlobalTransactionId()) .put(xid.getBranchQualifier()) .array(); }
/** Construct an XID as a clone of another XID. */ public JtdsXid(Xid xid) { fmtId = xid.getFormatId(); gtran = new byte[xid.getGlobalTransactionId().length]; System.arraycopy(xid.getGlobalTransactionId(), 0, gtran, 0, gtran.length); bqual = new byte[xid.getBranchQualifier().length]; System.arraycopy(xid.getBranchQualifier(), 0, bqual, 0, bqual.length); calculateHash(); }
public boolean equals(Object object) { if (object instanceof Xid) { Xid xid = (Xid) object; return xid.getFormatId() == 1 && Arrays.equals(xid.getGlobalTransactionId(), gid) && xid.getBranchQualifier() == null; } else { return false; } }
private void clearRemoteTransactions(Xid xid) { NodeEngine nodeEngine = getNodeEngine(); InternalPartitionService partitionService = nodeEngine.getPartitionService(); OperationService operationService = nodeEngine.getOperationService(); SerializableXID serializableXID = new SerializableXID( xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); Data xidData = nodeEngine.toData(serializableXID); int partitionId = partitionService.getPartitionId(xidData); ClearRemoteTransactionOperation operation = new ClearRemoteTransactionOperation(xidData); operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); }
@Override public boolean equals(Object other) { if (other instanceof Xid) { Xid xid = (Xid) other; if (xid.getFormatId() == formatId) { if (Arrays.equals(branchQualifier, xid.getBranchQualifier())) { if (Arrays.equals(globalTransactionId, xid.getGlobalTransactionId())) { return true; } } } } return false; }
private static byte[] toByteArray(final Xid xid) { byte[] branchQualifier = xid.getBranchQualifier(); byte[] globalTransactionId = xid.getGlobalTransactionId(); int formatId = xid.getFormatId(); byte[] hashBytes = new byte[branchQualifier.length + globalTransactionId.length + 4]; System.arraycopy(branchQualifier, 0, hashBytes, 0, branchQualifier.length); System.arraycopy( globalTransactionId, 0, hashBytes, branchQualifier.length, globalTransactionId.length); byte[] intBytes = new byte[4]; for (int i = 0; i < 4; i++) { intBytes[i] = (byte) ((formatId >> i * 8) % 0xFF); } System.arraycopy( intBytes, 0, hashBytes, branchQualifier.length + globalTransactionId.length, 4); return hashBytes; }
protected int doEnd(Xid xid, int flag) throws XAException { int returnVal = -1; synchronized (physicalConn) { synchronized (this) { try { try { T4CTTIOtxse otxse = physicalConn.otxse; byte xidxid[] = null; byte gtrid[] = xid.getGlobalTransactionId(); byte bqual[] = xid.getBranchQualifier(); int gtrid_l = 0; int bqual_l = 0; if (gtrid != null && bqual != null) { gtrid_l = Math.min(gtrid.length, 64); bqual_l = Math.min(bqual.length, 64); xidxid = new byte[128]; System.arraycopy(gtrid, 0, xidxid, 0, gtrid_l); System.arraycopy(bqual, 0, xidxid, gtrid_l, bqual_l); } byte txctx[] = context; int t4cflag = 0; if (((flag & 2) == 2 || (flag & 0x100000) != 0x100000) && (flag & 0x2000000) == 0x2000000) { t4cflag = 0x100000; } physicalConn.sendPiggyBackedMessages(); otxse.marshal(2, txctx, xidxid, xid.getFormatId(), gtrid_l, bqual_l, timeout, t4cflag); byte ctx[] = otxse.receive(applicationValueArr); if (ctx != null) { context = ctx; } returnVal = 0; } catch (IOException ioe) { DatabaseError.throwSqlException(ioe); } } catch (SQLException s) { returnVal = s.getErrorCode(); if (returnVal == 0) { throw new XAException(-6); } } } } return returnVal; }
public boolean equals(Object another) { if (another instanceof Xid) { Xid anotherAsXid = (Xid) another; if (this.myFormatId != anotherAsXid.getFormatId()) { return false; } byte[] otherBqual = anotherAsXid.getBranchQualifier(); byte[] otherGtrid = anotherAsXid.getGlobalTransactionId(); if (otherGtrid != null && otherGtrid.length == this.myGtrid.length) { int length = otherGtrid.length; for (int i = 0; i < length; i++) { if (otherGtrid[i] != this.myGtrid[i]) { return false; } } if (otherBqual != null && otherBqual.length == myBqual.length) { length = otherBqual.length; for (int i = 0; i < length; i++) { if (otherBqual[i] != this.myBqual[i]) { return false; } } } else { return false; } return true; } else { return false; } } else { return false; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Xid)) { return false; } Xid that = (Xid) o; if (formatId != that.getFormatId()) { return false; } if (!Arrays.equals(branchQualifier, that.getBranchQualifier())) { return false; } if (!Arrays.equals(globalTransactionId, that.getGlobalTransactionId())) { return false; } return true; }
private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException { NodeEngine nodeEngine = getNodeEngine(); InternalPartitionService partitionService = nodeEngine.getPartitionService(); OperationService operationService = nodeEngine.getOperationService(); SerializableXID serializableXID = new SerializableXID( xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); Data xidData = nodeEngine.toData(serializableXID); int partitionId = partitionService.getPartitionId(xidData); FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit); InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId); Integer errorCode; try { errorCode = future.get(); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } if (errorCode != null) { throw new XAException(errorCode); } }
protected int doStart(Xid xid, int flag) throws XAException { int returnVal = -1; synchronized (this.physicalConn) { synchronized (this) { if (this.isTransLoose) { flag |= 65536; } int swtch = flag & 0x8200000; if ((swtch == 134217728) && (OracleXid.isLocalTransaction(xid))) { return 0; } this.applicationValueArr[0] = 0; try { try { T4CTTIOtxse otxse = this.physicalConn.otxse; byte[] xidxid = null; byte[] gtrid = xid.getGlobalTransactionId(); byte[] bqual = xid.getBranchQualifier(); int gtrid_l = 0; int bqual_l = 0; if ((gtrid != null) && (bqual != null)) { gtrid_l = Math.min(gtrid.length, 64); bqual_l = Math.min(bqual.length, 64); xidxid = new byte['\u0080']; System.arraycopy(gtrid, 0, xidxid, 0, gtrid_l); System.arraycopy(bqual, 0, xidxid, gtrid_l, bqual_l); } int t4cflag = 0; if (((flag & 0x200000) != 0) || ((flag & 0x8000000) != 0)) t4cflag |= 4; else { t4cflag |= 1; } if ((flag & 0x100) != 0) { t4cflag |= 256; } if ((flag & 0x200) != 0) { t4cflag |= 512; } if ((flag & 0x400) != 0) { t4cflag |= 1024; } if ((flag & 0x10000) != 0) { t4cflag |= 65536; } this.physicalConn.sendPiggyBackedMessages(); otxse.marshal( 1, null, xidxid, xid.getFormatId(), gtrid_l, bqual_l, this.timeout, t4cflag); byte[] ctx = otxse.receive(this.applicationValueArr); if (ctx != null) { this.context = ctx; } returnVal = 0; } catch (IOException ioe) { DatabaseError.throwSqlException(ioe); } } catch (SQLException s) { returnVal = s.getErrorCode(); if (returnVal == 0) { throw new XAException(-6); } } } } return returnVal; }
private void forgetWithXid(int nodeIndex) { Xid xid = tx.getXid(); recoveryOps(nodeIndex) .forget(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); assertEquals(tt(1).getRemoteTxCount(), 0); // make sure tx has been removed }
public XATransactionId(final Xid xid) { this.formatId = xid.getFormatId(); this.globalTransactionId = xid.getGlobalTransactionId(); this.branchQualifier = xid.getBranchQualifier(); }
/** * Copy constructor * * @param other */ public XidImpl(final Xid other) { branchQualifier = copyBytes(other.getBranchQualifier()); formatId = other.getFormatId(); globalTransactionId = copyBytes(other.getGlobalTransactionId()); }
public void testInternalIdOnSameNode() throws Exception { Xid xid = tx.getXid(); recoveryOps(0) .forget(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); assertEquals(tt(1).getRemoteTxCount(), 0); // make sure tx has been removed }