public final class SequentialIdGenerator extends Object
| Key | Value |
|---|---|
| dataSourceName | Name of the non-transaction aware data source |
| txDataSourceName | Name of the transaction aware data source |
| tableName | Name of the table used to store sequence IDs |
| sequenceColumnName | Name of the column that stores the name of the sequence |
| currentIDColumnName | Name of the column that stores the current value of the sequence |
| Modifier and Type | Method and Description |
|---|---|
long |
fetchNextSequentialID(String sequenceName)
Fetches the current sequence id for the supplied sequenceName, increments it and stores it in the database.
|
long |
fetchNextSequentialID(String sequenceName,
int numberOfIds)
Fetches the current sequence id for the supplied sequenceName, increments it by the supplied numberOfIds and stores it
in the database.
|
static SequentialIdGenerator |
getInstance(boolean useTransaction)
Simply returns one of two (transaction aware or not) sequential ID generator objects.
|
public static SequentialIdGenerator getInstance(boolean useTransaction) throws NamingException
useTransaction - Supply true to construct a transaction aware generator, otherwise supply false.
ObjectIdDispenser is an example of a class that specifies false.
Using false has the advantage of not locking the sequence during the entire transaction.MissingResourceException - When one of the required resources does not exist.
NamingException - When an initial context is not available or when the Transaction capable datasource could not be
looked up.public long fetchNextSequentialID(String sequenceName) throws SequentialIdGeneratorException
sequenceName - Name of the sequence for which the next ID should be fetched.IllegalArgumentException - When the supplied sequenceName is empty.NullPointerException - When the supplied sequenceName is null.SequentialIdGeneratorException - When a database related error occurs.public long fetchNextSequentialID(String sequenceName, int numberOfIds) throws SequentialIdGeneratorException
sequenceName - Name of the sequence for which the next ID should be fetched.numberOfIds - The number of sequential ID's to reserve.IllegalArgumentException - When the supplied sequenceName is empty or when numberOfIds is less than 1.NullPointerException - When the supplied sequenceName is null.SequentialIdGeneratorException - When a database related error occurs.Copyright © 2008–2017. All rights reserved.