Expresso 5-6

com.jcorporate.expresso.core.dbobj
Class NextNumberImpl

java.lang.Object
  extended bycom.jcorporate.expresso.core.dbobj.NextNumber
      extended bycom.jcorporate.expresso.core.dbobj.NextNumberImpl

public class NextNumberImpl
extends NextNumber

this class is a SOLITAIRE, used in NextNumber

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

Modify by Yves Henri AMAIZO

See Also:
NextNumber - Manages in-memory, database independent autoincrement values. This version is not cluster safe. See Expresso Enterprise for a cluster-safe version.

Field Summary
protected  EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap contextMap
          Top level hashMap - This level separates the db contexts.
 
Fields inherited from class com.jcorporate.expresso.core.dbobj.NextNumber
CHECK_PARAMETERS, DEFAULT_CLASS_HANDLER, log, theInstance
 
Constructor Summary
NextNumberImpl()
          Create the base level hashes for each db key.
 
Method Summary
protected  void checkParams(String db, DBObject callingObject, String fieldName)
          All parameters are fully checked to avoid potential NullPointerExceptions
 long getNext(String db, DBObject callingDBObject, String fieldName)
          Get the nextnumber for this dbobject.
 void initialize(String db, DBObject callingObject)
          Initializes hash entries for all auto-inc fields in a particular DBOBject.
 void registerField(String db, DBObject callingDBOBject, String fieldName)
          Register a field for next number information.
 void reset(String db)
          Reset the counts for the paritcular db each subsequent operation will require a new getMax().
 void reset(String db, DBObject callingObject)
          Clears the table on a particular dbobject.
 
Methods inherited from class com.jcorporate.expresso.core.dbobj.NextNumber
destroy, getInstance, getKey, getMax
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contextMap

protected volatile EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap contextMap
Top level hashMap - This level separates the db contexts. The object returned by a get() is another Map() containing lists of dbobject fields. The key is DBObject.getTargetTable() + "." + DBField.getFieldName() this will return the Integer object that will be the number is internally incremented,

Constructor Detail

NextNumberImpl

public NextNumberImpl()
Create the base level hashes for each db key.

Method Detail

initialize

public void initialize(String db,
                       DBObject callingObject)
                throws DBException
Initializes hash entries for all auto-inc fields in a particular DBOBject. This is called the first time that a particular DBObject has a nextnumber called for any field. this method should be synchronized externally.

Parameters:
db - The db to hook this nextnumber object to.
callingObject - the object to initialize from.
Throws:
DBException

registerField

public void registerField(String db,
                          DBObject callingDBOBject,
                          String fieldName)
                   throws DBException
Register a field for next number information.

Specified by:
registerField in class NextNumber
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

checkParams

protected void checkParams(String db,
                           DBObject callingObject,
                           String fieldName)
                    throws DBException
All parameters are fully checked to avoid potential NullPointerExceptions

Parameters:
db - The context to get this out of.
callingObject - - the DBObject that this nextnumber object belongs to.
fieldName - - the field name within the callingObject that this nextnumber belongs to.
Throws:
DBException

getNext

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

Specified by:
getNext in class NextNumber
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 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.

Specified by:
reset in class NextNumber
Parameters:
db - the db context to clear all the next number values for.

reset

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

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

Expresso 5-6

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