Expresso 5-6

com.jcorporate.expresso.core.dbobj
Class NextNumber

java.lang.Object
  extended bycom.jcorporate.expresso.core.dbobj.NextNumber
Direct Known Subclasses:
NextNumberImpl

public abstract class NextNumber
extends Object

Base class for pluggable next number autoincrementing system.

Since:
$DatabaseSchema $Date: 2004/11/17 20:48:11 $
Author:
Original by Michael Nash, rewritten by Michael Rimov

Modify by Yves Henri AMAIZO

See Also:
for more information

Field Summary
protected static boolean CHECK_PARAMETERS
          Set this to false and recompile to cause NextNumber to not check it's input parameters.
static String DEFAULT_CLASS_HANDLER
           
protected static org.apache.log4j.Logger log
          The lo4j log category.
protected static NextNumber theInstance
          The actual static instance of the Next Number implementation
 
Constructor Summary
protected NextNumber()
          Constructor - Do not call directly.
 
Method Summary
static void destroy()
          Fill in for potential resource removal Should be called by ConfigInit.
static NextNumber getInstance()
          Factory Method returns a constructed instance of the NextNumber Manager.
protected  String getKey(DBObject callingDBObject, String fieldName)
          Builds the key string for lookup within the dbobject hashmap.
protected  long getMax(String db, DBObject callingObject, String oneField)
          Gets the maximum value for a particular object and field Used if there's no value loaded in memory or state.
abstract  long getNext(String db, DBObject callingDBObject, String fieldName)
          Get the nextnumber for this dbobject.
abstract  void registerField(String db, DBObject callingDBObject, String fieldName)
          Register a field for next number information.
abstract  void reset(String db)
          Reset the counts for the paritcular db each subsequent operation will require a new getMax().
abstract  void reset(String db, DBObject callingObject)
          Clears the table on a particular dbobject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CLASS_HANDLER

public static final String DEFAULT_CLASS_HANDLER

CHECK_PARAMETERS

protected static final boolean CHECK_PARAMETERS
Set this to false and recompile to cause NextNumber to not check it's input parameters. May result in NullPointerExceptions if there's bugs in the code. But will result in a speed increase.

See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log
The lo4j log category.


theInstance

protected static NextNumber theInstance
The actual static instance of the Next Number implementation

Constructor Detail

NextNumber

protected NextNumber()
Constructor - Do not call directly. Use getInstance() instead.

Method Detail

getInstance

public static NextNumber getInstance()
                              throws DBException
Factory Method returns a constructed instance of the NextNumber Manager.

Returns:
instantiated NextNumber object
Throws:
DBException

getMax

protected long getMax(String db,
                      DBObject callingObject,
                      String oneField)
               throws DBException
Gets the maximum value for a particular object and field Used if there's no value loaded in memory or state.

Parameters:
db - The dataContext to get for
callingObject - the calling DBObject
oneField - the field name to query
Returns:
long value covering the max used for the field so far
Throws:
DBException

registerField

public abstract void registerField(String db,
                                   DBObject callingDBObject,
                                   String fieldName)
                            throws DBException
Register a field for next number information. This may happen even if it isn't an auto-inc field.

Parameters:
db - The database context to work with.
callingDBObject - The calling database object to register the field for
fieldName - The field name to register into the NextNumber engine
Throws:
DBException

getNext

public abstract long getNext(String db,
                             DBObject callingDBObject,
                             String fieldName)
                      throws DBException
Get the nextnumber for this dbobject. Increments the internal value.

Parameters:
db - The datacontext. MAKE SURE THIS IS CORRECT or else you will get duplicate running counts for each incorrect DB name, and thus Duplicate key errors when trying to write rows.
callingDBObject - The calling DBOBject
fieldName - the name of the field to get the next number value for
Returns:
long integer representing the next number to use for that field
Throws:
DBException

reset

public abstract void reset(String db)
Reset the counts for the paritcular db each subsequent operation will require a new getMax(). There is questionable threadsafety about the reset methods. Please only do it on a "non-live" server. Used after a DBCreate or DeleteSchema has been called.

Parameters:
db - the db context to clear all the next number values for.

reset

public abstract void reset(String db,
                           DBObject callingObject)
Clears the table on a particular dbobject. Similar to reset db, but

Parameters:
db - The db context that the next number resides in.
callingObject - the object that links to the various nextnumber objects

destroy

public static void destroy()

Fill in for potential resource removal Should be called by ConfigInit. destroy() Or by unit tests to reset everything to a pristine state.

Note: Do not call getInstance() to call destroy. Simply use NextNumber.destroy();


getKey

protected String getKey(DBObject callingDBObject,
                        String fieldName)
                 throws DBException
Builds the key string for lookup within the dbobject hashmap.

Parameters:
callingDBObject - the calling DBObject
fieldName - the fieldName to get the key for
Returns:
a string formatted in [callingDBObject].[fieldName]
Throws:
DBException - upon error

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/17 20:48:11 $

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.