Coverage Report - org.apache.ojb.broker.util.sequence.SequenceManagerTransientImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
SequenceManagerTransientImpl
N/A
N/A
1
 
 1  
 package org.apache.ojb.broker.util.sequence;
 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.broker.PersistenceBroker;
 19  
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 20  
 
 21  
 /**
 22  
  * For internal use only!
 23  
  * This class is used to create transient primary key values for transient 
 24  
  * {@link org.apache.ojb.broker.Identity} objects.
 25  
  *
 26  
  * @version $Id: SequenceManagerTransientImpl.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
 27  
  */
 28  
 public class SequenceManagerTransientImpl extends AbstractSequenceManager
 29  
 {
 30  
     /*
 31  
      Use keyword 'volatile' to make decrement of a long value an
 32  
      atomic operation
 33  
      */
 34  
     private static volatile long tempKey = 1000;
 35  
 
 36  
     public SequenceManagerTransientImpl(PersistenceBroker broker)
 37  
     {
 38  
         super(broker);
 39  
     }
 40  
 
 41  
     protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
 42  
     {
 43  
         /*
 44  
         arminw:
 45  
         We need unique 'dummy keys' for new objects before storing.
 46  
         Variable 'tempKey' is declared volatile, thus increment should be atomic
 47  
         */
 48  
         return ++tempKey;
 49  
     }
 50  
     
 51  
         /*
 52  
          * abyrne: KULRNE-4545 when the maintenance framework triggers a refresh
 53  
          * of references on a new bank account, and ojb goes to retrieve the bank, it uses this class
 54  
          * to initialize any null keys on bank account with a unique value.  however, after setting
 55  
          * the bank account to a number > 1000, it calls the sqlToJava method on the field converter.
 56  
          * bank account number is an encrypted field, and the field converter complains because the value passed in
 57  
          * is not encrypted.  so, we removing the field conversion call, which should not impact uniqueness
 58  
          * or anything else since the unique long did not come from the db in this case
 59  
          */
 60  
     /**
 61  
      * Returns a unique object for the given field attribute.
 62  
      * The returned value takes in account the jdbc-type
 63  
      * and the FieldConversion.sql2java() conversion defined for <code>field</code>.
 64  
      * The returned object is unique accross all tables in the extent
 65  
      * of class the field belongs to.
 66  
      */
 67  
     public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException
 68  
     {
 69  
         return field.getJdbcType().sequenceKeyConversion(new Long(getUniqueLong(field)));
 70  
         // perform a sql to java conversion here, so that clients do
 71  
         // not see any db specific values
 72  
         // abyrne commented out: result = field.getFieldConversion().sqlToJava(result);
 73  
         // abyrne commented out: return result;
 74  
     }
 75  
 }