Coverage report

  %line %branch
mnemosyne.core.AggregatedTransaction
95% 
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 mnemosyne.guid.Guid;
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 import java.util.HashMap;
 23  
 import java.util.Map;
 24  
 
 25  
 /**
 26  
  * @version $Id: AggregatedTransaction.java,v 1.1.1.1 2004/08/07 06:40:56 charlesblaxland Exp $
 27  
  */
 28  32
 public class AggregatedTransaction
 29  
 {
 30  6
     private static final Log log = LogFactory.getLog(AggregatedTransaction.class);
 31  
 
 32  32
     private Map modifiedObjects = new HashMap();
 33  32
     private Map unresolvedReferences = new HashMap();
 34  32
     private boolean complete = false;
 35  
 
 36  
     public PersistentObject addModifiedObject(final PersistentObject obj)
 37  
     {
 38  15
         Guid guid = obj.getGuid();
 39  15
         PersistentObject result = obj;
 40  15
         PersistentObject modifiedObject = (PersistentObject) modifiedObjects.get(guid);
 41  15
         if (modclass="keyword">ifiedObject == null)
 42  
         {
 43  14
             if (log.isTraceEnabled())
 44  0
                 log.trace("Adding modified object " + obj);
 45  
 
 46  14
             result = resolveUnresolvedReferences(obj);
 47  14
             modifiedObjects.put(guid, result);
 48  
         }
 49  
         else
 50  
         {
 51  1
             if (log.isTraceEnabled())
 52  0
                 log.trace("Modified object already loaded " + obj);
 53  1
             result = modifiedObject;
 54  
         }
 55  
 
 56  15
         return result;
 57  
     }
 58  
 
 59  
     public PersistentObject addUnresolvedReference(final PersistentObject obj)
 60  
     {
 61  6
         Guid guid = obj.getGuid();
 62  6
         PersistentObject result = obj;
 63  6
         PersistentObject modifiedObject = (PersistentObject) modifiedObjects.get(guid);
 64  6
         if (modclass="keyword">ifiedObject == null)
 65  
         {
 66  5
             log.debug("Adding unresolved reference " + obj);
 67  5
             if (!unresolvedReferences.containsKey(guid))
 68  
             {
 69  4
                 unresolvedReferences.put(guid, obj);
 70  
             }
 71  
         }
 72  
         else
 73  
         {
 74  1
             log.debug("Reference " + obj + " found in modified map");
 75  1
             result = modifiedObject;
 76  
         }
 77  
 
 78  6
         return result;
 79  
     }
 80  
 
 81  
     public PersistentObject resolveObject(final PersistentObject obj)
 82  
     {
 83  36
         Guid guid = obj.getGuid();
 84  36
         PersistentObject resolvedObject = (PersistentObject) modifiedObjects.get(guid);
 85  36
         if (resolvedObject == null)
 86  
         {
 87  23
             resolvedObject = resolveUnresolvedReferences(obj);
 88  
         }
 89  
         else
 90  
         {
 91  13
             log.debug("Found modified version of object " + obj);
 92  
         }
 93  
 
 94  36
         return resolvedObject;
 95  
     }
 96  
 
 97  
     private PersistentObject resolveUnresolvedReferences(final PersistentObject obj)
 98  
     {
 99  37
         Guid guid = obj.getGuid();
 100  37
         PersistentObject result = obj;
 101  37
         PersistentObject unresolvedRef = (PersistentObject) unresolvedReferences.remove(guid);
 102  37
         if (unresolvedRef != null)
 103  
         {
 104  3
             log.debug("Resolved unresolved reference " + obj);
 105  3
             unresolvedRef.initialize(obj.findTargetObject());
 106  3
             result = unresolvedRef;
 107  
         }
 108  
 
 109  37
         return result;
 110  
     }
 111  
 
 112  
     public boolean isComplete()
 113  
     {
 114  4
         return complete;
 115  
     }
 116  
 
 117  
     public void setComplete(boolean complete)
 118  
     {
 119  3
         this.complete = complete;
 120  3
     }
 121  
 
 122  
 }

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