Coverage report

  %line %branch
mnemosyne.system.LocalPersistentSystem
0% 
0% 

 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.system;
 17  
 
 18  
 import mnemosyne.archiver.Archiver;
 19  
 import mnemosyne.archiver.ArchiverException;
 20  
 import mnemosyne.core.*;
 21  
 import mnemosyne.util.PersistenceRuntimeException;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  * @version $Id: LocalPersistentSystem.java,v 1.1.1.1 2004/08/07 06:41:22 charlesblaxland Exp $
 27  
  */
 28  
 public class LocalPersistentSystem implements PersistentSystem
 29  
 {
 30  0
     private static final Log log = LogFactory.getLog(LocalPersistentSystem.class);
 31  
 
 32  
     private PersistentRoot root;
 33  
 
 34  
     private Archiver archiver;
 35  
     private VersionManager versionMgr;
 36  
 
 37  
     public LocalPersistentSystem(Archiver archiver, VersionManager versionMgr) throws InitializationException
 38  0
     {
 39  0
         this.archiver = archiver;
 40  0
         this.versionMgr = versionMgr;
 41  
         try
 42  
         {
 43  0
             root = this.archiver.loadLatest();
 44  0
         }
 45  
         catch (ArchiverException e)
 46  
         {
 47  0
             throw new InitializationException("Unable to load persistent data from archiver", e);
 48  
         }
 49  0
     }
 50  
 
 51  
     public void advanceVersion()
 52  
     {
 53  0
         versionMgr.advanceThisThreadsVersion();
 54  0
     }
 55  
 
 56  
     public Object getPersistentRoot(String rootName)
 57  
     {
 58  0
         return root.getPersistentRoot(rootName);
 59  
     }
 60  
 
 61  
     public void setPersistentRoot(String rootName, Object value)
 62  
     {
 63  0
         root.setPersistentRoot(rootName, value);
 64  0
     }
 65  
 
 66  
     public void removePersistentRoot(String rootName)
 67  
     {
 68  0
         setPersistentRoot(rootName, null);
 69  0
     }
 70  
 
 71  
     public void beginTransaction()
 72  
     {
 73  0
         log.info("beginTransaction");
 74  0
         PersistentContext context = PersistentContext.get(versionMgr);
 75  0
         if (context.isInTransaction())
 76  
         {
 77  0
             throw new PersistenceRuntimeException("Nested transactions not supported");
 78  
         }
 79  
 
 80  0
         advanceVersion();
 81  0
         Transaction transaction = new StandardTransaction();
 82  0
         context.setTransaction(transaction);
 83  0
     }
 84  
 
 85  
     public void endTransaction() throws TransactionAbortedException
 86  
     {
 87  
         // TODO - review failure scenarios
 88  0
         log.info("endTransaction");
 89  0
         PersistentContext context = PersistentContext.get(versionMgr);
 90  0
         Transaction transaction = context.getTransaction();
 91  0
         if (transaction == null)
 92  
         {
 93  0
             throw new PersistenceRuntimeException("endTransaction called when no transaction was active");
 94  
         }
 95  
 
 96  
         try
 97  
         {
 98  0
             transaction.prepareForCommit();
 99  0
             archiver.saveTransaction(transaction);
 100  0
         }
 101  
         catch (ArchiverException e)
 102  
         {
 103  0
             transaction.rollback();
 104  0
             throw new TransactionAbortedException("Unable to archive transaction", e);
 105  
         }
 106  
 
 107  
         // At this point the transaction should be regarded as "successful" and should not fail!
 108  
 
 109  
         // TODO - could possibly get rid of this synchronized block if we do some trickiness with the version updating...
 110  0
         synchronized(this)
 111  
         {
 112  0
             Version newVersion = versionMgr.getNextVersion();
 113  0
             log.debug("Assigned version " + newVersion + " to this transaction");
 114  0
             transaction.commit(newVersion);
 115  
 
 116  
             // Make this new data "visible" to everyone else
 117  0
             versionMgr.setLatestVersion(newVersion);
 118  0
         }
 119  
 
 120  0
         context.setTransaction(null);
 121  0
         advanceVersion();
 122  0
         log.debug("Transaction committed");
 123  0
     }
 124  
 }

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