Refine search
public static int getXidEncodeLength(final Xid xid) { return DataConstants.SIZE_INT * 3 + xid.getBranchQualifier().length + xid.getGlobalTransactionId().length; }
public XATransactionId(Xid xid) { this.formatId = xid.getFormatId(); this.globalTransactionId = xid.getGlobalTransactionId(); this.branchQualifier = xid.getBranchQualifier(); }
public String getNameFromXid(@NotNull final Xid xid) { final int formatId = xid.getFormatId(); if (formatId == 0x20000 || formatId == 0x20005 || formatId == 0x20008) { final byte[] gtid = xid.getGlobalTransactionId(); final int length = gtid.length; if (length <= UID_LEN) { // no parent name encoded there return null; } return new String(gtid, UID_LEN, length - UID_LEN, StandardCharsets.UTF_8); } else { return null; } }
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 void forget(Xid xid, String resourceId) throws RuntimeException { byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); byte[] keyByteArray = resourceId.getBytes(); if (keyByteArray.length > CONSTANTS_RES_ID_MAX_SIZE) { throw new IllegalStateException("The resource name is too long!"); } 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); }
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"); } }
public static Map<byte[], byte[]> serialize(ObjectSerializer serializer, Transaction transaction) { Map<byte[], byte[]> map = new HashMap<byte[], byte[]>(); map.put("GLOBAL_TX_ID".getBytes(), transaction.getXid().getGlobalTransactionId()); map.put("BRANCH_QUALIFIER".getBytes(), transaction.getXid().getBranchQualifier()); map.put("STATUS".getBytes(), ByteUtils.intToBytes(transaction.getStatus().getId())); map.put("TRANSACTION_TYPE".getBytes(), ByteUtils.intToBytes(transaction.getTransactionType().getId())); map.put("RETRIED_COUNT".getBytes(), ByteUtils.intToBytes(transaction.getRetriedCount())); map.put("CREATE_TIME".getBytes(), DateFormatUtils.format(transaction.getCreateTime(), "yyyy-MM-dd HH:mm:ss").getBytes()); map.put("LAST_UPDATE_TIME".getBytes(), DateFormatUtils.format(transaction.getLastUpdateTime(), "yyyy-MM-dd HH:mm:ss").getBytes()); map.put("VERSION".getBytes(), ByteUtils.longToBytes(transaction.getVersion())); map.put("CONTENT".getBytes(), serializer.serialize(transaction)); map.put("CONTENT_VIEW".getBytes(), JSON.toJSONString(transaction).getBytes()); return map; }
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; }
public static byte[] serialize(ObjectSerializer serializer, Transaction transaction) { Map<String, Object> map = new HashMap<String, Object>(); map.put("GLOBAL_TX_ID", transaction.getXid().getGlobalTransactionId()); map.put("BRANCH_QUALIFIER", transaction.getXid().getBranchQualifier()); map.put("STATUS", transaction.getStatus().getId()); map.put("TRANSACTION_TYPE", transaction.getTransactionType().getId()); map.put("RETRIED_COUNT", transaction.getRetriedCount()); map.put("CREATE_TIME", transaction.getCreateTime()); map.put("LAST_UPDATE_TIME", transaction.getLastUpdateTime()); map.put("VERSION", transaction.getVersion()); map.put("CONTENT", serializer.serialize(transaction)); return serializer.serialize(map); }
/** * Create a {@link SerializableXid}, copying the format ID, GTRID and BQUAL of an existing {@link Xid}. * * @param xid a {@link Xid} implementation. */ public SerializableXid(Xid xid) { if (xid.getGlobalTransactionId() == null) { throw new NullPointerException(); } if (xid.getBranchQualifier() == null) { throw new NullPointerException(); } this.formatId = xid.getFormatId(); this.globalTransactionId = xid.getGlobalTransactionId(); this.branchQualifier = xid.getBranchQualifier(); }
public void forget(CleanupRecord record) throws RuntimeException { Xid xid = record.getXid(); String resourceId = record.getResource(); byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); byte[] keyByteArray = resourceId.getBytes(); 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) record.getRecordFlag()); buffer.put(globalTransactionId); buffer.put(branchQualifier); buffer.put(resourceByteArray); buffer.flip(); try { this.channel.position(record.getStartIndex()); buffer.rewind(); this.channel.write(buffer); buffer.rewind(); } catch (Exception ex) { throw new IllegalStateException(ex); } byte recordFlag = buffer.get(); buffer.rewind(); this.registerRecord(buffer, recordFlag, record.getStartIndex()); }
private static byte[] encode(final Xid original) { final byte[] gtid = original.getGlobalTransactionId(); final byte[] bqal = original.getBranchQualifier(); final int formatId = original.getFormatId(); final byte[] target = new byte[gtid.length + bqal.length + 7]; target[0] = 0x02; target[1] = (byte) (formatId >>> 24); target[2] = (byte) (formatId >>> 16); target[3] = (byte) (formatId >>> 8); target[4] = (byte) (formatId); target[5] = (byte) gtid.length; System.arraycopy(gtid, 0, target, 6, gtid.length); target[6 + gtid.length] = (byte) bqal.length; System.arraycopy(bqal, 0, target, 7 + gtid.length, bqal.length); return target; }
protected int doDelete(Transaction transaction) { Connection connection = null; PreparedStatement stmt = null; try { connection = this.getConnection(); StringBuilder builder = new StringBuilder(); builder.append("DELETE FROM " + getTableName() + " WHERE GLOBAL_TX_ID = ? AND BRANCH_QUALIFIER = ?"); builder.append(StringUtils.isNotEmpty(domain) ? " AND DOMAIN = ?" : ""); stmt = connection.prepareStatement(builder.toString()); stmt.setBytes(1, transaction.getXid().getGlobalTransactionId()); stmt.setBytes(2, transaction.getXid().getBranchQualifier()); if (StringUtils.isNotEmpty(domain)) { stmt.setString(3, domain); } return stmt.executeUpdate(); } catch (SQLException e) { throw new TransactionIOException(e); } finally { closeStatement(stmt); this.releaseConnection(connection); } }
public boolean equals(Object o) { if (o == this) // optimization for the common case. return true; if (!(o instanceof Xid)) return false; Xid other = (Xid) o; if (other.getFormatId() != formatId) return false; if (!Arrays.equals(globalTransactionId, other.getGlobalTransactionId())) return false; if (!Arrays.equals(branchQualifier, other.getBranchQualifier())) return false; return true; }
stmt.setBytes(++i, xid.getGlobalTransactionId()); stmt.setBytes(++i, xid.getBranchQualifier());
if (xother.getFormatId() != formatId) { return false; if (xother.getBranchQualifier().length != branchQualifier.length) { return false; if (xother.getGlobalTransactionId().length != globalTransactionId.length) { return false; byte[] otherBQ = xother.getBranchQualifier(); if (branchQualifier[i] != otherBQ[i]) { return false; byte[] otherGtx = xother.getGlobalTransactionId(); if (globalTransactionId[i] != otherGtx[i]) { return false;
protected int doCreate(Transaction transaction) { Connection connection = null; PreparedStatement stmt = null; try { connection = this.getConnection(); StringBuilder builder = new StringBuilder(); builder.append("INSERT INTO " + getTableName() + "(GLOBAL_TX_ID,BRANCH_QUALIFIER,TRANSACTION_TYPE,CONTENT,STATUS,RETRIED_COUNT,CREATE_TIME,LAST_UPDATE_TIME,VERSION"); builder.append(StringUtils.isNotEmpty(domain) ? ",DOMAIN ) VALUES (?,?,?,?,?,?,?,?,?,?)" : ") VALUES (?,?,?,?,?,?,?,?,?)"); stmt = connection.prepareStatement(builder.toString()); stmt.setBytes(1, transaction.getXid().getGlobalTransactionId()); stmt.setBytes(2, transaction.getXid().getBranchQualifier()); stmt.setInt(3, transaction.getTransactionType().getId()); stmt.setBytes(4, serializer.serialize(transaction)); stmt.setInt(5, transaction.getStatus().getId()); stmt.setInt(6, transaction.getRetriedCount()); stmt.setTimestamp(7, new java.sql.Timestamp(transaction.getCreateTime().getTime())); stmt.setTimestamp(8, new java.sql.Timestamp(transaction.getLastUpdateTime().getTime())); stmt.setLong(9, transaction.getVersion()); if (StringUtils.isNotEmpty(domain)) { stmt.setString(10, domain); } return stmt.executeUpdate(); } catch (SQLException e) { throw new TransactionIOException(e); } finally { closeStatement(stmt); this.releaseConnection(connection); } }
public static SimpleXid of(final Xid xid) { return xid instanceof SimpleXid ? (SimpleXid) xid : new SimpleXid(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier()); }
public void forget(Xid xid, String resourceId) throws RuntimeException { try { String application = CommonUtils.getApplication(this.endpoint); String databaseName = application.replaceAll("\\W", "_"); MongoDatabase mdb = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> collection = mdb.getCollection(CONSTANTS_TB_REMOVEDRESES); byte[] global = xid.getGlobalTransactionId(); byte[] branch = xid.getBranchQualifier(); Document document = new Document(); document.append(CONSTANTS_FD_GLOBAL, ByteUtils.byteArrayToString(global)); document.append(CONSTANTS_FD_BRANCH, ByteUtils.byteArrayToString(branch)); document.append("resource_id", resourceId); document.append("created", this.endpoint); collection.insertOne(document); } catch (RuntimeException error) { logger.error("Error occurred while forgetting resource({}).", resourceId, error); } }
public boolean equals(Object o) { if (o == this) { // optimization for the common case. return true; } if (!(o instanceof Xid)) { return false; } Xid other = (Xid) o; if (other.getFormatId() != formatId) { return false; } if (!Arrays.equals(globalTransactionId, other.getGlobalTransactionId())) { return false; } if (!Arrays.equals(branchQualifier, other.getBranchQualifier())) { return false; } return true; }