JDBCSequencer Class

DEPRECATED Use com.bea.p13n.util.jdbc.Sequencer and com.bea.p13n.util.jdbc.SequencerFactory

com.beasys.commerce.util
JDBCSequencer Class

public class JDBCSequencer

    extends Object
    implements 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:

Note:JDBSequencer must run in WebLogic because it must suspend the current transaction when allocating a new block of sequence numbers.

Related Topics

Sequencer
SequencerFactory


Hierarchy
Object
  JDBCSequencer
All Implemented Interfaces

com.beasys.commerce.util.Sequencer

Field Summary

public static final long
DEFAULT_CACHE_SIZE
long
public static final String
DEFAULT_SEQUENCE_NAME
String
public static final String
DEFAULT_SEQUENCER_DATASOURCE_NAME
String
public static final String
DEFAULT_SEQUENCER_NAME
String
public static final long
DEFAULT_STEP_SIZE
long
public static final String
SEQUENCE_LOCK_IDENTIFIER
String
public static final String
SEQUENCE_NAME_IDENTIFIER
String
public static final String
SEQUENCE_VALUE_IDENTIFIER
String
public static final String
SEQUENCER_DATASOURCE_NAME_PROPERTY
String
public static final String
SEQUENCER_MAX_RETRY_PROPERTY
String
 

Constructor Summary

JDBCSequencer()

Default constructor.
JDBCSequencer(String sequencerName, String sequenceName, long cacheSize, long stepSize)

Creates a new JDBCSequencer with the supplied sequencer name, managed sequence name, cache size, and step size.
JDBCSequencer(String sequencerName, String sequenceName, long cacheSize)

Creates a new JDBCSequencer with the supplied sequencer name, managed sequence name, and cache size.
JDBCSequencer(String sequencerName, String sequenceName)

Creates a new JDBCSequencer with the supplied sequencer name and managed sequence name.
 

Method Summary

protected final void
allocateSequenceBlock()
Allocates a new block of sequence numbers from the database.
protected final void
cleanUpResources()
Closes any open DB resources.
public long
getCacheSize()
Returns the cache size.
public long
getCurrent(Connection databaseConnection)
Gets the current sequence number associated with this sequencer.
public long
getCurrent()
Gets the current sequence number associated with this sequencer.
public long
getIncrementAmount()
Returns the increment amount.
public long
getNext(Connection databaseConnection)
Gets the next sequence number using the supplied database connection.
public long
getNext()
Gets the next sequence number.
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.
public void
setCacheSize(long cacheSize)
Sets the cache size.
public void
setIncrementAmount(long incrementAmount)
Sets the increment amount.
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.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   
Methods from interface com.beasys.commerce.util.com.beasys.commerce.util.Sequencer
getCacheSize, getCurrent, getIncrementAmount, getNext, getSequenceName, getSequencerName, getStepSize, setCacheSize, setIncrementAmount, setSequenceName, setSequencerName, setStepSize
 

Field Detail

DEFAULT_CACHE_SIZE

public static final long DEFAULT_CACHE_SIZE


DEFAULT_SEQUENCE_NAME

public static final String DEFAULT_SEQUENCE_NAME


DEFAULT_SEQUENCER_DATASOURCE_NAME

public static final String DEFAULT_SEQUENCER_DATASOURCE_NAME


DEFAULT_SEQUENCER_NAME

public static final String DEFAULT_SEQUENCER_NAME


DEFAULT_STEP_SIZE

public static final long DEFAULT_STEP_SIZE


SEQUENCE_LOCK_IDENTIFIER

public static final String SEQUENCE_LOCK_IDENTIFIER


SEQUENCE_NAME_IDENTIFIER

public static final String SEQUENCE_NAME_IDENTIFIER


SEQUENCE_VALUE_IDENTIFIER

public static final String SEQUENCE_VALUE_IDENTIFIER


SEQUENCER_DATASOURCE_NAME_PROPERTY

public static final String SEQUENCER_DATASOURCE_NAME_PROPERTY


SEQUENCER_MAX_RETRY_PROPERTY

public static final String SEQUENCER_MAX_RETRY_PROPERTY

 

Constructor Detail

JDBCSequencer

public JDBCSequencer()
Default constructor.

JDBCSequencer

public JDBCSequencer(String sequencerName, 
                     String sequenceName, 
                     long cacheSize, 
                     long stepSize)
Creates a new JDBCSequencer with the supplied sequencer name, managed sequence name, cache size, and step size.

JDBCSequencer

public JDBCSequencer(String sequencerName, 
                     String sequenceName, 
                     long cacheSize)
Creates a new JDBCSequencer with the supplied sequencer name, managed sequence name, and cache size.

JDBCSequencer

public JDBCSequencer(String sequencerName, 
                     String sequenceName)
Creates a new JDBCSequencer with the supplied sequencer name and managed sequence name.
 

Method Detail

allocateSequenceBlock() Method

protected final void allocateSequenceBlock()
throws SQLException
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.

Exceptions

SQLException

cleanUpResources() Method

protected final void cleanUpResources()
Closes any open DB resources.


getCacheSize() Method

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.

Returns

The cache size.

getCurrent(Connection) Method

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(Connection databaseConnection)
throws SQLException
Gets the current sequence number associated with this sequencer.

Parameters

databaseConnection
The database connection used to generate the next sequence number.

Exceptions

SQLException

getCurrent() Method

public long getCurrent()
throws SQLException
Gets the current sequence number associated with this sequencer.

Exceptions

SQLException

getIncrementAmount() Method

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.

Returns

The increment amount.

Related Topics

JDBCSequencer.getCacheSize()


getNext(Connection) Method

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(Connection databaseConnection)
throws SQLException
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.

Parameters

databaseConnection
The database connection used to generate the next sequence number.

Exceptions

SQLException

getNext() Method

public long getNext()
throws SQLException
Gets the next sequence number. A new block of sequence numbers is allocated if the cache of numbers is exhausted.

Returns

the next sequence number

Exceptions

SQLException

getSequenceName() Method

public String getSequenceName()
Returns the name of the sequence that is managed by this sequencer.

Returns

The sequence name.

getSequencerName() Method

public String getSequencerName()
Returns the name of this sequencer.

Returns

The sequencer name.

getStepSize() Method

public long getStepSize()
Returns the step size. The step size determines the difference between the values returned from successive calls to getNext().

Returns

The step size.

setCacheSize(long) Method

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.

Parameters

cacheSize
The cache size.

setIncrementAmount(long) Method

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.

Parameters

incrementAmount
The increment amount.

Related Topics

JDBCSequencer.setCacheSize(long)


setSequenceName(String) Method

public void setSequenceName(String sequenceName)
Sets the name of the sequence that is managed by this sequencer.

Parameters

sequenceName
The new sequence name.

setSequencerName(String) Method

public void setSequencerName(String sequencerName)
Sets the name of this sequencer.

Parameters

sequencerName
The new sequencer name.

setStepSize(long) Method

public void setStepSize(long stepSize)
Sets the step size. The step size determines the difference between the values returned from successive calls to getNext().

Parameters

stepSize
The step size.