Coverage report

  %line %branch
mnemosyne.core.StandardTransaction
100% 
100% 

 1  
 /*
 2  
  * Copyright 2004 Charles Blaxland
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package mnemosyne.core;
 17  
 
 18  
 import java.util.Collection;
 19  
 import java.util.HashSet;
 20  
 import java.util.Iterator;
 21  
 import java.util.Set;
 22  
 
 23  
 /**
 24  
  * @version $Id: StandardTransaction.java,v 1.1.1.1 2004/08/07 06:41:12 charlesblaxland Exp $
 25  
  */
 26  9
 public class StandardTransaction implements Transaction
 27  
 {
 28  9
     private Set modifiedObjects = new HashSet();
 29  9
     private Set addedObjects = new HashSet();
 30  9
     private boolean complete = false;
 31  
 
 32  
     public void addModifiedObject(PersistentObject obj)
 33  
     {
 34  7
         modifiedObjects.add(obj);
 35  7
     }
 36  
 
 37  
     public boolean hasModifiedOrAddedObject(PersistentObject obj)
 38  
     {
 39  5
         return modifiedObjects.contains(obj) || addedObjects.contains(obj);
 40  
     }
 41  
 
 42  
     public void prepareForCommit()
 43  
     {
 44  9
         for (Iterator iterator = modifiedObjects.iterator(); iterator.hasNext();)
 45  
         {
 46  3
             PersistentObject persistentObject = (PersistentObject) iterator.next();
 47  3
             addedObjects.addAll(persistentObject.prepareForCommit());
 48  
         }
 49  3
     }
 50  
 
 51  
     public void commit(Version versionToCommitAs)
 52  
     {
 53  1
         commit(modifiedObjects, versionToCommitAs);
 54  1
         commit(addedObjects, versionToCommitAs);
 55  1
         complete = true;
 56  1
     }
 57  
 
 58  
     private static void commit(Collection persistentObjects, Version versionToCommitAs)
 59  
     {
 60  6
         for (Iterator iterator = persistentObjects.iterator(); iterator.hasNext();)
 61  
         {
 62  2
             PersistentObject persistentObject = (PersistentObject) iterator.next();
 63  2
             persistentObject.commit(versionToCommitAs);
 64  
         }
 65  2
     }
 66  
 
 67  
     public void rollback()
 68  
     {
 69  18
         rollback(modifiedObjects);
 70  8
         rollback(addedObjects);
 71  8
         complete = true;
 72  8
     }
 73  
 
 74  
     private static void rollback(Collection persistentObjects)
 75  
     {
 76  59
         for (Iterator iterator = persistentObjects.iterator(); iterator.hasNext();)
 77  
         {
 78  17
             PersistentObject persistentObject = (PersistentObject) iterator.next();
 79  7
             persistentObject.rollback();
 80  
         }
 81  16
     }
 82  
 
 83  
     protected void finalize() throws Throwable
 84  
     {
 85  17
         super.finalize();
 86  17
         if (!complete)
 87  
         {
 88  17
             rollback();
 89  
         }
 90  7
     }
 91  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.