org.apache.ojb.broker.util.sequence
Class SequenceManagerHelper

java.lang.Object
  extended byorg.apache.ojb.broker.util.sequence.SequenceManagerHelper

public class SequenceManagerHelper
extends java.lang.Object

Helper class for SequenceManager implementations.

Version:
$Id: SequenceManagerHelper.java,v 1.13 2003/06/15 12:00:03 arminw Exp $
Author:
Armin Waibel

Constructor Summary
SequenceManagerHelper()
           
 
Method Summary
static java.lang.String buildSequenceName(PersistenceBroker brokerForClass, FieldDescriptor field, boolean autoNaming)
          Returns a unique sequence name (unique across all extents).
static long getMaxForExtent(PersistenceBroker brokerForClass, FieldDescriptor field)
          Lookup all tables associated with given class (search all extent classes) to find the current maximum value for the given field.
static long getMaxId(PersistenceBroker brokerForClass, java.lang.Class topLevel, FieldDescriptor original)
          Search down all extent classes and return max of all found PK values.
static long getMaxIdForClass(PersistenceBroker brokerForClass, ClassDescriptor cldForOriginalOrExtent, FieldDescriptor original)
          lookup current maximum value for a single field in table the given class descriptor was associated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceManagerHelper

public SequenceManagerHelper()
Method Detail

buildSequenceName

public static java.lang.String buildSequenceName(PersistenceBroker brokerForClass,
                                                 FieldDescriptor field,
                                                 boolean autoNaming)
                                          throws SequenceManagerException
Returns a unique sequence name (unique across all extents).
If we found a non null value for the 'sequence-name' attribute in the field descriptor, we use the 'sequence-name' value as sequence name.
Else if the top-level class of the target class has extents, we take the first extent class table name of the extents as sequence name.
Else we take the table name of the target class.

If the method argument 'autoNaming' is true, the generated sequence name will be set in the given field descriptor using FieldDescriptor.setSequenceName(java.lang.String) to speed up sequence name lookup in future calls.

Parameters:
brokerForClass - current used PB instance
field - target field
autoNaming - if 'false' no auto sequence name was build and a exception was throw if none could be found in field.
Throws:
SequenceManagerException

getMaxForExtent

public static long getMaxForExtent(PersistenceBroker brokerForClass,
                                   FieldDescriptor field)
                            throws PersistenceBrokerException
Lookup all tables associated with given class (search all extent classes) to find the current maximum value for the given field.
Note: Only works for long autoincrement fields.

Parameters:
brokerForClass - persistence broker instance match the database of the given field/class
field - the target field
Throws:
PersistenceBrokerException

getMaxId

public static long getMaxId(PersistenceBroker brokerForClass,
                            java.lang.Class topLevel,
                            FieldDescriptor original)
                     throws PersistenceBrokerException
Search down all extent classes and return max of all found PK values.

Throws:
PersistenceBrokerException

getMaxIdForClass

public static long getMaxIdForClass(PersistenceBroker brokerForClass,
                                    ClassDescriptor cldForOriginalOrExtent,
                                    FieldDescriptor original)
                             throws PersistenceBrokerException
lookup current maximum value for a single field in table the given class descriptor was associated.

Throws:
PersistenceBrokerException


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14