public abstract class AbstractJdbcSequenceNumberService extends JdbcService
The default database schema is assumed to be
CREATE TABLE SEQUENCES (ID VARCHAR(255) NOT NULL, SEQ_NUMBER INT)
The default SQL statements reflect this; and provided that a table called 'SEQUENCES' contains at least those two columns
then it should work without any changes to the SQL statements. Be aware that all statements default to upper-case which will have
an impact if your database is case-sensitive (such as MySQL on Linux).
Concrete implementations of this simply have to derive the appropriate 'id' from the AdaptrisMessage; everything else is done in this class.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractJdbcSequenceNumberService.OverflowBehaviour
The behaviour of the sequence number generator when the number exceeds that specified by the number format.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_INSERT_STATEMENT |
static java.lang.String |
DEFAULT_RESET_STATEMENT |
static java.lang.String |
DEFAULT_SELECT_STATEMENT |
static java.lang.String |
DEFAULT_UPDATE_STATEMENT |
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
AbstractJdbcSequenceNumberService() |
Modifier and Type | Method and Description |
---|---|
protected void |
closeJdbcService()
Close the service.
|
void |
doService(AdaptrisMessage msg)
Apply the service to the message.
|
protected boolean |
exceedsMaxSequence(int count) |
java.lang.Boolean |
getAlwaysReplaceMetadata() |
java.lang.Boolean |
getCreateDatabase() |
protected abstract java.lang.String |
getIdentity(AdaptrisMessage msg)
Get the appropriate identity from the msg.
|
java.lang.String |
getInsertStatement() |
java.lang.Long |
getMaximumSequenceNumber() |
java.lang.String |
getMetadataKey() |
java.lang.String |
getNumberFormat() |
AbstractJdbcSequenceNumberService.OverflowBehaviour |
getOverflowBehaviour() |
java.lang.String |
getResetStatement() |
java.lang.String |
getSelectStatement() |
java.lang.String |
getUpdateStatement() |
protected boolean |
hasOverflowed(java.lang.String formattedCount) |
protected void |
initJdbcService() |
void |
prepareService() |
void |
setAlwaysReplaceMetadata(java.lang.Boolean t)
Whether or not to always replace the metadata key.
|
void |
setCreateDatabase(java.lang.Boolean b)
Specify whether or not to attempt to create a standard database table if one cannot be found.
|
void |
setInsertStatement(java.lang.String stmt)
Set the insert statement to use when creating a new row in the sequence number table.
|
void |
setMaximumSequenceNumber(java.lang.Long l)
Set the maximum sequence number which will reset the count when reached.
|
void |
setMetadataKey(java.lang.String key)
Set the metadata key where the resulting sequence number will be stored.
|
void |
setNumberFormat(java.lang.String format)
Metadata will be formatted using the pattern specified.
|
void |
setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour s)
Set the behaviour when the sequence number exceeds that specified by the number format.
|
void |
setResetStatement(java.lang.String s)
Set the statement that will be executed to reset the sequence number when the overflow behaviour of
ResetToOne is
triggered. |
void |
setSelectStatement(java.lang.String stmt)
Set the select statement to use when getting a sequence number.
|
void |
setUpdateStatement(java.lang.String stmt)
Set the update statement to be used after extracting the sequence number.
|
protected void |
startService()
Start the service.
|
protected void |
stopService()
Stop the service.
|
applyTimeout, closeService, commit, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, rollback, setConnection, setStatementTimeout, start, stop
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsConfirmation, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isConfirmation, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, rethrowServiceException, retrieveComponentState, setContinueOnFail, setIsConfirmation, setIsTrackingEndpoint, setLookupName, setUniqueId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
continueOnFailure, isBranching, setUniqueId
createName, createQualifier, isConfirmation, isTrackingEndpoint
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
getUniqueId
close, init
getLookupName
public static final java.lang.String DEFAULT_RESET_STATEMENT
public static final java.lang.String DEFAULT_UPDATE_STATEMENT
public static final java.lang.String DEFAULT_INSERT_STATEMENT
public static final java.lang.String DEFAULT_SELECT_STATEMENT
protected void initJdbcService() throws CoreException
initJdbcService
in class JdbcService
CoreException
protected void startService() throws CoreException
JdbcService
This is called after the connection is started
startService
in class JdbcService
CoreException
protected void stopService()
JdbcService
This is called after before the connection is stopped
stopService
in class JdbcService
protected void closeJdbcService()
JdbcService
This is called before the connection is closed
closeJdbcService
in class JdbcService
public void doService(AdaptrisMessage msg) throws ServiceException
Service
Apply the service to the message.
msg
- the AdaptrisMessage
to processServiceException
- wrapping any underlying Exception
sService.doService(com.adaptris.core.AdaptrisMessage)
protected abstract java.lang.String getIdentity(AdaptrisMessage msg) throws ServiceException
For sequence numbers, the identity returned here will be used as a substitution for an SQL statement.
msg
- the message currently being processedServiceException
- wrapping any exception.protected boolean hasOverflowed(java.lang.String formattedCount)
protected boolean exceedsMaxSequence(int count)
public java.lang.String getSelectStatement()
public void setSelectStatement(java.lang.String stmt)
stmt
- the update statement to set, default if not specified is "SELECT SEQ_NUMBER from SEQUENCES where ID=?"public java.lang.String getInsertStatement()
public void setInsertStatement(java.lang.String stmt)
This statement is only executed if the configured select statement returns no rows.
stmt
- the update statement to set, default if not specified is "INSERT INTO SEQUENCES (ID, SEQ_NUMBER) VALUES (?, 2)"public java.lang.String getUpdateStatement()
public void setUpdateStatement(java.lang.String stmt)
stmt
- the update statement to set, default if not specified is "UPDATE SEQUENCES SET SEQ_NUMBER = SEQ_NUMBER+1 WHERE ID=?"public java.lang.String getMetadataKey()
public void setMetadataKey(java.lang.String key)
key
- the metadataKey to setpublic java.lang.String getNumberFormat()
public void setNumberFormat(java.lang.String format)
This allows you to format the number precisely to the value that is required; e.g if you use "000000000" then the metadata value is always 9 characters long, the number being prefixed by leading zeros
format
- the numberFormat to set, you must set this otherwise the service will not initialise. If you use '0' with an
overflow behaviour of 'Continue' then this will just use the raw number.DecimalFormat
public java.lang.Boolean getAlwaysReplaceMetadata()
public void setAlwaysReplaceMetadata(java.lang.Boolean t)
t
- the alwaysReplaceMetadata to set, default is true.public java.lang.String getResetStatement()
public void setResetStatement(java.lang.String s)
ResetToOne
is
triggered.s
- the resetStatement to set, default if not specified is "UPDATE SEQUENCES SET SEQ_NUMBER = ? WHERE ID = ?"public AbstractJdbcSequenceNumberService.OverflowBehaviour getOverflowBehaviour()
public void setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour s)
s
- the behaviour to set (default is AbstractJdbcSequenceNumberService.OverflowBehaviour.Continue
)AbstractJdbcSequenceNumberService.OverflowBehaviour
public java.lang.Long getMaximumSequenceNumber()
public void setMaximumSequenceNumber(java.lang.Long l)
l
- the maximum sequence number, a value of null means there is no maximum (default).public java.lang.Boolean getCreateDatabase()
public void setCreateDatabase(java.lang.Boolean b)
By specifying this to be true, then you are implicitly accepting the default statements for update/insert/reset/select as you will not be able to modify the create statement itself. The update/insert/reset/select statements will be reset back to their defaults regardless of your configuration if the database had to be created.
You would use this in the event that you wanted to maintain sequence numbers and wanted a hands-off configuration of a derby (or similar) database.
b
- true to create the database; default is false.public void prepareService() throws CoreException
prepareService
in class JdbcService
CoreException