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

java.lang.Object
  extended by org.apache.ojb.broker.util.sequence.SequenceManagerHelper

public class SequenceManagerHelper
extends java.lang.Object

Helper class for SequenceManager implementations.

Version:
$Id: SequenceManagerHelper.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
Armin Waibel

Field Summary
static java.lang.String PROP_SEQ_AS
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_CACHE
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_CYCLE
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_INCREMENT_BY
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_MAX_VALUE
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_MIN_VALUE
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_ORDER
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_START
          Property name used to configure sequence manager implementations.
static java.lang.String PROP_SEQ_START_OLD
          Deprecated. use PROP_SEQ_START instead.
 
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.
static java.lang.String getSeqAsValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Long getSeqCacheValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Boolean getSeqCycleValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Long getSeqIncrementBy(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Long getSeqMaxValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Long getSeqMinValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Boolean getSeqOrderValue(java.util.Properties prop)
          Database sequence properties helper method.
static java.lang.Long getSeqStart(java.util.Properties prop)
          Database sequence properties helper method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SEQ_AS

public static final java.lang.String PROP_SEQ_AS
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_START_OLD

public static final java.lang.String PROP_SEQ_START_OLD
Deprecated. use PROP_SEQ_START instead.
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_START

public static final java.lang.String PROP_SEQ_START
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_INCREMENT_BY

public static final java.lang.String PROP_SEQ_INCREMENT_BY
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_MAX_VALUE

public static final java.lang.String PROP_SEQ_MAX_VALUE
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_MIN_VALUE

public static final java.lang.String PROP_SEQ_MIN_VALUE
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_CYCLE

public static final java.lang.String PROP_SEQ_CYCLE
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_CACHE

public static final java.lang.String PROP_SEQ_CACHE
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values

PROP_SEQ_ORDER

public static final java.lang.String PROP_SEQ_ORDER
Property name used to configure sequence manager implementations.

See Also:
Constant Field Values
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

getSeqStart

public static java.lang.Long getSeqStart(java.util.Properties prop)
Database sequence properties helper method. Return sequence start value or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqIncrementBy

public static java.lang.Long getSeqIncrementBy(java.util.Properties prop)
Database sequence properties helper method. Return sequence increment by value or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqMaxValue

public static java.lang.Long getSeqMaxValue(java.util.Properties prop)
Database sequence properties helper method. Return sequence max value or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqMinValue

public static java.lang.Long getSeqMinValue(java.util.Properties prop)
Database sequence properties helper method. Return sequence min value or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqCacheValue

public static java.lang.Long getSeqCacheValue(java.util.Properties prop)
Database sequence properties helper method. Return sequence cache value or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqCycleValue

public static java.lang.Boolean getSeqCycleValue(java.util.Properties prop)
Database sequence properties helper method. Return sequence cycle Booelan or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqOrderValue

public static java.lang.Boolean getSeqOrderValue(java.util.Properties prop)
Database sequence properties helper method. Return sequence order Booelan or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.

getSeqAsValue

public static java.lang.String getSeqAsValue(java.util.Properties prop)
Database sequence properties helper method. Return the datatype to set for the sequence or null if not set.

Parameters:
prop - The Properties instance to use.
Returns:
The found expression or null.


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30