Coverage report

  %line %branch
mnemosyne.core.PersistentContext
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 org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 
 22  
 /**
 23  
  * The persistent context is a thread local that holds information about
 24  
  * the transactional state of the current thread.
 25  
  *
 26  
  * Method in this class are protected (they are only called from within the core
 27  
  * package) to prevent direct manipulation of transactions and versions.
 28  
  *
 29  
  * @version $Id: PersistentContext.java,v 1.1.1.1 2004/08/07 06:41:05 charlesblaxland Exp $
 30  
  * @see java.lang.ThreadLocal
 31  
  */
 32  
 public class PersistentContext
 33  
 {
 34  8
     private static Log log = LogFactory.getLog(PersistentContext.class);
 35  
 
 36  4
     private static ThreadLocal thePersistentContext = new ThreadLocal();
 37  
 
 38  
     private Version version;
 39  
     private Transaction transaction;
 40  
 
 41  
     protected PersistentContext(Version currentVersion)
 42  25
     {
 43  25
         this.version = currentVersion;
 44  25
     }
 45  
 
 46  
     public Version getVersion()
 47  
     {
 48  43
         return version;
 49  
     }
 50  
 
 51  
     public void setVersion(final Version version)
 52  
     {
 53  15
         if (log.isDebugEnabled())
 54  0
             log.debug("Setting thead persistent graph version version to " + version);
 55  
 
 56  15
         this.version = version;
 57  15
     }
 58  
 
 59  
     public Transaction getTransaction()
 60  
     {
 61  25
         return transaction;
 62  
     }
 63  
 
 64  
     public boolean isInTransaction()
 65  
     {
 66  43
         return transaction != null;
 67  
     }
 68  
 
 69  
     public void setTransaction(Transaction currentTransaction)
 70  
     {
 71  26
         this.transaction = currentTransaction;
 72  26
     }
 73  
 
 74  
     public final static PersistentContext get(class="keyword">final VersionManager versionMgr)
 75  
     {
 76  
         // TODO support multiple persistent systems
 77  91
         Object context = thePersistentContext.get();
 78  91
         if (context == null)
 79  
         {
 80  3
             context = new PersistentContext(versionMgr.getLatestVersion());
 81  3
             thePersistentContext.set(context);
 82  
         }
 83  
 
 84  91
         return (PersistentContext) context;
 85  
     }
 86  
 
 87  
     public final static PersistentContext reset(class="keyword">final VersionManager versionMgr)
 88  
     {
 89  22
         PersistentContext context = new PersistentContext(versionMgr.getLatestVersion());
 90  22
         thePersistentContext.set(context);
 91  22
         return context;
 92  
     }
 93  
 }

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