|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.services.uniqueid.DefaultUniqueIDServiceImpl
Default implementation of UniqueIDService interface. This implementation uses a database to store the next unique id. It uses transactions at the database level to ensure ID uniqueness across a cluster of machines and synchronization to ensure that this component does not return the same ID twice. To decrease database hits, this implementation stores a block of IDs with each database request instead of querying the database for each ID. Copyright 2002 Sapient
Field Summary | |
protected boolean |
autoCreate
Enable/disable autocreate if the id doesnt exist |
protected long |
blockSize
The number of IDs reserved with each database request |
protected ConnectionFactory |
connectionFactory
Connection Factory used for the Select/Update query |
protected String |
createStatementName
Name of of the create statement within statementFactory |
protected long |
currentBlockEnd
End value of the current block (inclusive) |
protected long |
currentBlockStart
Start value of the current block (inclusive) |
protected long |
currentValue
Current value of the ID, returned by the next call to getNextID |
protected String |
idName
UniqueID name used to identify the ID in the database |
protected long |
initialBlockStart
Starting value of the ID used while creating a new id |
private boolean |
isSecondAttemptRequired
This variable is used to ensure that only one attempt is made to retreive a new block of unique id in case of synchronization problem when two threads are trying to create the same unique id name at the same time. |
private org.apache.commons.logging.Log |
log
Provides a handle to Apache-commons logger |
protected boolean |
retrieveNewBlock
Flag that signifies that a new ID block should be retrieved regardless of currentValue and whether it falls outside of the current block. |
protected String |
retrieveStatementName
Name of of the retrieve statement within statementFactory |
protected StatementFactory |
statementFactory
Factory used to get the Statements to query the database |
protected String |
updateStatementName
Name of of the update statement within statementFactory |
Constructor Summary | |
DefaultUniqueIDServiceImpl()
|
Method Summary | |
void |
configure(ComponentConfiguration configuration)
Configure the component. |
protected long |
createUniqueID()
Inserts a new row into the Unique ID holding table with an initial value defined by initialBlockStart which is set from configuration. |
long |
getNextID()
Method is expected to return then next value, if the value is in the current block, otherwise resever a new block. |
protected void |
reserveBlock(long nextBlockStart,
Connection connection)
Reserves a block of IDs by updating the row corresponding to this ID, increasing it by blockSize (configurable). |
protected void |
reserveNewBlock()
Reserves a new block of IDs, creating it if it does not exists and this component is configured to do so. |
protected long |
retrieveBlockStart(Connection connection)
Retrieves the beginning of the next block of IDs. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private org.apache.commons.logging.Log log
protected String idName
protected long blockSize
protected long initialBlockStart
protected long currentBlockStart
protected long currentBlockEnd
protected long currentValue
protected boolean autoCreate
protected StatementFactory statementFactory
protected ConnectionFactory connectionFactory
protected String retrieveStatementName
protected String updateStatementName
protected String createStatementName
protected boolean retrieveNewBlock
private boolean isSecondAttemptRequired
true : indicates only one attempt has been made and second is
required
false : indicates, no more attempts are required, continue the
execution
Constructor Detail |
public DefaultUniqueIDServiceImpl()
Method Detail |
public long getNextID() throws UniqueIDServiceException
getNextID
in interface UniqueIDService
UniqueIDServiceException
- if unable to generate the valuepublic void configure(ComponentConfiguration configuration)
configure
in interface Configurable
configuration
- A UniqueIDServiceConfigurationUniqueIDServiceConfiguration
protected void reserveNewBlock() throws UniqueIDServiceException
UniqueIDServiceException
- indicates an generic errorprotected long retrieveBlockStart(Connection connection) throws UniqueIDNotFoundException, UniqueIDServiceException
connection
- connection used to query the database, explicitly
passed to allow transaction handling
UniqueIDNotFoundException
- indicates the ID is not found
UniqueIDServiceException
- indicates a generic errorprotected void reserveBlock(long nextBlockStart, Connection connection) throws UniqueIDServiceException
nextBlockStart
- the starting value of the next block of IDsconnection
- the connection used to update the database, explicitly
passed to allow transaction handling
UniqueIDServiceException
- indicates an error reserving a blockprotected long createUniqueID() throws UniqueIDCreationException, SQLException
Inserts a new row into the Unique ID holding table with an initial
value defined by initialBlockStart which is set from configuration.
This Unique ID can then be accessed through the normal
reserveBlock
method.
UniqueIDCreationException
- when unable to create the Unique ID
in the table
SQLException
- when unable to insert the row in table
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |