Java Code Examples for javax.transaction.xa.Xid#getFormatId()

The following examples show how to use javax.transaction.xa.Xid#getFormatId() . 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: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void writeXaPrepare(NetConnection conn) throws SqlException {
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    Xid xid = callInfo.xid_;
    // don't forget that xars.prepare() does not have flags, assume TMNOFLAGS
    int xaFlags = XAResource.TMNOFLAGS;

    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_PREPARE);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);
    updateLengthBytes();
}
 
Example 2
Source File: NetXAConnectionRequest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
void writeXID(int codepoint, Xid xid) throws SqlException {
    int len = 0;
    int formatId = xid.getFormatId();
    byte[] gtrid = xid.getGlobalTransactionId();
    byte[] bqual = xid.getBranchQualifier();

    markLengthBytes(codepoint);

    len = 4;                    // length of formatId
    len += (bqual.length + 4);  // bqual length
    len += (gtrid.length + 4);  // gtrid length

    write4Bytes(formatId);
    write4Bytes(gtrid.length);
    write4Bytes(bqual.length);

    writeBytes(gtrid);
    writeBytes(bqual);

    updateLengthBytes();

}
 
Example 3
Source File: XidWrapperImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean equals(Object object)
{
   if (object == this)
      return true;

   if (object == null || !(object instanceof Xid))
      return false;  

   Xid other = (Xid)object;
   return
      (
         formatId == other.getFormatId() && 
         Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) &&
         Arrays.equals(branchQualifier, other.getBranchQualifier())
      );
}
 
Example 4
Source File: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
void buildSYNCCTLCommit(int xaFlags, Xid xid) throws SqlException {
    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_COMMITTED);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);

    updateLengthBytes();
}
 
Example 5
Source File: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void writeXaCommit(NetConnection conn, Xid xid) throws SqlException {
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    int xaFlags = callInfo.xaFlags_;

    // create DSS command with no reply.
    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_COMMITTED);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);
    updateLengthBytes();
}
 
Example 6
Source File: RecoveredXid.java    From spanner-jdbc with MIT License 6 votes vote down vote up
@Override
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;
  }
  return Arrays.equals(branchQualifier, other.getBranchQualifier());
}
 
Example 7
Source File: XidImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: TransactionCoordinator.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forgetQuietly(Xid xid) {
	TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	int formatId = xid.getFormatId();
	if (XidFactory.JTA_FORMAT_ID == formatId) {
		transactionCoordinator.forgetQuietly(xid);
	} else if (XidFactory.TCC_FORMAT_ID == formatId) {
		compensableCoordinator.forgetQuietly(xid);
	}
}
 
Example 9
Source File: TestXABase.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return a string that describes any Xid instance.
 */
static String toString(Xid id) {
    if (id == null)
        return "[NULL Xid]";

    String s = id.getClass().getName();
    s = s.substring(s.lastIndexOf('.') + 1);
    s = s + " [FormatId=" + id.getFormatId() +
            ", GlobalId=" + new String(id.getGlobalTransactionId()).trim() +
            ", BranchQual=" + new String(id.getBranchQualifier()).trim() + "]";

    return s;
}
 
Example 10
Source File: FBXid.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Compare for equality.
 * <p>
 * Instances are considered equal if they are both instances of XidImpl,
 * and if they have the same global transaction id and transaction
 * branch qualifier.
 * </p>
 */
public boolean equals(Object obj) {
    if (this == obj) return true;
    if (!(obj instanceof Xid)) return false;

    Xid other = (Xid) obj;

    boolean result = formatId == other.getFormatId();
    byte[] otherGlobalID = other.getGlobalTransactionId();
    byte[] otherBranchID = other.getBranchQualifier();
    result &= Arrays.equals(globalId, otherGlobalID);
    result &= Arrays.equals(branchId, otherBranchID);

    return result;
}
 
Example 11
Source File: DummyXid.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: MariaDbXid.java    From mariadb-connector-j with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Equal implementation.
 *
 * @param obj object to compare
 * @return true if object is MariaDbXi and as same parameters
 */
public boolean equals(Object obj) {
  if (obj instanceof Xid) {
    Xid other = (Xid) obj;
    return formatId == other.getFormatId()
        && Arrays.equals(globalTransactionId, other.getGlobalTransactionId())
        && Arrays.equals(branchQualifier, other.getBranchQualifier());
  }
  return false;
}
 
Example 13
Source File: XAXactId.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object other) 
  {
if (other == this)
	return true;

if (other == null)
	return false;
	
try
   {
	if (other instanceof GlobalXact)
		return super.equals(other);
	// Just cast it and catch the exception rather than doing the type
	// checking twice.
	Xid other_xid = (Xid) other;

	return(
		   java.util.Arrays.equals(
							other_xid.getGlobalTransactionId(),
							this.global_id)          &&
		   java.util.Arrays.equals(
							other_xid.getBranchQualifier(),
							this.branch_id)          &&
		   other_xid.getFormatId() == this.format_id);

   }
catch(ClassCastException cce)
   {
	// this class only knows how to compare with other Xids
	if (SanityManager.DEBUG)
		SanityManager.THROWASSERT("comparing XAXactId with " + 
								  other.getClass().getName(), cce); 

	return false;
   }
  }
 
Example 14
Source File: NetXAResource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static boolean xidsEqual(Xid xid1, Xid xid2) { // determine if the 2 xids contain the same values even if not same object
    // comapre the format ids
    if (xid1.getFormatId() != xid2.getFormatId()) {
        return false; // format ids are not the same
    }

    // compare the global transaction ids
    int xid1Length = xid1.getGlobalTransactionId().length;
    if (xid1Length != xid2.getGlobalTransactionId().length) {
        return false; // length of the global trans ids are not the same
    }
    byte[] xid1Bytes = xid1.getGlobalTransactionId();
    byte[] xid2Bytes = xid2.getGlobalTransactionId();
    int i;
    for (i = 0; i < xid1Length; ++i) { // check all bytes are the same
        if (xid1Bytes[i] != xid2Bytes[i]) {
            return false; // bytes in the global trans ids are not the same
        }
    }

    // compare the branch qualifiers
    xid1Length = xid1.getBranchQualifier().length;
    if (xid1Length != xid2.getBranchQualifier().length) {
        return false; // length of the global trans ids are not the same
    }
    xid1Bytes = xid1.getBranchQualifier();
    xid2Bytes = xid2.getBranchQualifier();
    for (i = 0; i < xid1Length; ++i) { // check all bytes are the same
        if (xid1Bytes[i] != xid2Bytes[i]) {
            return false; // bytes in the global trans ids are not the same
        }
    }

    return true; // all of the fields are the same, xid1 == xid2
}
 
Example 15
Source File: SerializableXid.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 16
Source File: FBXid.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return a string that describes any Xid instance.
 */
static String toString(Xid id) {
    if (id == null)
        return "[NULL Xid]";

    String s = id.getClass().getName();
    s = s.substring(s.lastIndexOf('.') + 1);
    s = s + " [FormatId=" + id.getFormatId() +
            ", GlobalId=" + new String(id.getGlobalTransactionId()).trim() +
            ", BranchQual=" + new String(id.getBranchQualifier()).trim() + "]";

    return s;
}
 
Example 17
Source File: DummyXid.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 18
Source File: NetXAConnectionRequest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void writeXaStartUnitOfWork(NetConnection conn) throws SqlException {
    NetXACallInfo callInfo = conn.xares_.callInfoArray_[conn.currXACallInfoOffset_];
    Xid xid = callInfo.xid_;
    int xaFlags = callInfo.xaFlags_;
    long xaTimeout = callInfo.xaTimeoutMillis_;

    // create DSS command with reply.
    createCommand();

    // save the length bytes for later update
    markLengthBytes(CodePoint.SYNCCTL);

    // SYNCTYPE
    writeSYNCType(CodePoint.SYNCTYPE, CodePoint.SYNCTYPE_NEW_UOW);

    if (xid.getFormatId() != -1) {
        writeXID(CodePoint.XID, xid);
    } else
    // write the null XID for local transaction on XA connection
    {
        writeNullXID(CodePoint.XID);
    }

    writeXAFlags(CodePoint.XAFLAGS, xaFlags);
    // Check whether the timeout value was specified.
    // Value less than 0 means no timeout is specified.
    if (xaTimeout >= 0) {
        writeXATimeout(CodePoint.TIMEOUT, xaTimeout);
    }
    updateLengthBytes();
}
 
Example 19
Source File: DummyXid.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * Copy constructor
 *
 * @param other
 */
public DummyXid(final Xid other) {
   branchQualifier = copyBytes(other.getBranchQualifier());
   formatId = other.getFormatId();
   globalTransactionId = copyBytes(other.getGlobalTransactionId());
}
 
Example 20
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void compensableRecoveryResume(Xid xid) throws NotSupportedException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	TransactionRepository transactionRepository = this.beanFactory.getCompensableRepository();
	TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();
	if (xid == null) {
		throw new IllegalStateException();
	} else if (TransactionXid.class.isInstance(xid) == false) {
		throw new IllegalStateException();
	} else if (xid.getFormatId() != XidFactory.TCC_FORMAT_ID) {
		throw new IllegalStateException();
	}

	TransactionXid compensableXid = (TransactionXid) xid;
	CompensableTransaction transaction = null;
	try {
		transaction = (CompensableTransaction) transactionRepository.getTransaction(compensableXid);
	} catch (TransactionException tex) {
		logger.error("Error occurred while getting transaction from transaction repository!", tex);
		throw new IllegalStateException();
	}

	if (transaction == null) {
		throw new IllegalStateException();
	} else if (CompensableTransaction.class.isInstance(transaction) == false) {
		throw new IllegalStateException();
	}

	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();

	TransactionContext transactionContext = transaction.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	} else if (transactionContext.isRecoveried()) {
		try {
			compensableCoordinator.start(transactionContext, XAResource.TMNOFLAGS);
		} catch (XAException ex) {
			logger.error("Error occurred while resuming an compensable transaction!", ex);
			throw new SystemException(ex.getMessage());
		}
	} else if (compensable == null) {
		throw new IllegalStateException();
	} else if (compensable.equals(transaction) == false) {
		throw new IllegalStateException();
	}

}