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/memory/jca MapXAResource.java
Date Tue, 20 Jul 2004 09:21:32 GMT
ozeigermann    2004/07/20 02:21:32

  Modified:    transaction/src/java/org/apache/commons/transaction/memory/jca
                        MapXAResource.java
  Log:
  Ported it to AbstractXAResource
  
  Revision  Changes    Path
  1.4       +57 -88    jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/jca/MapXAResource.java
  
  Index: MapXAResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/transaction/src/java/org/apache/commons/transaction/memory/jca/MapXAResource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MapXAResource.java	12 Jun 2004 13:39:24 -0000	1.3
  +++ MapXAResource.java	20 Jul 2004 09:21:31 -0000	1.4
  @@ -23,28 +23,33 @@
   
   package org.apache.commons.transaction.memory.jca;
   
  +import java.io.PrintWriter;
   
  -import javax.transaction.Status;
   import javax.transaction.xa.XAException;
   import javax.transaction.xa.XAResource;
   import javax.transaction.xa.Xid;
   
   import org.apache.commons.transaction.memory.TransactionalMapWrapper;
  +import org.apache.commons.transaction.util.LoggerFacade;
  +import org.apache.commons.transaction.util.PrintWriterLogger;
  +import org.apache.commons.transaction.util.xa.AbstractTransactionalResource;
  +import org.apache.commons.transaction.util.xa.AbstractXAResource;
  +import org.apache.commons.transaction.util.xa.TransactionalResource;
   
   /**
  - *   
  - * @version $Revision$
    * 
  + * @version $Revision$
  + *  
    */
  -public class MapXAResource implements XAResource, Status {
  +public class MapXAResource extends AbstractXAResource {
   
       TransactionalMapWrapper map;
  -    TransactionalMapWrapper suspended = null;
  -
  -    boolean includeBranch = true;
  +    LoggerFacade loggerFacade;
   
       public MapXAResource(TransactionalMapWrapper map) {
           this.map = map;
  +        // log important stuff to standard out as long as nothing else is configured
  +        this.loggerFacade = new PrintWriterLogger(new PrintWriter(System.out), "WebDAVXAResource",
false);
       }
   
       public int getTransactionTimeout() throws XAException {
  @@ -63,97 +68,61 @@
           return null;
       }
   
  -    public int prepare(Xid xid) throws XAException {
  -        System.out.println("Prepare "+xid);
  -        
  -        if (map == null) {
  -            throw new XAException(XAException.XAER_NOTA);
  -        }
  -        if (xid == null) {
  -            throw new XAException(XAException.XAER_INVAL);
  -        }
  +    protected LoggerFacade getLoggerFacade() {
  +        return loggerFacade;
  +    }
  +    
  +    protected void setLoggerFacade(LoggerFacade loggerFacade) {
  +        this.loggerFacade = loggerFacade;
  +    }
   
  -        if (map.isTransactionMarkedForRollback()) {
  -            throw new XAException(XAException.XA_RBROLLBACK);
  -        }
  -        
  -        if (map.isReadOnly()) {
  -            return XA_RDONLY;
  -        }
  -        
  -        return XA_OK;
  +    protected void setLoggerFacade(PrintWriter out) {
  +        loggerFacade = new PrintWriterLogger(out, "WebDAVXAResource", true);
       }
   
  -    public void forget(Xid xid) throws XAException {
  -        System.out.println("Forget "+xid);
  -        map = null;
  -    }
  -
  -    public void rollback(Xid xid) throws XAException {
  -        System.out.println("Rollback "+xid);
  -        if (map == null)
  -            throw new XAException(XAException.XAER_NOTA);
  -        if (xid == null)
  -            throw new XAException(XAException.XAER_INVAL);
  -        try {
  -            map.rollbackTransaction();
  -        } catch (IllegalStateException e) {
  -            throw new XAException(e.toString());
  -        }
  +    protected TransactionalResource createTransactionResource(Xid xid) throws Exception
{
  +        return new MapTransactionalResource(xid, map, getLoggerFacade());
  +    }
   
  +    protected boolean includeBranchInXid() {
  +        return true;
       }
   
  -    public void end(Xid xid, int flags) throws XAException {
  -        System.out.println("End "+xid);
  +    protected static class MapTransactionalResource extends AbstractTransactionalResource
{
   
  -        if (map == null)
  -            throw new XAException(XAException.XAER_NOTA);
  -        if (xid == null)
  -            throw new XAException(XAException.XAER_INVAL);
  -
  -        if (flags == XAResource.TMSUSPEND) {
  -            suspended = map;
  -            map = null;
  -        }
  +        TransactionalMapWrapper map;
   
  -        if (flags == XAResource.TMFAIL) {
  -            map.markTransactionForRollback();
  -        }
  +        LoggerFacade loggerFacade;
   
  -    }
  +        public MapTransactionalResource(Xid xid, TransactionalMapWrapper map, LoggerFacade
loggerFacade) {
  +            super(xid);
  +            this.map = map;
  +            this.loggerFacade = loggerFacade;
  +        }
   
  -    public void start(Xid xid, int flags) throws XAException {
  -        System.out.println("Start "+xid);
  +        public void commit() throws XAException {
  +            try {
  +                map.commitTransaction();
  +            } catch (IllegalStateException e) {
  +                throw new XAException(e.toString());
  +            }
  +        }
   
  -        switch (flags) {
  -            case TMNOFLAGS :
  -            case TMJOIN :
  -                try {
  -                    map.startTransaction();
  -                } catch (IllegalStateException e) {
  -                    throw new XAException(e.toString());
  -                }
  -                break;
  -            case TMRESUME :
  -                if (suspended == null) {
  -                    throw new XAException(XAException.XAER_NOTA);
  -                }
  -                map = suspended;
  -                suspended = null;
  +        public void rollback() throws XAException {
  +            try {
  +                map.rollbackTransaction();
  +            } catch (IllegalStateException e) {
  +                throw new XAException(e.toString());
  +            }
           }
  -    }
   
  -    public void commit(Xid xid, boolean onePhase) throws XAException {
  -        System.out.println("Commit "+xid);
  -        if (map == null)
  -            throw new XAException(XAException.XAER_NOTA);
  -        if (xid == null)
  -            throw new XAException(XAException.XAER_INVAL);
  -        try {
  -            map.commitTransaction();
  -        } catch (IllegalStateException e) {
  -            throw new XAException(e.toString());
  +        public int prepare() throws XAException {
  +            if (map.isTransactionMarkedForRollback()) {
  +                throw new XAException(XAException.XA_RBROLLBACK);
  +            }
  +
  +            return (map.isReadOnly() ? XA_RDONLY : XA_OK);
           }
   
       }
  -}
  +}
  \ No newline at end of file
  
  
  

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