db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/odmg ODMGRollbackTest.java
Date Mon, 28 Jul 2003 14:34:21 GMT
arminw      2003/07/28 07:34:21

  Modified:    src/java/org/apache/ojb/odmg TransactionImpl.java
                        ObjectEnvelopeTable.java
               src/test/org/apache/ojb/odmg ODMGRollbackTest.java
  Log:
  - fix checkpoint() problem posted by
  Jeremy Wilkerson:
  I'm using the ODMG API of OJB 1.0.rc3 with MySQL. When I call
  checkpoint() on a Transaction, the underlying
  database transaction isn't being committed.
  
  - move PB.beginTranscation call from ObjectEnvelopeTable
  to TransactionImpl
  
  - make ObjectEnvelopeTable reuseable
  
  Revision  Changes    Path
  1.43      +15 -3     db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- TransactionImpl.java	7 Jun 2003 10:06:58 -0000	1.42
  +++ TransactionImpl.java	28 Jul 2003 14:34:20 -0000	1.43
  @@ -330,6 +330,13 @@
       {
           ObjectEnvelope item;
   
  +        /*
  +        arminw:
  +        if broker isn't in PB-tx, start tx
  +        */
  +        if (log.isDebugEnabled()) log.debug("call beginTransaction() on PB instance");
  +        if(!broker.isInTransaction()) broker.beginTransaction();
  +
           // Notify objects of impending commits.
           Enumeration enum = objectEnvelopeTable.elements();
           while (enum.hasMoreElements())
  @@ -419,8 +426,9 @@
                */
               try
               {
  -                objectEnvelopeTable.close();
  -                objectEnvelopeTable = null;
  +                objectEnvelopeTable.refresh();
  +                // we reuse ObjectEnvelopeTable instance
  +                // objectEnvelopeTable = null;
               }
               catch (Exception e)
               {
  @@ -457,6 +465,10 @@
           try
           {
               doCommitOnObjects();
  +            // do real commit
  +            broker.commitTransaction();
  +            // associate new PB instance
  +            getBroker();
           }
           catch (Throwable t)
           {
  
  
  
  1.26      +32 -19    db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ObjectEnvelopeTable.java	28 Apr 2003 17:10:41 -0000	1.25
  +++ ObjectEnvelopeTable.java	28 Jul 2003 14:34:20 -0000	1.26
  @@ -116,13 +116,15 @@
        */
       private boolean needsCommit = false;
   
  -    public void close()
  +    /**
  +     * prepare this instance for reuse
  +     */
  +    public void refresh()
       {
           /**
            * MBAIRD: be nice and remove all references so they can be
            * gc'd
            */
  -        transaction = null;
           if (mhtObjectEnvelopes != null)
           {
               Iterator iter = mvOrderOfIds.iterator();
  @@ -131,9 +133,11 @@
               {
                   temp = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
                   temp.close();
  -                temp = null;
               }
           }
  +        needsCommit = false;
  +        mhtObjectEnvelopes.clear();
  +        mvOrderOfIds.clear();
       }
   
       /**
  @@ -166,9 +170,11 @@
               // all neccessary db operations are executed within a PersistenceBroker transaction:
               if (!broker.isInTransaction())
               {
  -                if (log.isDebugEnabled())
  -                    log.debug("call beginTransaction() on PB instance");
  -                broker.beginTransaction();
  +//                if (log.isDebugEnabled())
  +//                    log.debug("call beginTransaction() on PB instance");
  +//                broker.beginTransaction();
  +                log.error("PB associated with current odmg-tx is not in tx");
  +                throw new TransactionAbortedException("Underlying PB is not in tx");
               }
   
               // Committing has to be done in two phases. First implicitly upgrade to lock
on all related
  @@ -190,10 +196,10 @@
   
               // 4. execute batch
               connMan.executeBatch();
  -            
  +
               // 5.Update all Envelopes to new CleanState
               setCleanState();
  -            
  +
           }
           catch (Throwable t)
           {
  @@ -213,6 +219,7 @@
           }
           finally
           {
  +            needsCommit = false;
               connMan.setBatchMode(saveBatchMode);
           }
       }
  @@ -317,7 +324,6 @@
                   needsCommit = true;
               }
           }
  -
       }
   
       /**
  @@ -325,19 +331,26 @@
        */
       public void rollback()
       {
  -        PersistenceBroker broker = transaction.getBroker();
  -        Iterator iter = mvOrderOfIds.iterator();
  -        while (iter.hasNext())
  +        try
           {
  -            ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  -            if (log.isDebugEnabled())
  -                log.debug("rollback: " + mod);
  -            // if the Object has been modified has been modified by transaction, mark object
as dirty
  -            if (mod.hasChanged())
  +            PersistenceBroker broker = transaction.getBroker();
  +            Iterator iter = mvOrderOfIds.iterator();
  +            while (iter.hasNext())
               {
  -                mod.setModificationState(mod.getModificationState().markDirty());
  +                ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  +                if (log.isDebugEnabled())
  +                    log.debug("rollback: " + mod);
  +                // if the Object has been modified has been modified by transaction, mark
object as dirty
  +                if (mod.hasChanged())
  +                {
  +                    mod.setModificationState(mod.getModificationState().markDirty());
  +                }
  +                mod.getModificationState().rollback(mod, broker);
               }
  -            mod.getModificationState().rollback(mod, broker);
  +        }
  +        finally
  +        {
  +            needsCommit = false;
           }
       }
   
  
  
  
  1.14      +15 -17    db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java
  
  Index: ODMGRollbackTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ODMGRollbackTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ODMGRollbackTest.java	16 Jul 2003 11:21:39 -0000	1.13
  +++ ODMGRollbackTest.java	28 Jul 2003 14:34:20 -0000	1.14
  @@ -353,11 +353,10 @@
               Transaction tx = ojb.newTransaction();
               tx.begin();
               storeObjects(tx, getNewODMGZoos(10));
  -            storeObjects(tx, getNewProjects(10));
  -            // now we bring objects to DB
  +            // now we store objects to DB
               tx.checkpoint();
  -
  -            //we abort tx
  +            storeObjects(tx, getNewProjects(10));
  +            //we abort tx, all actions after the last checkpoint call should be rollback
               tx.abort();
   
               int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
  @@ -365,23 +364,22 @@
               int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(ojb, ODMGZoo.class);
               int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(ojb, Project.class);
   
  -            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore, odmgZoosAfter);
  +            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfter);
               assertEquals("Wrong number of projects found", projectsBefore, projectsAfter);
  -            assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore), odmgZoosAfterOQL);
  -            assertEquals("Wrong number of projects found", (projectsBefore), projectsAfterOQL);
  +            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfterOQL);
  +            assertEquals("Wrong number of projects found", projectsBefore, projectsAfterOQL);
   
  -            //We do this twice
  +            //***********************
  +            // do the procedure again
               odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
               projectsBefore = getDBObjectCountWithNewPB(Project.class);
  -
  +            // we reuse current tx
               tx.begin();
               storeObjects(tx, getNewODMGZoos(10));
  -            storeObjects(tx, getNewProjects(10));
  -
  -            // now we bring objects to DB
  +            // now we store objects to DB
               tx.checkpoint();
  -
  -            //we abort tx
  +            storeObjects(tx, getNewProjects(10));
  +            //we abort tx, all actions after the last checkpoint call should be rollback
               tx.abort();
   
               odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
  @@ -389,10 +387,10 @@
               odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(ojb, ODMGZoo.class);
               projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(ojb, Project.class);
   
  -            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore, odmgZoosAfter);
  +            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfter);
               assertEquals("Wrong number of projects found", projectsBefore, projectsAfter);
  -            assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore), odmgZoosAfterOQL);
  -            assertEquals("Wrong number of projects found", (projectsBefore), projectsAfterOQL);
  +            assertEquals("Wrong number of odmgZoos found", odmgZoosBefore + 10, odmgZoosAfterOQL);
  +            assertEquals("Wrong number of projects found", projectsBefore, projectsAfterOQL);
           }
           finally
           {
  
  
  

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


Mime
View raw message