public abstract class AbstractHiLoIdGenerator extends Object implements IdGenerator
A Hi-Lo ID generator, which generates IDs in block with a configurable bock size.
Be sure to call initialize()
after setting a valid datasource
via setDataSource(DataSource)
and actually creating your generator
database table.
The code is placed in this abstract class, since some details have to be done in slightly different way when dealing with a Hibernate-controlled database. This means, usually the subclass HiLoIdGenerator should be used. Only when supporting a database Hibernate controls, the other subclass HibernateHiLoIdGenerator should be used, as hibernate stores values divided by the block size in the id table, whereas HiLoIdGenerator stores values without division.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ID_TABLE_NAME |
static String |
DEFAULT_NEXT_ID_COL_NAME |
Constructor and Description |
---|
AbstractHiLoIdGenerator() |
Modifier and Type | Method and Description |
---|---|
protected Long |
fetchNextId(Statement statement) |
Long |
generateNext() |
protected abstract Long |
getBaseId()
Returns the current base id, to which the lo value is added.
|
long |
getBlockSize() |
DataSource |
getDataSource() |
protected abstract Long |
getHiStepSize()
Returns the step size, by which the hi value (as stored in the database) is incremented when a new
block has to be started.
|
Long |
getHiValue()
Getter to the hi value as stored in the corresponding database table, in order to make
it available for test cases.
|
String |
getIdTableName() |
protected abstract Long |
getInitialHiValue()
Returns the very first hi value the generator writes into the database (if none was written before).
|
String |
getNextIdColumnName() |
void |
initialize()
An initialization function, which check the database table for a single row
with the next high value.
|
protected Long |
runInSerializableTransaction(org.clazzes.util.aop.jdbc.JdbcStatementAction<Long> action) |
void |
setBlockSize(long blockSize) |
void |
setDataSource(DataSource dataSource) |
void |
setIdTableName(String idTableName) |
void |
setNextIdColumnName(String nextIdColumnName) |
public static final String DEFAULT_ID_TABLE_NAME
public static final String DEFAULT_NEXT_ID_COL_NAME
protected abstract Long getInitialHiValue()
protected abstract Long getHiStepSize()
protected abstract Long getBaseId()
protected Long runInSerializableTransaction(org.clazzes.util.aop.jdbc.JdbcStatementAction<Long> action) throws SQLException
SQLException
protected Long fetchNextId(Statement statement) throws SQLException
SQLException
public void initialize() throws SQLException
SQLException
public Long generateNext()
generateNext
in interface IdGenerator
public Long getHiValue()
public String getIdTableName()
public void setIdTableName(String idTableName)
idTableName
- THe name of the ID table. The default value
is "ID_GENERATOR"
resp. @see DEFAULT_ID_TABLE_NAME.public String getNextIdColumnName()
public void setNextIdColumnName(String nextIdColumnName)
nextIdColumnName
- The name of the column,
where the next hi value is stored. The default value is
"NEXT_ID"
resp. @see DEFAULT_NEXT_ID_COL_NAMEpublic long getBlockSize()
public void setBlockSize(long blockSize)
blockSize
- The block size to set. The default value is
100
.public DataSource getDataSource()
public void setDataSource(DataSource dataSource)
dataSource
- The datasource use to pull new connections to set.Copyright © 2017 Clazzes.org. All rights reserved.