:D remove unused databasebc.transaction.*

master
Vitaliy Filippov 2015-12-20 20:45:18 +03:00
parent ea5b40011d
commit 4a592c717b
9 changed files with 0 additions and 1818 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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 + ")";
}
}
}

View File

@ -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