Coverage Report - org.apache.ojb.odmg.states.StateNewClean
 
Classes in this File Line Coverage Branch Coverage Complexity
StateNewClean
N/A
N/A
1
 
 1  
 package org.apache.ojb.odmg.states;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import org.apache.ojb.odmg.ObjectEnvelope;
 19  
 
 20  
 /**
 21  
  * this state represents new objects which have not been altered during tx.
 22  
  */
 23  
 public class StateNewClean extends ModificationState
 24  
 {
 25  
     private static StateNewClean _instance = new StateNewClean();
 26  
 
 27  
     /**
 28  
      * private constructor: we use singleton instances
 29  
      */
 30  
     private StateNewClean()
 31  
     {
 32  
     }
 33  
 
 34  
     /**
 35  
      * perform a checkpoint, i.e. perform updates on underlying db but keep locks on objects
 36  
      */
 37  
     public static StateNewClean getInstance()
 38  
     {
 39  
         return _instance;
 40  
     }
 41  
 
 42  
     /**
 43  
      * return resulting state after marking clean
 44  
      */
 45  
     public ModificationState markClean()
 46  
     {
 47  
         return this;
 48  
     }
 49  
 
 50  
     /**
 51  
      * return resulting state after marking delete
 52  
      */
 53  
     public ModificationState markDelete()
 54  
     {
 55  
         return StateNewDelete.getInstance();
 56  
     }
 57  
 
 58  
     /**
 59  
      * return resulting state after marking dirty
 60  
      */
 61  
     public ModificationState markDirty()
 62  
     {
 63  
         return StateNewDirty.getInstance();
 64  
     }
 65  
 
 66  
     /**
 67  
      * return resulting state after marking new
 68  
      */
 69  
     public ModificationState markNew()
 70  
     {
 71  
         return this;
 72  
     }
 73  
 
 74  
     /**
 75  
      * return resulting state after marking old
 76  
      */
 77  
     public ModificationState markOld()
 78  
     {
 79  
         return StateOldClean.getInstance();
 80  
     }
 81  
 
 82  
     /**
 83  
      * object is new, thus we need an INSERT to store it
 84  
      */
 85  
     public boolean needsInsert()
 86  
     {
 87  
         return true;
 88  
     }
 89  
 
 90  
     /**
 91  
      * checkpoint the transaction
 92  
      */
 93  
     public void checkpoint(ObjectEnvelope mod)
 94  
             throws org.apache.ojb.broker.PersistenceBrokerException
 95  
     {
 96  
         mod.doInsert();
 97  
         mod.setModificationState(StateOldClean.getInstance());
 98  
     }
 99  
 
 100  
 
 101  
     /**
 102  
      * commit the associated transaction
 103  
      */
 104  
     public void commit(ObjectEnvelope mod) throws org.apache.ojb.broker.PersistenceBrokerException
 105  
     {
 106  
         mod.doInsert();
 107  
         mod.setModificationState(StateOldClean.getInstance());
 108  
     }
 109  
 
 110  
     /**
 111  
      * rollback the transaction
 112  
      */
 113  
     public void rollback(ObjectEnvelope mod)
 114  
     {
 115  
         mod.doEvictFromCache();
 116  
     }
 117  
 }