dirkv       01/09/22 05:53:12

  Modified:    src/stores/slidestore/reference JDBCContentStore.java
                        JDBCDescriptorsStore.java
  Log:
  modifications outside a transaction are discarded (autocommit=false)
  
  Revision  Changes    Path
  1.12      +33 -14    
jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java
  
  Index: JDBCContentStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JDBCContentStore.java     2001/09/21 00:57:41     1.11
  +++ JDBCContentStore.java     2001/09/22 12:53:12     1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v 1.11 
2001/09/21 00:57:41 dirkv Exp $
  - * $Revision: 1.11 $
  - * $Date: 2001/09/21 00:57:41 $
  + * $Header: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCContentStore.java,v 1.12 
2001/09/22 12:53:12 dirkv Exp $
  + * $Revision: 1.12 $
  + * $Date: 2001/09/22 12:53:12 $
    *
    * ====================================================================
    *
  @@ -90,7 +90,7 @@
    * JDBC 2.0 compliant implementation of ContentStore.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    */
   public class JDBCContentStore extends AbstractSimpleService
       implements ContentStore {
  @@ -138,6 +138,11 @@
        */
       protected String password;
       
  +    /**
  +     * This store doesn't handle nested transactions, this variable keeps track 
  +     * if the store is already enlisted to a transaction.
  +     */
  +    protected boolean alreadyEnlisted=false;
       
       // -------------------------------------------------------- Service Methods
       
  @@ -209,13 +214,13 @@
               getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
               throw new ServiceConnectionFailedException(this, e);
           }
  -        
  -        // Start with autocommit true (start of transaction will set it to false)
  +
  +        // all updates must be done inside a transaction, no auto commits
           try {
  -            connection.setAutoCommit(true);
  +            connection.setAutoCommit(false);
           } catch (SQLException e) {
           }
  -        
  +
           Statement statement = null;
           try {
               statement = connection.createStatement();
  @@ -223,10 +228,16 @@
               for (int i=0; i<statements.length ; i++ ) {
                   statement.execute(statements[i]);
               }
  +            // Cloudscape needs a commit on DDL statements (create,...)
  +            connection.commit();
           } catch (SQLException e) {
  +            try { connection.rollback(); } catch (SQLException ex) { }
           } finally {
               closeStatement(statement);
           }
  +
  +        // we are just connected and are not enlisted
  +        alreadyEnlisted=false;
       }
       
       
  @@ -344,11 +355,12 @@
           throws XAException {
           super.commit(xid, onePhase);
           try {
  +//            getLogger().log("commit",LOG_CHANNEL,Logger.DEBUG);
               connection.commit();
  -            connection.setAutoCommit(true);
           } catch (SQLException e) {
               throw new XAException(XAException.XA_RBCOMMFAIL);
           }
  +        alreadyEnlisted=false;
       }
       
       
  @@ -360,11 +372,12 @@
           throws XAException {
           super.rollback(xid);
           try {
  +//            getLogger().log("rollback",LOG_CHANNEL,Logger.DEBUG);
               connection.rollback();
  -            connection.setAutoCommit(true);
           } catch (SQLException e) {
               throw new XAException(XAException.XA_HEURCOM);
           }
  +        alreadyEnlisted=false;
       }
       
       
  @@ -374,10 +387,16 @@
       public void start(Xid xid, int flags)
           throws XAException {
           super.start(xid, flags);
  -        try {
  -            connection.setAutoCommit(false);
  -        } catch (SQLException e) {
  -            throw new XAException(XAException.XAER_RMERR);
  +        if (!alreadyEnlisted) 
  +        {
  +            try {
  +//                getLogger().log("start",LOG_CHANNEL,Logger.DEBUG);
  +                // discard changes made outside a tranaction
  +                connection.rollback();
  +            } catch (SQLException e) {
  +                throw new XAException(XAException.XAER_RMERR);
  +            }
  +            alreadyEnlisted=true;
           }
       }
       
  
  
  
  1.27      +30 -11    
jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java
  
  Index: JDBCDescriptorsStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- JDBCDescriptorsStore.java 2001/09/21 00:57:41     1.26
  +++ JDBCDescriptorsStore.java 2001/09/22 12:53:12     1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 
1.26 2001/09/21 00:57:41 dirkv Exp $
  - * $Revision: 1.26 $
  - * $Date: 2001/09/21 00:57:41 $
  + * $Header: 
/home/cvs/jakarta-slide/src/stores/slidestore/reference/JDBCDescriptorsStore.java,v 
1.27 2001/09/22 12:53:12 dirkv Exp $
  + * $Revision: 1.27 $
  + * $Date: 2001/09/22 12:53:12 $
    *
    * ====================================================================
    *
  @@ -86,7 +86,7 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    * @author Dirk Verbeeck
  - * @version $Revision: 1.26 $
  + * @version $Revision: 1.27 $
    */
   
   public class JDBCDescriptorsStore
  @@ -203,6 +203,11 @@
        */
       protected int jdbcVersion;
       
  +    /**
  +     * This store doesn't handle nested transactions, this variable keeps track 
  +     * if the store is already enlisted to a transaction.
  +     */
  +    protected boolean alreadyEnlisted=false;
       
       // -------------------------------------------------------- Service Methods
       
  @@ -310,7 +315,7 @@
               throw new ServiceConnectionFailedException(this, e);
           }
   
  -        // Start with autocommit true (start of transaction will set it to false)
  +        // all updates must be done inside a transaction, no auto commits
           try {
               connection.setAutoCommit(false);
           } catch (SQLException e) {
  @@ -323,10 +328,16 @@
               for (int i=0; i<statements.length ; i++ ) {
                   statement.execute(statements[i]);
               }
  +            // Cloudscape needs a commit on DDL statements (create,...)
  +            connection.commit();
           } catch (SQLException e) {
  +            try { connection.rollback(); } catch (SQLException ex) { }
           } finally {
               closeStatement(statement);
           }
  +        
  +        // we are just connected and are not enlisted
  +        alreadyEnlisted=false;
       }
       
       
  @@ -491,11 +502,12 @@
           throws XAException {
           super.commit(xid, onePhase);
           try {
  +//            getLogger().log("commit",LOG_CHANNEL,Logger.DEBUG);
               connection.commit();
  -            connection.setAutoCommit(true);
           } catch (SQLException e) {
               throw new XAException(XAException.XA_RBCOMMFAIL);
           }
  +        alreadyEnlisted=false;
       }
       
       
  @@ -507,11 +519,12 @@
           throws XAException {
           super.rollback(xid);
           try {
  +//            getLogger().log("rollback",LOG_CHANNEL,Logger.DEBUG);
               connection.rollback();
  -            connection.setAutoCommit(true);
           } catch (SQLException e) {
               throw new XAException(XAException.XA_HEURCOM);
           }
  +        alreadyEnlisted=false;
       }
       
       
  @@ -521,10 +534,16 @@
       public void start(Xid xid, int flags)
           throws XAException {
           super.start(xid, flags);
  -        try {
  -            connection.setAutoCommit(false);
  -        } catch (SQLException e) {
  -            throw new XAException(XAException.XAER_RMERR);
  +        if (!alreadyEnlisted) 
  +        {
  +            try {
  +//                getLogger().log("start",LOG_CHANNEL,Logger.DEBUG);
  +                // discard changes made outside a tranaction
  +                connection.rollback();
  +            } catch (SQLException e) {
  +                throw new XAException(XAException.XAER_RMERR);
  +            }
  +            alreadyEnlisted=true;
           }
       }
       
  
  
  

Reply via email to