:D remove unused databasebc.transaction.*
parent
ea5b40011d
commit
4a592c717b
|
@ -79,8 +79,6 @@ import org.glassfish.openesb.databasebc.model.runtime.Db2DataAccess;
|
|||
import org.glassfish.openesb.databasebc.model.runtime.DerbyDataAccess;
|
||||
import org.glassfish.openesb.databasebc.model.runtime.OracleDataAccess;
|
||||
import org.glassfish.openesb.databasebc.model.runtime.SqlServerDataAccess;
|
||||
import org.glassfish.openesb.databasebc.transaction.TransactionHelper;
|
||||
import org.glassfish.openesb.databasebc.transaction.XidImpl;
|
||||
import com.sun.jbi.nms.exchange.ExchangePattern;
|
||||
|
||||
import com.sun.jbi.common.qos.messaging.MessagingChannel;
|
||||
|
|
|
@ -54,7 +54,6 @@ import javax.xml.parsers.DocumentBuilder;
|
|||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import com.sun.jbi.internationalization.Messages;
|
||||
import org.glassfish.openesb.databasebc.transaction.*;
|
||||
|
||||
import javax.transaction.xa.XAResource;
|
||||
import org.glassfish.openesb.databasebc.model.runtime.DBConnectionInfo;
|
||||
|
@ -95,9 +94,6 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
CallableStatement cs = null;
|
||||
//private TransactionManager mTxManager = null;
|
||||
private XidImpl xid = null;
|
||||
TransactionHelper mtxHelper = null;
|
||||
private boolean mtxFlag;
|
||||
XAResource xaResource = null;
|
||||
// Settings for custom reliability header extensions
|
||||
|
@ -129,12 +125,9 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
mExchange = exchange;
|
||||
mContext = context;
|
||||
mInboundExchanges = inboundMessageExchanges;
|
||||
//mTxManager = (TransactionManager) context.getTransactionManager();
|
||||
|
||||
final DocumentBuilderFactory docBuilderFact = DocumentBuilderFactory.
|
||||
newInstance();
|
||||
mDocBuilder = docBuilderFact.newDocumentBuilder();
|
||||
// mtxHelper = new TransactionHelper();
|
||||
dbConnectionInfo = new DBConnectionInfo();
|
||||
}
|
||||
|
||||
|
@ -1019,8 +1012,6 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
|
||||
if (inout.isTransacted())
|
||||
// Removing manual enlistment. Moving to automatic resource enlistment
|
||||
// mtxHelper.handleOutbound(mExchange);
|
||||
// enlistResource(epb);
|
||||
transaction =
|
||||
(Transaction) inout.getProperty(
|
||||
MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
|
||||
|
@ -1299,8 +1290,6 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
if (spInput != null) {
|
||||
if (inout.isTransacted())
|
||||
// Removing manual enlistment. Moving to automatic resource enlistment
|
||||
// mtxHelper.handleOutbound(mExchange);
|
||||
// enlistResource(epb);
|
||||
transaction =
|
||||
(Transaction) inout.getProperty(
|
||||
MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
|
||||
|
@ -1538,8 +1527,6 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
|
||||
if (inonly.isTransacted())
|
||||
// Removing manual enlistment. Moving to automatic resource enlistment
|
||||
// mtxHelper.handleOutbound(mExchange);
|
||||
// enlistResource(epb);
|
||||
transaction = (Transaction) inonly.getProperty(
|
||||
MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
|
||||
|
||||
|
@ -1590,10 +1577,6 @@ public class OutboundMessageProcessor implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if (inonly.isTransacted()) { mtxHelper.handleInbound(mExchange); }
|
||||
*/
|
||||
|
||||
if (transaction != null)
|
||||
getTransactionManager().suspend();
|
||||
mChannel.send(inonly);
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)GlobalId.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Venkat P
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
/**
|
||||
* This object encapsulates the global transaction ID of a transaction.
|
||||
* It is similar to an Xid, but holds only the GlobalId part.
|
||||
* This implementation is immutable and always serializable at runtime.
|
||||
*
|
||||
* @see XidImpl
|
||||
* @author <a href="mailto:Narayana.Rallabandi@Sun.Com">Narayana Rallabandi</a>
|
||||
* @version
|
||||
*/
|
||||
public class GlobalId implements java.io.Externalizable{
|
||||
|
||||
static final long serialVersionUID = 234567891L;
|
||||
private int formatId;
|
||||
//Global Transaction Id
|
||||
private byte[] globalId;
|
||||
// hash code for the global id
|
||||
private int hash;
|
||||
|
||||
public GlobalId(){
|
||||
}
|
||||
|
||||
protected GlobalId(int formatId, byte[] globalId, int hash){
|
||||
this.formatId = formatId;
|
||||
this.globalId = globalId;
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
protected GlobalId(int formatId, byte[] globalId){
|
||||
this.formatId = formatId;
|
||||
this.globalId = globalId;
|
||||
hash = computeHash();
|
||||
}
|
||||
|
||||
private GlobalId(Xid xid){
|
||||
formatId = xid.getFormatId();
|
||||
globalId = xid.getGlobalTransactionId();
|
||||
if (xid instanceof XidImpl) {
|
||||
hash = xid.hashCode();
|
||||
}else{
|
||||
hash = computeHash();
|
||||
}
|
||||
}
|
||||
|
||||
private GlobalId(int formatId, int bqual_length, byte[] tid){
|
||||
this.formatId = formatId;
|
||||
if (bqual_length == 0)
|
||||
globalId = tid;
|
||||
else {
|
||||
int len = tid.length - bqual_length;
|
||||
globalId = new byte[len];
|
||||
System.arraycopy(tid, 0, globalId, 0, len);
|
||||
}
|
||||
hash = computeHash();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public boolean equals(Object obj){
|
||||
if (obj instanceof GlobalId) {
|
||||
GlobalId other = (GlobalId)obj;
|
||||
if (formatId != other.formatId)
|
||||
return false;
|
||||
if (globalId == other.globalId)
|
||||
return true;
|
||||
if (globalId.length != other.globalId.length)
|
||||
return false;
|
||||
|
||||
int len = globalId.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
if (globalId[i] != other.globalId[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int hashCode(){
|
||||
return hash;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "[formatId=" + formatId
|
||||
+ ", globalId=" + new String(globalId).trim()
|
||||
+ ", hash=" + hash + "]";
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void writeExternal(java.io.ObjectOutput out) throws IOException {
|
||||
out.writeInt(formatId);
|
||||
out.writeObject(globalId);
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException{
|
||||
formatId = in.readInt();
|
||||
globalId = (byte[])in.readObject();
|
||||
hash = computeHash();
|
||||
}
|
||||
|
||||
private int computeHash(){
|
||||
int len = globalId.length;
|
||||
int hashval = 0;
|
||||
// TODO: use a better hash function
|
||||
for (int i = 0; i < len; ++i)
|
||||
hashval = 3 * globalId[i] + hashval;
|
||||
hashval += formatId;
|
||||
return hashval;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)LocalId.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Venkat P
|
||||
*/
|
||||
/**
|
||||
* LocalId symbloizes the transaction id from the Application Server
|
||||
* This class implements the Externizable interface for making the object
|
||||
* serialiable during runtime.
|
||||
*
|
||||
* @author <a href="Narayana.Rallabandi@Sun.Com">Narayana Rallabandi</a>
|
||||
* @version
|
||||
*/
|
||||
public class LocalId implements java.io.Externalizable{
|
||||
|
||||
static final long serialVersionUID = 123456789L;
|
||||
private long localIdvalue; //
|
||||
|
||||
public LocalId(){
|
||||
}
|
||||
|
||||
protected LocalId(long localIdvalue){
|
||||
this.localIdvalue = localIdvalue;
|
||||
}
|
||||
|
||||
protected LocalId(XidImpl xid){
|
||||
this(xid.getLocalIdValue());
|
||||
}
|
||||
|
||||
private long getValue(){
|
||||
return localIdvalue;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public boolean equals(Object obj){
|
||||
return (obj instanceof LocalId) ?
|
||||
(localIdvalue == ((LocalId)obj).localIdvalue): false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int hashCode(){
|
||||
return (int)localIdvalue;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void writeExternal(java.io.ObjectOutput out)
|
||||
throws java.io.IOException
|
||||
{
|
||||
out.writeLong(localIdvalue);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void readExternal(java.io.ObjectInput in)
|
||||
throws java.io.IOException, ClassNotFoundException {
|
||||
localIdvalue = in.readLong();
|
||||
}
|
||||
|
||||
// this morphs the long under consideration
|
||||
// which fecilitates to Obtain the global transaction identifier
|
||||
// part of XID as an array of bytes
|
||||
private static void toByteArray(long localId, byte[] destination, int dstBegin){
|
||||
destination[dstBegin + 0] = (byte)(0xff & (localId >>> 56));
|
||||
destination[dstBegin + 1] = (byte)(0xff & (localId >>> 48));
|
||||
destination[dstBegin + 2] = (byte)(0xff & (localId >>> 40));
|
||||
destination[dstBegin + 3] = (byte)(0xff & (localId >>> 32));
|
||||
destination[dstBegin + 4] = (byte)(0xff & (localId >>> 24));
|
||||
destination[dstBegin + 5] = (byte)(0xff & (localId >>> 16));
|
||||
destination[dstBegin + 6] = (byte)(0xff & (localId >>> 8));
|
||||
destination[dstBegin + 7] = (byte)(0xff & (localId >>> 0));
|
||||
}
|
||||
|
||||
// this morphs the byrearray source under consideration
|
||||
// which fecilitates to Obtain the global transaction identifier
|
||||
// as long which is part of XID.
|
||||
private static long fromByteArray(byte[] source, int srcBegin) {
|
||||
return ((long)(source[srcBegin + 0] & 0xff) << 56)
|
||||
| ((long)(source[srcBegin + 1] & 0xff) << 48)
|
||||
| ((long)(source[srcBegin + 2] & 0xff) << 40)
|
||||
| ((long)(source[srcBegin + 3] & 0xff) << 32)
|
||||
| ((long)(source[srcBegin + 4] & 0xff) << 24)
|
||||
| ((long)(source[srcBegin + 5] & 0xff) << 16)
|
||||
| ((long)(source[srcBegin + 6] & 0xff) << 8)
|
||||
| ((long)(source[srcBegin + 7] & 0xff));
|
||||
}
|
||||
}
|
|
@ -1,696 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)TransactionHelper.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
import com.sun.jbi.internationalization.Messages;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Synchronization;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.RollbackException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.jbi.component.ComponentContext;
|
||||
import javax.jbi.messaging.MessageExchange;
|
||||
import javax.jbi.messaging.ExchangeStatus;
|
||||
import javax.jbi.messaging.InOnly;
|
||||
|
||||
import javax.sql.XAConnection;
|
||||
import javax.sql.XADataSource;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.InvalidTransactionException;
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Narayanaa
|
||||
*/
|
||||
public class TransactionHelper {
|
||||
|
||||
//private static final Messages mMessages = Messages.getMessages(TransactionHelper.class);
|
||||
|
||||
private static final Logger mLogger = Messages.getLogger(TransactionHelper.class);
|
||||
|
||||
|
||||
/** Creates a new instance of TransactionHelper */
|
||||
public TransactionHelper() {
|
||||
xid = xidFactory.newXid();
|
||||
gid = xid.getTrulyGlobalId();
|
||||
status = Status.STATUS_ACTIVE;
|
||||
start = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setComponentContext(ComponentContext componentContext) throws Exception{
|
||||
manager = (TransactionManager)componentContext.getTransactionManager();
|
||||
transaction = manager.getTransaction();
|
||||
if(transaction == null){
|
||||
begin();
|
||||
transaction = manager.getTransaction();
|
||||
}
|
||||
status = manager.getStatus();
|
||||
xid = xidFactory.newXid();
|
||||
}
|
||||
|
||||
public void setMessageExchange(MessageExchange messageExchange) throws Exception{
|
||||
this.messageExchange = messageExchange;
|
||||
}
|
||||
|
||||
public boolean isInOnly(MessageExchange me) {
|
||||
return (me instanceof InOnly);
|
||||
}
|
||||
|
||||
public boolean isTxEnabled(MessageExchange me) {
|
||||
return ((tx_enable==null || tx_enable.equalsIgnoreCase("true"))
|
||||
&& !isInOnly(me));
|
||||
}
|
||||
|
||||
public void setXAResource(XAResource xar){
|
||||
this.xar = xar;
|
||||
start = System.currentTimeMillis();
|
||||
try{
|
||||
this.timeoutPeriod = xar.getTransactionTimeout();
|
||||
}catch(XAException xae){
|
||||
mLogger.log(Level.SEVERE,"Error While setting the XA Resource",xae);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDataSource(XADataSource xads){
|
||||
this.xads = xads;
|
||||
try{
|
||||
xac = xads.getXAConnection();
|
||||
xar = xads.getXAConnection().getXAResource();
|
||||
start = System.currentTimeMillis();
|
||||
this.timeoutPeriod = xar.getTransactionTimeout();
|
||||
}catch(SQLException se){
|
||||
mLogger.log(Level.SEVERE,"Error While setting the Data Source",se);
|
||||
//se.getStackTrace();
|
||||
}catch(XAException xe){
|
||||
mLogger.log(Level.SEVERE,"Error While getting the XA Connection",xe);
|
||||
//xe.getStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerXAResouce() {
|
||||
|
||||
// componentContext = (com.sun.jbi.framework.ComponentContext)componentContext;
|
||||
// componentContext.registerXAResource(xar);
|
||||
}
|
||||
|
||||
public XAConnection getXAConnection(){
|
||||
return this.xac;
|
||||
}
|
||||
|
||||
public void handleInbound(MessageExchange me) throws Exception {
|
||||
if(!isTxEnabled(me))
|
||||
return;
|
||||
suspendTx(me);
|
||||
}
|
||||
|
||||
public void handleOutbound(MessageExchange me) throws Exception {
|
||||
if(!isTxEnabled(me))
|
||||
return;
|
||||
resumeTx(me);
|
||||
}
|
||||
|
||||
public TransactionManager getTransactionManager (){
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
public void suspendTx(MessageExchange me) throws SystemException {
|
||||
TransactionManager tm = getTransactionManager();
|
||||
Transaction tx = tm.getTransaction();
|
||||
if (tx != null) {
|
||||
if(me.getStatus().equals(ExchangeStatus.ERROR))
|
||||
tx.setRollbackOnly();
|
||||
tx = tm.suspend();
|
||||
me.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, tx);
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeTx(MessageExchange me) throws
|
||||
SystemException,
|
||||
InvalidTransactionException {
|
||||
TransactionManager tm = getTransactionManager();
|
||||
Transaction tx = (Transaction)me.getProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
|
||||
if(tx != null) {
|
||||
if(me.getStatus().equals(ExchangeStatus.ERROR))
|
||||
tx.setRollbackOnly();
|
||||
manager.resume(tx);
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int hashCode() {
|
||||
return xid.hashCode();
|
||||
}
|
||||
|
||||
//@Override
|
||||
public String toString() {
|
||||
return "TransactionHelper:" + xidFactory.toString(xid);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof TransactionHelper)
|
||||
return getLocalIdValue() == (((TransactionHelper)obj).getLocalIdValue());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the local id of this transaction. The local id is used as
|
||||
* a transaction propagation context within the JBoss server, and
|
||||
* in the TxManager for mapping local transaction ids to transactions.
|
||||
*/
|
||||
public long getLocalIdValue() {
|
||||
return xid.getLocalIdValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local id of this transaction. The local id is used as
|
||||
* a transaction propagation context within the JBoss server, and
|
||||
* in the TxManager for mapping local transaction ids to transactions.
|
||||
*/
|
||||
public LocalId getLocalId() {
|
||||
return xid.getLocalId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global id of this transaction. Ths global id is used in
|
||||
* the TxManager, which keeps a map from global ids to transactions.
|
||||
*/
|
||||
public GlobalId getGlobalId() {
|
||||
return gid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the xid of this transaction.
|
||||
*/
|
||||
public XidImpl getXid() {
|
||||
return xid;
|
||||
}
|
||||
|
||||
private long lastBranchId = 0;
|
||||
private Xid createXidBranch() {
|
||||
long branchId = ++lastBranchId;
|
||||
return xidFactory.newBranch(xid, branchId);
|
||||
}
|
||||
|
||||
// commit the transaction underconsideration
|
||||
//
|
||||
public void commit()
|
||||
throws RollbackException,
|
||||
java.lang.SecurityException,
|
||||
java.lang.IllegalStateException,
|
||||
SystemException,
|
||||
Exception{
|
||||
status = transaction.getStatus();
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
|
||||
if (status == Status.STATUS_COMMITTED){
|
||||
xar.commit(xid,true);
|
||||
transaction.commit();
|
||||
// checkHeuristics();
|
||||
}else{
|
||||
Throwable causedByThrowable = exceptionReason;
|
||||
//rollbackResources();
|
||||
//completeTransaction();
|
||||
xar.rollback(xid);
|
||||
transaction.rollback();
|
||||
// throw jboss rollback exception with the saved off exceptionReason
|
||||
mLogger.log(Level.SEVERE,"Error While Commiting the transaction",causedByThrowable);
|
||||
throw new Exception("Unable to commit, tx=" +
|
||||
toString() + " status=" + TransactionStateUtility.getStringStatus(status),
|
||||
causedByThrowable);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rollback()
|
||||
throws java.lang.IllegalStateException,
|
||||
java.lang.SecurityException,
|
||||
SystemException {
|
||||
status = transaction.getStatus();
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
|
||||
switch (status) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
transaction.setRollbackOnly();
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
//endResources();
|
||||
xar.end(xid,XAResource.TMFAIL);
|
||||
transaction.rollback();
|
||||
case Status.STATUS_PREPARING:
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
transaction.setRollbackOnly();
|
||||
return;
|
||||
default:
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new IllegalStateException("Cannot rollback(), " +
|
||||
"tx=" + toString() +
|
||||
" status=" +
|
||||
TransactionStateUtility.getStringStatus(status));
|
||||
}
|
||||
} catch(XAException xe){
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status",xe);
|
||||
//xe.getStackTrace();
|
||||
}finally {
|
||||
//Thread.interrupted();// clear timeout that did an interrupt
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean enlist() throws RollbackException,
|
||||
java.lang.IllegalStateException,
|
||||
SystemException {
|
||||
|
||||
if (xar == null)
|
||||
throw new IllegalArgumentException("null xaRes tx=" + this);
|
||||
|
||||
//get status from the TM
|
||||
if(transaction != null)
|
||||
status = transaction.getStatus();
|
||||
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
switch (status) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_PREPARING:
|
||||
break;
|
||||
case Status.STATUS_PREPARED:
|
||||
throw new IllegalStateException("Already prepared. " + this);
|
||||
case Status.STATUS_COMMITTING:
|
||||
throw new IllegalStateException("Already started committing. " + this);
|
||||
case Status.STATUS_COMMITTED:
|
||||
throw new IllegalStateException("Already committed. " + this);
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
throw new RollbackException("Already marked for rollback " + this);
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
throw new RollbackException("Already started rolling back. " + this);
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
throw new RollbackException("Already rolled back. " + this);
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
if(transaction == null)
|
||||
break;
|
||||
else
|
||||
throw new IllegalStateException("No transaction. " + this);
|
||||
case Status.STATUS_UNKNOWN:
|
||||
throw new IllegalStateException("Unknown state " + this);
|
||||
default:
|
||||
throw new IllegalStateException("Illegal status: " + TransactionStateUtility.getStringStatus(status) + " tx=" + this);
|
||||
}
|
||||
isEnlisted = transaction.enlistResource(xar);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return isEnlisted;
|
||||
}
|
||||
|
||||
public void delist()throws java.lang.IllegalStateException,
|
||||
SystemException,XAException {
|
||||
if(lock.tryLock()){
|
||||
try{
|
||||
delist(transaction.getStatus());
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void begin() throws NotSupportedException,SystemException{
|
||||
if(lock.tryLock()){
|
||||
try{
|
||||
manager.begin();
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TMCommit() throws RollbackException,
|
||||
HeuristicMixedException,
|
||||
HeuristicRollbackException,
|
||||
SystemException{
|
||||
if(lock.tryLock()){
|
||||
try{
|
||||
manager.commit();
|
||||
}catch(RollbackException re){
|
||||
try{
|
||||
manager.rollback();
|
||||
}catch(SystemException se){
|
||||
mLogger.log(Level.SEVERE,"Error While Commiting the Transaction",se);
|
||||
}
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void suspend() throws SystemException{
|
||||
if(lock.tryLock()){
|
||||
try{
|
||||
manager.suspend();
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resume() throws SystemException,InvalidTransactionException{
|
||||
if(lock.tryLock()){
|
||||
try{
|
||||
manager.resume(transaction);
|
||||
}finally{
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getStatus() throws SystemException {
|
||||
if (done)
|
||||
return Status.STATUS_NO_TRANSACTION;
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
public boolean isEnlisted() {
|
||||
return this.isEnlisted;
|
||||
}
|
||||
|
||||
public synchronized void instanceDone() {
|
||||
status = Status.STATUS_NO_TRANSACTION;
|
||||
notifyAll();
|
||||
done = true;
|
||||
}
|
||||
|
||||
// for registering synchronizations during transaction
|
||||
public void registerSynchronization(Synchronization s)
|
||||
throws RollbackException,
|
||||
java.lang.IllegalStateException,
|
||||
SystemException {
|
||||
if (s == null)
|
||||
throw new IllegalArgumentException("Null synchronization " + this);
|
||||
|
||||
//get status of the transaction
|
||||
status = transaction.getStatus();
|
||||
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
switch (status) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_PREPARING:
|
||||
break;
|
||||
case Status.STATUS_PREPARED:
|
||||
throw new IllegalStateException("Already prepared. " + this);
|
||||
case Status.STATUS_COMMITTING:
|
||||
throw new IllegalStateException("Already started committing. " + this);
|
||||
case Status.STATUS_COMMITTED:
|
||||
throw new IllegalStateException("Already committed. " + this);
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
throw new RollbackException("Already marked for rollback " + this);
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
throw new RollbackException("Already started rolling back. " + this);
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
throw new RollbackException("Already rolled back. " + this);
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
throw new IllegalStateException("No transaction. " + this);
|
||||
case Status.STATUS_UNKNOWN:
|
||||
throw new IllegalStateException("Unknown state " + this);
|
||||
default:
|
||||
throw new IllegalStateException("Illegal status: " + TransactionStateUtility.getStringStatus(status) + " tx=" + this);
|
||||
}
|
||||
|
||||
if (syncCount == syncAllocSize) {
|
||||
syncAllocSize = 2 * syncAllocSize;
|
||||
Synchronization[] sy = new Synchronization[syncAllocSize];
|
||||
System.arraycopy(sync, 0, sy, 0, syncCount);
|
||||
sync = sy;
|
||||
}
|
||||
sync[syncCount++] = s;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean delist(int flag)
|
||||
throws java.lang.IllegalStateException,
|
||||
SystemException, XAException{
|
||||
boolean isDelisted = false;
|
||||
if (xar == null)
|
||||
throw new IllegalArgumentException("null xaRes tx=" + this);
|
||||
if (flag != XAResource.TMSUCCESS &&
|
||||
flag != XAResource.TMSUSPEND &&
|
||||
flag != XAResource.TMFAIL)
|
||||
throw new IllegalArgumentException("Bad flag: " + flag + " tx=" + this);
|
||||
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
status = transaction.getStatus();
|
||||
switch (status) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
break;
|
||||
case Status.STATUS_PREPARING:
|
||||
throw new IllegalStateException("Already started preparing. " + this);
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
throw new IllegalStateException("Already started rolling back. " + this);
|
||||
case Status.STATUS_PREPARED:
|
||||
throw new IllegalStateException("Already prepared. " + this);
|
||||
case Status.STATUS_COMMITTING:
|
||||
throw new IllegalStateException("Already started committing. " + this);
|
||||
case Status.STATUS_COMMITTED:
|
||||
throw new IllegalStateException("Already committed. " + this);
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
throw new IllegalStateException("Already rolled back. " + this);
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
throw new IllegalStateException("No transaction. " + this);
|
||||
case Status.STATUS_UNKNOWN:
|
||||
throw new IllegalStateException("Unknown state " + this);
|
||||
default:
|
||||
throw new IllegalStateException("Illegal status: " + TransactionStateUtility.getStringStatus(status) + " tx=" + this);
|
||||
}
|
||||
try{
|
||||
xar.end(xid,XAResource.TMSUCCESS);
|
||||
isDelisted= transaction.delistResource(xar,flag);
|
||||
}catch(XAException xae){
|
||||
xar.end(xid,XAResource.TMFAIL);
|
||||
transaction.setRollbackOnly();
|
||||
transaction.delistResource(xar,XAResource.TMFAIL);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return isDelisted;
|
||||
}
|
||||
|
||||
public void setRollbackOnly()
|
||||
throws java.lang.IllegalStateException,
|
||||
SystemException,
|
||||
XAException{
|
||||
status = transaction.getStatus();
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
switch (status) {
|
||||
case Status.STATUS_ACTIVE:
|
||||
case Status.STATUS_PREPARING:
|
||||
case Status.STATUS_PREPARED:
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
xar.rollback(xid);
|
||||
transaction.setRollbackOnly();
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
xar.rollback(xid);
|
||||
transaction.setRollbackOnly();
|
||||
return;
|
||||
case Status.STATUS_COMMITTING:
|
||||
throw new IllegalStateException("Already started committing. " + this);
|
||||
case Status.STATUS_COMMITTED:
|
||||
throw new IllegalStateException("Already committed. " + this);
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
throw new IllegalStateException("Already rolled back. " + this);
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
throw new IllegalStateException("No transaction. " + this);
|
||||
case Status.STATUS_UNKNOWN:
|
||||
throw new IllegalStateException("Unknown state " + this);
|
||||
default:
|
||||
throw new IllegalStateException("Illegal status: " + TransactionStateUtility.getStringStatus(status) + " tx=" + this);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this needs to be brought into the code for
|
||||
public void timedOut() throws SystemException{
|
||||
status = transaction.getStatus();
|
||||
if(lock.tryLock()){
|
||||
try {
|
||||
switch (status) {
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
case Status.STATUS_COMMITTED:
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
return;
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
return;
|
||||
case Status.STATUS_COMMITTING:
|
||||
gotHeuristic(null, XAException.XA_HEURMIX);
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
return; // commit will fail
|
||||
case Status.STATUS_PREPARED:
|
||||
case Status.STATUS_ACTIVE:
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
return;
|
||||
case Status.STATUS_PREPARING:
|
||||
status = Status.STATUS_MARKED_ROLLBACK;
|
||||
return; // commit will fail
|
||||
default:
|
||||
return;
|
||||
}
|
||||
} catch(XAException xe){
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status",xe);
|
||||
//xe.printStackTrace();
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// need to do
|
||||
public void gotHeuristic(XAResource resource, int code) throws XAException{
|
||||
switch (code) {
|
||||
case XAException.XA_HEURMIX:
|
||||
heuristicCode = XAException.XA_HEURMIX;
|
||||
break;
|
||||
case XAException.XA_HEURRB:
|
||||
if (heuristicCode == HEUR_NONE)
|
||||
heuristicCode = XAException.XA_HEURRB;
|
||||
else if (heuristicCode == XAException.XA_HEURCOM ||
|
||||
heuristicCode == XAException.XA_HEURHAZ)
|
||||
heuristicCode = XAException.XA_HEURMIX;
|
||||
break;
|
||||
case XAException.XA_HEURCOM:
|
||||
if (heuristicCode == HEUR_NONE)
|
||||
heuristicCode = XAException.XA_HEURCOM;
|
||||
else if (heuristicCode == XAException.XA_HEURRB ||
|
||||
heuristicCode == XAException.XA_HEURHAZ)
|
||||
heuristicCode = XAException.XA_HEURMIX;
|
||||
break;
|
||||
case XAException.XA_HEURHAZ:
|
||||
if (heuristicCode == HEUR_NONE)
|
||||
heuristicCode = XAException.XA_HEURHAZ;
|
||||
else if (heuristicCode == XAException.XA_HEURCOM ||
|
||||
heuristicCode == XAException.XA_HEURRB)
|
||||
heuristicCode = XAException.XA_HEURMIX;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
if (resource != null)
|
||||
resource.forget(xid);
|
||||
}
|
||||
|
||||
public void checkHeuristics()
|
||||
throws HeuristicMixedException, HeuristicRollbackException {
|
||||
switch (heuristicCode) {
|
||||
case XAException.XA_HEURHAZ:
|
||||
case XAException.XA_HEURMIX:
|
||||
heuristicCode = HEUR_NONE;
|
||||
throw new HeuristicMixedException();
|
||||
case XAException.XA_HEURRB:
|
||||
heuristicCode = HEUR_NONE;
|
||||
throw new HeuristicRollbackException();
|
||||
case XAException.XA_HEURCOM:
|
||||
heuristicCode = HEUR_NONE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int HEUR_NONE = XAException.XA_RETRY;
|
||||
private XidImpl xid;
|
||||
private GlobalId gid;
|
||||
//callback synchronizations
|
||||
private Synchronization[] sync = new Synchronization[3];
|
||||
private int syncAllocSize = 3;
|
||||
private int syncCount = 0;
|
||||
private ArrayList resources = new ArrayList(3);
|
||||
private int heuristicCode = HEUR_NONE;
|
||||
private int status;
|
||||
private long start;
|
||||
private long timeoutPeriod;
|
||||
|
||||
private boolean done = false;
|
||||
private Throwable exceptionReason;
|
||||
|
||||
public static XidFactory xidFactory = new XidFactory();//XidFactory.getXidFactoryInstance();
|
||||
|
||||
private final Lock lock = new ReentrantLock(true);
|
||||
private String tx_enable = System.getProperty("com.sun.enterprise.jbi.tx.enable");
|
||||
|
||||
TransactionManager manager = null;
|
||||
Transaction transaction = null;
|
||||
XADataSource xads = null;
|
||||
XAResource xar = null;
|
||||
XAConnection xac = null;
|
||||
boolean isEnlisted = false;
|
||||
|
||||
|
||||
ComponentContext componentContext = null;
|
||||
MessageExchange messageExchange = null;
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)TransactionStateUtility.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
|
||||
import com.sun.jbi.internationalization.Messages;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.Transaction;
|
||||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
/**
|
||||
*
|
||||
* @author Venkat P
|
||||
*/
|
||||
public class TransactionStateUtility {
|
||||
|
||||
private static final Messages mMessages = Messages.getMessages(TransactionStateUtility.class);
|
||||
|
||||
private static final Logger mLogger = Messages.getLogger(TransactionStateUtility.class);
|
||||
|
||||
/** Creates a new instance of TransactionStateUtility */
|
||||
private TransactionStateUtility() {
|
||||
}
|
||||
|
||||
/** Transaction Status Strings */
|
||||
private static final String[] TxStatusStrings =
|
||||
{
|
||||
"STATUS_ACTIVE",
|
||||
"STATUS_MARKED_ROLLBACK",
|
||||
"STATUS_PREPARED",
|
||||
"STATUS_COMMITTED",
|
||||
"STATUS_ROLLEDBACK",
|
||||
"STATUS_UNKNOWN",
|
||||
"STATUS_NO_TRANSACTION",
|
||||
"STATUS_PREPARING",
|
||||
"STATUS_COMMITTING",
|
||||
"STATUS_ROLLING_BACK"
|
||||
};
|
||||
|
||||
private static boolean isActive(Transaction tx) throws Exception{
|
||||
try {
|
||||
return tx != null && (tx.getStatus() == Status.STATUS_ACTIVE);
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isActive(TransactionManager tm) throws Exception{
|
||||
try {
|
||||
return isActive(tm.getTransaction());
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isActive(UserTransaction ut) throws Exception{
|
||||
try {
|
||||
return ut.getStatus() == Status.STATUS_ACTIVE;
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isUncommitted(Transaction tx) throws Exception{
|
||||
try {
|
||||
if (tx == null)
|
||||
return false;
|
||||
int status = tx.getStatus();
|
||||
return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isUncommitted(TransactionManager tm)throws Exception {
|
||||
try {
|
||||
return isUncommitted(tm.getTransaction());
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isUncommitted(UserTransaction ut) throws Exception {
|
||||
try {
|
||||
int status = ut.getStatus();
|
||||
return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
|
||||
} catch (SystemException error) {
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCompleted(Transaction tx) throws Exception{
|
||||
try {
|
||||
if (tx == null)
|
||||
return true;
|
||||
int status = tx.getStatus();
|
||||
return status == Status.STATUS_COMMITTED
|
||||
|| status == Status.STATUS_ROLLEDBACK
|
||||
|| status == Status.STATUS_NO_TRANSACTION;
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCompleted(TransactionManager tm) throws Exception{
|
||||
try {
|
||||
return isCompleted(tm.getTransaction());
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCompleted(UserTransaction ut) throws Exception{
|
||||
try {
|
||||
int status = ut.getStatus();
|
||||
return status == Status.STATUS_COMMITTED
|
||||
|| status == Status.STATUS_ROLLEDBACK
|
||||
|| status == Status.STATUS_NO_TRANSACTION;
|
||||
} catch (SystemException error) {
|
||||
mLogger.log(Level.SEVERE,"Error While Setting the Transaction Status");
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a tx Status index to a String
|
||||
*
|
||||
* @see javax.transaction.Status
|
||||
*
|
||||
* @param status the Status index
|
||||
* @return status as String or "STATUS_INVALID"
|
||||
*/
|
||||
private static String getStatusAsString(int status) {
|
||||
if (status >= Status.STATUS_ACTIVE && status <= Status.STATUS_ROLLING_BACK) {
|
||||
return TxStatusStrings[status];
|
||||
} else {
|
||||
return "STATUS_INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a XAResource flag to a String
|
||||
*
|
||||
* @see javax.transaction.xa.XAResource
|
||||
*
|
||||
* @param flags the flags passed in to start(), end(), recover()
|
||||
* @return the flags in String form
|
||||
*/
|
||||
private static String getXAResourceFlagsAsString(int flags) {
|
||||
if (flags == XAResource.TMNOFLAGS) {
|
||||
return "|TMNOFLAGS";
|
||||
} else {
|
||||
StringBuffer sbuf = new StringBuffer(64);
|
||||
|
||||
if ((flags & XAResource.TMONEPHASE) != 0) {
|
||||
sbuf.append("|TMONEPHASE");
|
||||
}
|
||||
if ((flags & XAResource.TMJOIN) != 0) {
|
||||
sbuf.append("|TMJOIN");
|
||||
}
|
||||
if ((flags & XAResource.TMRESUME) != 0) {
|
||||
sbuf.append("|TMRESUME");
|
||||
}
|
||||
if ((flags & XAResource.TMSUCCESS) != 0) {
|
||||
sbuf.append("|TMSUCCESS");
|
||||
}
|
||||
if ((flags & XAResource.TMFAIL) != 0) {
|
||||
sbuf.append("|TMFAIL");
|
||||
}
|
||||
if ((flags & XAResource.TMSUSPEND) != 0) {
|
||||
sbuf.append("|TMSUSPEND");
|
||||
}
|
||||
if ((flags & XAResource.TMSTARTRSCAN) != 0) {
|
||||
sbuf.append("|TMSTARTRSCAN");
|
||||
}
|
||||
if ((flags & XAResource.TMENDRSCAN) != 0) {
|
||||
sbuf.append("|TMENDRSCAN");
|
||||
}
|
||||
return sbuf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of the given status code.
|
||||
*/
|
||||
static String getStringStatus(int status) {
|
||||
switch (status) {
|
||||
case Status.STATUS_PREPARING:
|
||||
return "STATUS_PREPARING";
|
||||
case Status.STATUS_PREPARED:
|
||||
return "STATUS_PREPARED";
|
||||
case Status.STATUS_ROLLING_BACK:
|
||||
return "STATUS_ROLLING_BACK";
|
||||
case Status.STATUS_ROLLEDBACK:
|
||||
return "STATUS_ROLLEDBACK";
|
||||
case Status.STATUS_COMMITTING:
|
||||
return "STATUS_COMMITING";
|
||||
case Status.STATUS_COMMITTED:
|
||||
return "STATUS_COMMITED";
|
||||
case Status.STATUS_NO_TRANSACTION:
|
||||
return "STATUS_NO_TRANSACTION";
|
||||
case Status.STATUS_UNKNOWN:
|
||||
return "STATUS_UNKNOWN";
|
||||
case Status.STATUS_MARKED_ROLLBACK:
|
||||
return "STATUS_MARKED_ROLLBACK";
|
||||
case Status.STATUS_ACTIVE:
|
||||
return "STATUS_ACTIVE";
|
||||
default:
|
||||
return "STATUS_UNKNOWN(" + status + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of the given XA error code.
|
||||
*/
|
||||
private static String getStringXAErrorCode(int errorCode) {
|
||||
switch (errorCode) {
|
||||
case XAException.XA_HEURCOM:
|
||||
return "XA_HEURCOM";
|
||||
case XAException.XA_HEURHAZ:
|
||||
return "XA_HEURHAZ";
|
||||
case XAException.XA_HEURMIX:
|
||||
return "XA_HEURMIX";
|
||||
case XAException.XA_HEURRB:
|
||||
return "XA_HEURRB";
|
||||
case XAException.XA_NOMIGRATE:
|
||||
return "XA_NOMIGRATE";
|
||||
case XAException.XA_RBCOMMFAIL:
|
||||
return "XA_RBCOMMFAIL";
|
||||
case XAException.XA_RBDEADLOCK:
|
||||
return "XA_RBDEADLOCK";
|
||||
case XAException.XA_RBINTEGRITY:
|
||||
return "XA_RBINTEGRITY";
|
||||
case XAException.XA_RBOTHER:
|
||||
return "XA_RBOTHER";
|
||||
case XAException.XA_RBPROTO:
|
||||
return "XA_RBPROTO";
|
||||
case XAException.XA_RBROLLBACK:
|
||||
return "XA_RBROLLBACK";
|
||||
case XAException.XA_RBTIMEOUT:
|
||||
return "XA_RBTIMEOUT";
|
||||
case XAException.XA_RBTRANSIENT:
|
||||
return "XA_RBTRANSIENT";
|
||||
case XAException.XA_RDONLY:
|
||||
return "XA_RDONLY";
|
||||
case XAException.XA_RETRY:
|
||||
return "XA_RETRY";
|
||||
case XAException.XAER_ASYNC:
|
||||
return "XAER_ASYNC";
|
||||
case XAException.XAER_DUPID:
|
||||
return "XAER_DUPID";
|
||||
case XAException.XAER_INVAL:
|
||||
return "XAER_INVAL";
|
||||
case XAException.XAER_NOTA:
|
||||
return "XAER_NOTA";
|
||||
case XAException.XAER_OUTSIDE:
|
||||
return "XAER_OUTSIDE";
|
||||
case XAException.XAER_PROTO:
|
||||
return "XAER_PROTO";
|
||||
case XAException.XAER_RMERR:
|
||||
return "XAER_RMERR";
|
||||
case XAException.XAER_RMFAIL:
|
||||
return "XAER_RMFAIL";
|
||||
default:
|
||||
return "XA_UNKNOWN(" + errorCode + ")";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)XAResourceImpl.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.XAConnection;
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.sql.XADataSource;
|
||||
/**
|
||||
*
|
||||
* @author Venkat P
|
||||
*/
|
||||
public class XAResourceImpl implements XAResource{
|
||||
|
||||
protected final Object stateLock = new Object();
|
||||
protected AtomicBoolean inLocalTransaction = new AtomicBoolean(false);
|
||||
protected boolean jdbcAutoCommit = true;
|
||||
protected boolean underlyingAutoCommit = true;
|
||||
protected boolean jdbcReadOnly;
|
||||
protected boolean underlyingReadOnly;
|
||||
protected int jdbcTransactionIsolation;
|
||||
protected boolean destroyed = false;
|
||||
protected final XAConnection xaConnection;
|
||||
protected final XAResource xaResource;
|
||||
protected Xid currentXid;
|
||||
/** Creates a new instance of XAResourceImpl */
|
||||
public XAResourceImpl(){
|
||||
xaConnection = null;
|
||||
xaResource = null;
|
||||
}
|
||||
|
||||
private XAResourceImpl(XADataSource xad) throws SQLException{
|
||||
xaConnection = xad.getXAConnection();
|
||||
xaResource = xaConnection.getXAResource();
|
||||
}
|
||||
|
||||
private XAResourceImpl(XAConnection xaConnection) throws SQLException{
|
||||
this.xaConnection = xaConnection;
|
||||
xaConnection.addConnectionEventListener(new javax.sql.ConnectionEventListener(){
|
||||
//@Override
|
||||
public void connectionClosed(javax.sql.ConnectionEvent ce){
|
||||
//only we can do this, ignore
|
||||
}
|
||||
//@Override
|
||||
public void connectionErrorOccurred(javax.sql.ConnectionEvent ce){
|
||||
|
||||
}
|
||||
});
|
||||
this.xaResource = xaConnection.getXAResource();
|
||||
}
|
||||
|
||||
protected XAResource getXAResource() throws Exception{
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void destroy() throws Exception{
|
||||
try{
|
||||
//xaResource.end();
|
||||
}
|
||||
finally{
|
||||
try{
|
||||
xaConnection.close();
|
||||
}catch (SQLException e){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void start(Xid xid, int flags) throws XAException{
|
||||
xaResource.start(xid, flags);
|
||||
synchronized (stateLock){
|
||||
currentXid = xid;
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void end(Xid xid, int flags) throws XAException{
|
||||
xaResource.end(xid, flags);
|
||||
//we want to allow ending transactions that are not the current
|
||||
//one. When one does this, inManagedTransaction is still true.
|
||||
synchronized (stateLock){
|
||||
if (currentXid != null && currentXid.equals(xid)){
|
||||
currentXid = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int prepare(Xid xid) throws XAException
|
||||
{
|
||||
return xaResource.prepare(xid);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void commit(Xid xid, boolean onePhase) throws XAException{
|
||||
xaResource.commit(xid, onePhase);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void rollback(Xid xid) throws XAException{
|
||||
xaResource.rollback(xid);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void forget(Xid xid) throws XAException{
|
||||
xaResource.forget(xid);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public Xid[] recover(int flag) throws XAException{
|
||||
return xaResource.recover(flag);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public boolean isSameRM(XAResource other) throws XAException{
|
||||
return true;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int getTransactionTimeout() throws XAException{
|
||||
return xaResource.getTransactionTimeout();
|
||||
}
|
||||
|
||||
//@Override
|
||||
public boolean setTransactionTimeout(int seconds) throws XAException{
|
||||
return xaResource.setTransactionTimeout(seconds);
|
||||
}
|
||||
|
||||
protected void checkState() throws SQLException{
|
||||
synchronized (stateLock){
|
||||
// Check readonly
|
||||
if (jdbcReadOnly != underlyingReadOnly){
|
||||
//xaConnection.setReadOnly(jdbcReadOnly);
|
||||
underlyingReadOnly = jdbcReadOnly;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)XidFactory.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
|
||||
import java.net.InetAddress;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.net.UnknownHostException;
|
||||
/**
|
||||
* Factory class for generation of Xids
|
||||
* @author Venkat P
|
||||
*/
|
||||
public class XidFactory {
|
||||
|
||||
private String globalId;
|
||||
private long globalIdAsNumber = 0;
|
||||
private boolean isPadApplied = false;
|
||||
private byte[] branchId = new byte[1];
|
||||
private byte[] globalIdToBytes;
|
||||
|
||||
private static XidFactory instance = null;
|
||||
|
||||
public static XidFactory getXidFactoryInstance(){
|
||||
if (instance == null) {
|
||||
instance = new XidFactory();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public XidFactory() {
|
||||
try {
|
||||
globalId = InetAddress.getLocalHost().getHostName();
|
||||
if (globalId.length() > Xid.MAXGTRIDSIZE - 15)
|
||||
globalId = globalId.substring(0, Xid.MAXGTRIDSIZE - 15);
|
||||
globalId = globalId + "/";
|
||||
} catch (UnknownHostException e) {
|
||||
globalId = "localhost/";
|
||||
}
|
||||
globalIdToBytes = globalId.getBytes();
|
||||
}
|
||||
|
||||
public String getBaseGlobalId() {
|
||||
return globalId;
|
||||
}
|
||||
|
||||
public void setBaseGlobalId(final String baseGlobalId) {
|
||||
this.globalId = baseGlobalId;
|
||||
globalIdToBytes = baseGlobalId.getBytes();
|
||||
}
|
||||
|
||||
public synchronized long getGlobalIdNumber() {
|
||||
return globalIdAsNumber;
|
||||
}
|
||||
|
||||
public synchronized void setGlobalIdNumber(final long globalIdNumber) {
|
||||
this.globalIdAsNumber = globalIdNumber;
|
||||
}
|
||||
|
||||
public boolean isPadApplied() {
|
||||
return isPadApplied;
|
||||
}
|
||||
|
||||
public void setPadApplied(boolean pad) {
|
||||
this.isPadApplied = pad;
|
||||
if (pad)
|
||||
branchId = new byte[Xid.MAXBQUALSIZE];
|
||||
else
|
||||
branchId = new byte[1];
|
||||
}
|
||||
|
||||
|
||||
public XidImpl newXid() {
|
||||
long localId = getNextId();
|
||||
String id = Long.toString(localId);
|
||||
int len = isPadApplied?Xid.MAXGTRIDSIZE:id.length()+globalIdToBytes.length;
|
||||
byte[] globalId = new byte[len];
|
||||
System.arraycopy(globalIdToBytes, 0, globalId, 0, globalIdToBytes.length);
|
||||
id.getBytes(0, id.length(), globalId, globalIdToBytes.length);
|
||||
return new XidImpl(globalId, branchId, (int)localId, localId);
|
||||
}
|
||||
|
||||
public XidImpl newBranch(XidImpl xid, long branchIdNum) {
|
||||
String id = Long.toString(branchIdNum);
|
||||
int len = isPadApplied?Xid.MAXBQUALSIZE:id.length();
|
||||
byte[] branchId = new byte[len];
|
||||
id.getBytes(0, id.length(), branchId, 0);
|
||||
return new XidImpl(xid, branchId);
|
||||
}
|
||||
|
||||
public long extractLocalIdFrom(byte[] globalId) {
|
||||
int i, start;
|
||||
int len = globalId.length;
|
||||
|
||||
for (i = 0; globalId[i++] != (byte)'/'; )
|
||||
;
|
||||
start = i;
|
||||
while (i < len && globalId[i] != 0)
|
||||
i++;
|
||||
String globalIdNumber = new String(globalId, 0, start, i - start);
|
||||
return Long.parseLong(globalIdNumber);
|
||||
}
|
||||
|
||||
public String toString(Xid xid) {
|
||||
if (xid instanceof XidImpl)
|
||||
return XidImpl.toString(xid);
|
||||
else
|
||||
return xid.toString();
|
||||
}
|
||||
|
||||
public synchronized long getNextId() {
|
||||
return ++globalIdAsNumber;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
* BEGIN_HEADER - DO NOT EDIT
|
||||
*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the "License"). You may not use this file except
|
||||
* in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* HEADER in each file and include the License file at
|
||||
* https://open-jbi-components.dev.java.net/public/CDDLv1.0.html.
|
||||
* If applicable add the following below this CDDL HEADER,
|
||||
* with the fields enclosed by brackets "[]" replaced with
|
||||
* your own identifying information: Portions Copyright
|
||||
* [year] [name of copyright owner]
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)XidImpl.java
|
||||
*
|
||||
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* END_HEADER - DO NOT EDIT
|
||||
*/
|
||||
|
||||
package org.glassfish.openesb.databasebc.transaction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Venkat P
|
||||
*/
|
||||
import javax.transaction.xa.Xid;
|
||||
|
||||
/**
|
||||
* This object encapsulates the ID of a transaction.
|
||||
* This implementation is immutable and always serializable at runtime.
|
||||
*
|
||||
* @author <a href="Narayana.Rallabandi@Sun.Com">Narayana Rallabandi</a>
|
||||
* @version
|
||||
*/
|
||||
public class XidImpl implements Xid, java.io.Serializable {
|
||||
|
||||
static final long serialVersionUID = -123456789L;
|
||||
public static final int FORMAT_ID = 0x0101;
|
||||
private static boolean trulyGlobalIdsEnabled = false;
|
||||
|
||||
// represents the format id for this xid
|
||||
private final int formatId;
|
||||
// global id immutable once set
|
||||
private final byte[] globalId;
|
||||
// branch qualifier
|
||||
private final byte[] branchId;
|
||||
// hash for the xid
|
||||
private final int hash;
|
||||
// local id for this xid
|
||||
private final long localId;
|
||||
//global id
|
||||
private final GlobalId trulyGlobalId;
|
||||
|
||||
public static void setTrulyGlobalIdsEnabled(boolean newValue) {
|
||||
trulyGlobalIdsEnabled = newValue;
|
||||
}
|
||||
|
||||
public static boolean getTrulyGlobalIdsEnabled() {
|
||||
return trulyGlobalIdsEnabled;
|
||||
}
|
||||
|
||||
public 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()
|
||||
+ ((id instanceof XidImpl) ? ", localId=" + ((XidImpl)id).localId
|
||||
: "")
|
||||
+ "]";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public XidImpl(int formatId,
|
||||
byte[] globalId, byte[] branchId, int hash, long localId){
|
||||
this.formatId = formatId;
|
||||
this.globalId = globalId;
|
||||
this.branchId = branchId;
|
||||
this.hash = hash;
|
||||
this.localId = localId;
|
||||
this.trulyGlobalId = (trulyGlobalIdsEnabled)
|
||||
? new GlobalId(formatId, globalId)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with JBOSS_FORMAT_ID.
|
||||
*/
|
||||
public XidImpl(byte[] globalId, byte[] branchId, int hash, long localId){
|
||||
this.formatId = FORMAT_ID;
|
||||
this.globalId = globalId;
|
||||
this.branchId = branchId;
|
||||
this.hash = hash;
|
||||
this.localId = localId;
|
||||
this.trulyGlobalId = (trulyGlobalIdsEnabled)
|
||||
? new GlobalId(FORMAT_ID, globalId, hash)
|
||||
: null;
|
||||
}
|
||||
|
||||
public XidImpl(final XidImpl xidImpl, final byte[] branchId){
|
||||
this.formatId = xidImpl.formatId;
|
||||
this.globalId = xidImpl.globalId;
|
||||
this.branchId = branchId;
|
||||
this.hash = xidImpl.hash;
|
||||
this.localId = xidImpl.localId;
|
||||
this.trulyGlobalId = (trulyGlobalIdsEnabled)
|
||||
? xidImpl.trulyGlobalId
|
||||
: null;
|
||||
}
|
||||
|
||||
// retrun the Global TxId
|
||||
//@Override
|
||||
public byte[] getGlobalTransactionId(){
|
||||
return (byte[])globalId.clone();
|
||||
}
|
||||
|
||||
// return branch qualifier
|
||||
//@Override
|
||||
public byte[] getBranchQualifier(){
|
||||
if (branchId.length == 0)
|
||||
return branchId;
|
||||
else
|
||||
return (byte[])branchId.clone();
|
||||
}
|
||||
|
||||
//@Override
|
||||
public int getFormatId() {
|
||||
return formatId;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks for same format id, the same global transaction id
|
||||
* and the same transaction branch qualifier.
|
||||
*/
|
||||
//@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj==this)
|
||||
return true;
|
||||
if (obj instanceof XidImpl) {
|
||||
XidImpl other = (XidImpl)obj;
|
||||
|
||||
if (formatId != other.formatId ||
|
||||
globalId.length != other.globalId.length ||
|
||||
branchId.length != other.branchId.length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < globalId.length; ++i)
|
||||
if (globalId[i] != other.globalId[i])
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < branchId.length; ++i)
|
||||
if (branchId[i] != other.branchId[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return toString(this);
|
||||
}
|
||||
|
||||
public long getLocalIdValue() {
|
||||
return localId;
|
||||
}
|
||||
|
||||
public LocalId getLocalId() {
|
||||
return new LocalId(localId);
|
||||
}
|
||||
|
||||
public GlobalId getTrulyGlobalId() {
|
||||
return trulyGlobalId;
|
||||
}
|
||||
|
||||
|
||||
public boolean sameTransaction(XidImpl other){
|
||||
if(other == this)
|
||||
return true;
|
||||
if (formatId != other.formatId ||
|
||||
globalId.length != other.globalId.length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < globalId.length; ++i)
|
||||
if (globalId[i] != other.globalId[i])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//returns a reference to the global id byte array
|
||||
public byte[] getInternalGlobalTransactionId(){
|
||||
return globalId;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue