DEPRECATED Use com.bea.p13n.util.jdbc.Sequencer
and
com.bea.p13n.util.jdbc.SequencerFactory
Object
com.beasys.commerce.util.Sequencer
The JDBCSequencer class is a portable implementation for generating unique sequence numbers. JDBCSequencer uses a caching strategy where a block of sequence numbers is allocated in memory. When the block of sequence numbers is exhausted, JDBCSequencer obtains a new range of sequence numbers from the database. This approach has the advantage of minimizing the database access but it can create sequence numbers to be skipped if the server is restarted.
This implementation uses the WLCS_SEQUENCER table to maintain the current values of the different sequences. Each sequence is represented by a row in the WLCS_SEQUENCER and a row is automatically inserted for a sequence that does not exists already.
When allocating a new block of sequence numbers, JDBCSequencer uses a retry loop for obtaining an application lock (IS_LOCKED column in WLCS_SEQUENCER) before incrementing the current value of a sequence. Two properties can be defined in the weblogiccommerce.properties file to control the number of retries and the datasource name to use for obtaining a database connection:
commerce.jdbcSequencer.maxRetry
default value is 5 (1 second wait each retry)
commerce.jdbcSequencer.dataSource.name
default value is "weblogic.jdbc.jts.commercePool"
Related Topics
Object
JDBCSequencer
com.beasys.commerce.util.Sequencer
Field Summary |
public static final long |
|
public static final |
|
public static final | |
public static final |
|
public static final long |
|
public static final |
|
public static final |
|
public static final |
|
public static final | |
public static final |
|
Constructor Summary |
|
|
|
|
Method Summary |
protected final void |
|
protected final void |
|
public long |
|
public long |
|
public long |
|
public long |
|
public long |
|
public long |
|
public |
|
public |
|
public long |
|
public void |
|
public void |
|
public void |
|
public void |
|
public void |
|
Methods from class java.lang. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods from interface com.beasys.commerce.util. |
|
Field Detail |
public static final long DEFAULT_CACHE_SIZE
public static final String
DEFAULT_SEQUENCE_NAME
public static final String
DEFAULT_SEQUENCER_DATASOURCE_NAME
public static final String
DEFAULT_SEQUENCER_NAME
public static final long DEFAULT_STEP_SIZE
public static final String
SEQUENCE_LOCK_IDENTIFIER
public static final String
SEQUENCE_NAME_IDENTIFIER
public static final String
SEQUENCE_VALUE_IDENTIFIER
public static final String
SEQUENCER_DATASOURCE_NAME_PROPERTY
public static final String
SEQUENCER_MAX_RETRY_PROPERTY
Constructor Detail |
public JDBCSequencer()
public JDBCSequencer(String
sequencerName,String
sequenceName, long cacheSize, long stepSize)
JDBCSequencer
with the supplied sequencer name,
managed sequence name, cache size, and step size.public JDBCSequencer(String
sequencerName,String
sequenceName, long cacheSize)
JDBCSequencer
with the supplied sequencer name,
managed sequence name, and cache size.public JDBCSequencer(String
sequencerName,String
sequenceName)
JDBCSequencer
with the supplied sequencer name
and managed sequence name.
Method Detail |
protected final void allocateSequenceBlock()Allocates a new block of sequence numbers from the database. If a transaction is in progress, it is suspended during the database updates required for incrementing the current value of the sequence and resumed after.
throwsSQLException
SQLException
protected final void cleanUpResources()Closes any open DB resources.
public long getCacheSize()Returns the cache size. The cache size defines how often the sequencer will allocate a block of unique sequence numbers from the database. When the sequencer exhausts its supplied of allocated numbers, it will allocate a new sequence of numbers from the database.
DEPRECATED JDBCSequencer must allocate the sequence block using a separate
transaction because the database updates can be undone if a rollback
occurs on the passed connection. Replaced by com.beasys.commerce.util.JDBCSequencer.getNext()
public long getCurrent(Gets the current sequence number associated with this sequencer.Connection
databaseConnection)
throwsSQLException
SQLException
public long getCurrent()Gets the current sequence number associated with this sequencer.
throwsSQLException
SQLException
DEPRECATED Replaced by getCacheSize
public long getIncrementAmount()Returns the increment amount. The increment amount defines how often the sequencer will allocate a block of unique sequence numbers from the database. When the sequencer exhausts its supplied of allocated numbers, it will allocate a new sequence of numbers from the database.
Related Topics
DEPRECATED JDBCSequencer must allocate the sequence block using a separate
transaction because the database updates can be undone if a rollback
occurs on the passed connection. Replaced by com.beasys.commerce.util.JDBCSequencer.getNext()
public long getNext(Gets the next sequence number using the supplied database connection. The database connection will not be automatically closed upon method return. This class is thread safe.Connection
databaseConnection)
throwsSQLException
SQLException
public long getNext()Gets the next sequence number. A new block of sequence numbers is allocated if the cache of numbers is exhausted.
throwsSQLException
SQLException
public String
getSequenceName()
Returns the name of the sequence that is managed by this sequencer.
public String
getSequencerName()
Returns the name of this sequencer.
public long getStepSize()Returns the step size. The step size determines the difference between the values returned from successive calls to
getNext()
.
public void setCacheSize(long cacheSize)Sets the cache size. The cache size defines how often the sequencer will allocate a block of unique sequence numbers from the database. When the sequencer exhausts its supplied of allocated numbers, it will allocate a new sequence of numbers from the database.
DEPRECATED Replaced by setCacheSize
public void setIncrementAmount(long incrementAmount)Sets the increment amount. The increment amount defines how often the sequencer will allocate a block of unique sequence numbers from the database. When the sequencer exhausts its supplied of allocated numbers, it will allocate a new sequence of numbers from the database.
Related Topics
JDBCSequencer.setCacheSize(long)
public void setSequenceName(String
sequenceName)
Sets the name of the sequence that is managed by this sequencer.
public void setSequencerName(String
sequencerName)
Sets the name of this sequencer.
public void setStepSize(long stepSize)Sets the step size. The step size determines the difference between the values returned from successive calls to
getNext()
.