commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject cvs commit: jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/util/xa AbstractXAResource.java TransactionalResource.java
Date Thu, 01 Jul 2004 09:28:33 GMT
ozeigermann    2004/07/01 02:28:33

  Modified:    transaction/src/java/org/apache/commons/transaction/util/xa
                        AbstractXAResource.java TransactionalResource.java
  Log:
  - Misc corrections
  - Added close and xid methods to tx resource
  
  Revision  Changes    Path
  1.2       +36 -23    jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/util/xa/AbstractXAResource.java
  
  Index: AbstractXAResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/util/xa/AbstractXAResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractXAResource.java	23 Jun 2004 08:40:58 -0000	1.1
  +++ AbstractXAResource.java	1 Jul 2004 09:28:33 -0000	1.2
  @@ -48,21 +48,26 @@
   
       public abstract Xid[] recover(int flag) throws XAException;
   
  -    protected abstract LoggerFacade getLogger();
  +    protected abstract LoggerFacade getLoggerFacade();
   
       public void forget(Xid xid) throws XAException {
  -        getLogger().logFine("Preparing transaction branch " + xid);
  +        getLoggerFacade().logFine("Preparing transaction branch " + xid);
  +        TransactionalResource ts = getTransactionalResource(xid);
  +        if (ts == null) {
  +            throw new XAException(XAException.XAER_NOTA);
  +        }
  +        ts.close();
           setCurrentlyActiveTransactionalResource(null);
           removeActiveTransactionalResource(xid);
       }
   
       public void commit(Xid xid, boolean onePhase) throws XAException {
  -        TransactionalResource ts = getActiveTransactionalResource(xid);
  +        TransactionalResource ts = getTransactionalResource(xid);
           if (ts == null) {
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLogger().logFine("Committing transaction branch " + ts);
  +        getLoggerFacade().logFine("Committing transaction branch " + ts);
   
           if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
               throw new XAException(XAException.XA_RBROLLBACK);
  @@ -81,31 +86,33 @@
       }
   
       public void rollback(Xid xid) throws XAException {
  -        TransactionalResource ts = getActiveTransactionalResource(xid);
  +        TransactionalResource ts = getTransactionalResource(xid);
           if (ts == null) {
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLogger().logFine("Rolling back transaction branch " + ts);
  +        getLoggerFacade().logFine("Rolling back transaction branch " + ts);
   
  -        ts.commit();
  +        ts.rollback();
           setCurrentlyActiveTransactionalResource(null);
           removeActiveTransactionalResource(xid);
       }
   
       public int prepare(Xid xid) throws XAException {
  -        TransactionalResource ts = getActiveTransactionalResource(xid);
  +        TransactionalResource ts = getTransactionalResource(xid);
           if (ts == null) {
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLogger().logFine("Preparing transaction branch " + ts);
  +        getLoggerFacade().logFine("Preparing transaction branch " + ts);
   
           if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
               throw new XAException(XAException.XA_RBROLLBACK);
           }
  -
  -        return ts.prepare();
  +        	
  +        int result = ts.prepare();
  +        ts.setStatus(STATUS_PREPARED);
  +        return result;
       }
   
       public void end(Xid xid, int flags) throws XAException {
  @@ -116,7 +123,7 @@
           if (getCurrentlyActiveTransactionalResource() == null) {
               throw new XAException(XAException.XAER_INVAL);
           }
  -        getLogger().logFine(
  +        getLoggerFacade().logFine(
               "Thread "
                   + Thread.currentThread()
                   + (flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : " ends")
  @@ -127,23 +134,21 @@
               case TMSUSPEND :
                   addSuspendedTransactionalResource(xid, ts);
                   removeActiveTransactionalResource(xid);
  -                setCurrentlyActiveTransactionalResource(null);
                   break;
               case TMFAIL :
                   ts.setStatus(STATUS_MARKED_ROLLBACK);
  -                setCurrentlyActiveTransactionalResource(null);
                   break;
               case TMSUCCESS :
  -                setCurrentlyActiveTransactionalResource(null);
                   break;
           }
  +        setCurrentlyActiveTransactionalResource(null);
       }
   
       public void start(Xid xid, int flags) throws XAException {
           if (getCurrentlyActiveTransactionalResource() != null) {
               throw new XAException(XAException.XAER_INVAL);
           }
  -        getLogger().logFine(
  +        getLoggerFacade().logFine(
               "Thread "
                   + Thread.currentThread()
                   + (flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes")
  @@ -156,9 +161,12 @@
               case TMNOFLAGS :
               case TMJOIN :
               default :
  -                ts = createTransactionResource(xid);
  -                setCurrentlyActiveTransactionalResource(ts);
  -                addAcitveTransactionalResource(xid, ts);
  +                try {
  +					ts = createTransactionResource(xid);
  +				} catch (Exception e) {
  +					getLoggerFacade().logSevere("Could not create new transactional  resource", e);
  +					throw new XAException(e.getMessage());
  +				}
                   break;
               case TMRESUME :
                   ts = getSuspendedTransactionalResource(xid);
  @@ -172,7 +180,7 @@
           addAcitveTransactionalResource(xid, ts);
       }
   
  -    abstract protected TransactionalResource createTransactionResource(Xid xid);
  +    abstract protected TransactionalResource createTransactionResource(Xid xid) throws
Exception;
   
       protected TransactionalResource getCurrentlyActiveTransactionalResource() {
           TransactionalResource context = (TransactionalResource) activeTransactionBranch.get();
  @@ -183,6 +191,11 @@
           activeTransactionBranch.set(context);
       }
   
  +    protected TransactionalResource getTransactionalResource(Xid xid) {
  +    	TransactionalResource ts =  getActiveTransactionalResource(xid);
  +    	if (ts != null) return ts;
  +    	else return getSuspendedTransactionalResource(xid);
  +    }
       protected TransactionalResource getActiveTransactionalResource(Xid xid) {
           Xid wxid = XidWrapper.wrap(xid);
           return (TransactionalResource) activeContexts.get(wxid);
  
  
  
  1.2       +6 -3      jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/util/xa/TransactionalResource.java
  
  Index: TransactionalResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/util/xa/TransactionalResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransactionalResource.java	23 Jun 2004 08:40:58 -0000	1.1
  +++ TransactionalResource.java	1 Jul 2004 09:28:33 -0000	1.2
  @@ -24,6 +24,7 @@
   package org.apache.commons.transaction.util.xa;
   
   import javax.transaction.xa.XAException;
  +import javax.transaction.xa.Xid;
   
   /**
    * Interface for something that makes up a transactional resource.
  @@ -33,6 +34,8 @@
       public void commit() throws XAException;
       public int prepare() throws XAException;
       public void rollback() throws XAException;
  +    public void close() throws XAException;
       public int getStatus();
       public void setStatus(int status);
  +    public Xid getXid();
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message