Class AbstractJdbcSequenceNumberService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.jdbc.JdbcService
-
- com.adaptris.core.services.jdbc.AbstractJdbcSequenceNumberService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,ConnectedService,MessageEventGenerator,Service,StateManagedComponent
- Direct Known Subclasses:
MetadataIdentitySequenceNumberService,StaticIdentitySequenceNumberService
public abstract class AbstractJdbcSequenceNumberService extends JdbcService
Abstract base class for adding sequence numbers into metadata.The default database schema is assumed to be
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).CREATE TABLE SEQUENCES (ID VARCHAR(255) NOT NULL, SEQ_NUMBER INT)Concrete implementations of this simply have to derive the appropriate 'id' from the AdaptrisMessage; everything else is done in this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractJdbcSequenceNumberService.OverflowBehaviourThe behaviour of the sequence number generator when the number exceeds that specified by the number format.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_INSERT_STATEMENTstatic java.lang.StringDEFAULT_RESET_STATEMENTstatic java.lang.StringDEFAULT_SELECT_STATEMENTstatic java.lang.StringDEFAULT_UPDATE_STATEMENT-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description AbstractJdbcSequenceNumberService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcloseJdbcService()Close the service.voiddoService(AdaptrisMessage msg)Apply the service to the message.protected booleanexceedsMaxSequence(int count)java.lang.BooleangetAlwaysReplaceMetadata()java.lang.BooleangetCreateDatabase()protected abstract java.lang.StringgetIdentity(AdaptrisMessage msg)Get the appropriate identity from the msg.java.lang.StringgetInsertStatement()java.lang.LonggetMaximumSequenceNumber()java.lang.StringgetMetadataKey()java.lang.StringgetNumberFormat()AbstractJdbcSequenceNumberService.OverflowBehaviourgetOverflowBehaviour()java.lang.StringgetResetStatement()java.lang.StringgetSelectStatement()java.lang.StringgetUpdateStatement()protected booleanhasOverflowed(java.lang.String formattedCount)protected voidinitJdbcService()voidprepareService()voidsetAlwaysReplaceMetadata(java.lang.Boolean t)Whether or not to always replace the metadata key.voidsetCreateDatabase(java.lang.Boolean b)Specify whether or not to attempt to create a standard database table if one cannot be found.voidsetInsertStatement(java.lang.String stmt)Set the insert statement to use when creating a new row in the sequence number table.voidsetMaximumSequenceNumber(java.lang.Long l)Set the maximum sequence number which will reset the count when reached.voidsetMetadataKey(java.lang.String key)Set the metadata key where the resulting sequence number will be stored.voidsetNumberFormat(java.lang.String format)Metadata will be formatted using the pattern specified.voidsetOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour s)Set the behaviour when the sequence number exceeds that specified by the number format.voidsetResetStatement(java.lang.String s)Set the statement that will be executed to reset the sequence number when the overflow behaviour ofResetToOneis triggered.voidsetSelectStatement(java.lang.String stmt)Set the select statement to use when getting a sequence number.voidsetUpdateStatement(java.lang.String stmt)Set the update statement to be used after extracting the sequence number.protected voidstartService()Start the service.protected voidstopService()Stop the service.-
Methods inherited from class com.adaptris.core.jdbc.JdbcService
applyTimeout, closeService, createStatement, getConnection, getConnection, getStatementTimeout, initService, prepare, prepareStatement, prepareStatement, setConnection, setStatementTimeout, start, stop
-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.adaptris.core.AdaptrisComponent
getUniqueId
-
Methods inherited from interface com.adaptris.core.ComponentLifecycle
close, init
-
Methods inherited from interface com.adaptris.core.MessageEventGenerator
createName, createQualifier, isTrackingEndpoint
-
Methods inherited from interface com.adaptris.core.Service
continueOnFailure, isBranching, setUniqueId
-
Methods inherited from interface com.adaptris.core.StateManagedComponent
changeState, requestClose, requestInit, requestStart, requestStop, retrieveComponentState
-
-
-
-
Field Detail
-
DEFAULT_RESET_STATEMENT
public static final java.lang.String DEFAULT_RESET_STATEMENT
- See Also:
- Constant Field Values
-
DEFAULT_UPDATE_STATEMENT
public static final java.lang.String DEFAULT_UPDATE_STATEMENT
- See Also:
- Constant Field Values
-
DEFAULT_INSERT_STATEMENT
public static final java.lang.String DEFAULT_INSERT_STATEMENT
- See Also:
- Constant Field Values
-
DEFAULT_SELECT_STATEMENT
public static final java.lang.String DEFAULT_SELECT_STATEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
initJdbcService
protected void initJdbcService() throws CoreException- Specified by:
initJdbcServicein classJdbcService- Throws:
CoreException
-
startService
protected void startService() throws CoreExceptionDescription copied from class:JdbcServiceStart the service.This is called after the connection is started
- Specified by:
startServicein classJdbcService- Throws:
CoreException
-
stopService
protected void stopService()
Description copied from class:JdbcServiceStop the service.This is called after before the connection is stopped
- Specified by:
stopServicein classJdbcService
-
closeJdbcService
protected void closeJdbcService()
Description copied from class:JdbcServiceClose the service.This is called before the connection is closed
- Specified by:
closeJdbcServicein classJdbcService
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
Description copied from interface:ServiceApply the service to the message.
- Parameters:
msg- theAdaptrisMessageto process- Throws:
ServiceException- wrapping any underlyingExceptions- See Also:
Service.doService(com.adaptris.core.AdaptrisMessage)
-
getIdentity
protected abstract java.lang.String getIdentity(AdaptrisMessage msg) throws ServiceException
Get the appropriate identity from the msg.For sequence numbers, the identity returned here will be used as a substitution for an SQL statement.
- Parameters:
msg- the message currently being processed- Returns:
- the identity to be used as a parameter in the SQL statements, or null if no identity is required.
- Throws:
ServiceException- wrapping any exception.
-
hasOverflowed
protected boolean hasOverflowed(java.lang.String formattedCount)
-
exceedsMaxSequence
protected boolean exceedsMaxSequence(int count)
-
getSelectStatement
public java.lang.String getSelectStatement()
- Returns:
- the selectStatement
-
setSelectStatement
public void setSelectStatement(java.lang.String stmt)
Set the select statement to use when getting a sequence number.- Parameters:
stmt- the update statement to set, default if not specified is "SELECT SEQ_NUMBER from SEQUENCES where ID=?"
-
getInsertStatement
public java.lang.String getInsertStatement()
- Returns:
- the insertStatement
-
setInsertStatement
public void setInsertStatement(java.lang.String stmt)
Set the insert statement to use when creating a new row in the sequence number table.This statement is only executed if the configured select statement returns no rows.
- Parameters:
stmt- the update statement to set, default if not specified is "INSERT INTO SEQUENCES (ID, SEQ_NUMBER) VALUES (?, 2)"
-
getUpdateStatement
public java.lang.String getUpdateStatement()
- Returns:
- the updateStatement
-
setUpdateStatement
public void setUpdateStatement(java.lang.String stmt)
Set the update statement to be used after extracting the sequence number.- Parameters:
stmt- the update statement to set, default if not specified is "UPDATE SEQUENCES SET SEQ_NUMBER = SEQ_NUMBER+1 WHERE ID=?"
-
getMetadataKey
public java.lang.String getMetadataKey()
- Returns:
- the metadataKey
-
setMetadataKey
public void setMetadataKey(java.lang.String key)
Set the metadata key where the resulting sequence number will be stored.- Parameters:
key- the metadataKey to set
-
getNumberFormat
public java.lang.String getNumberFormat()
- Returns:
- the numberFormat
-
setNumberFormat
public void setNumberFormat(java.lang.String format)
Metadata will be formatted using the pattern specified.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
- Parameters:
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.- See Also:
DecimalFormat
-
getAlwaysReplaceMetadata
public java.lang.Boolean getAlwaysReplaceMetadata()
- Returns:
- the alwaysReplaceMetadata
-
setAlwaysReplaceMetadata
public void setAlwaysReplaceMetadata(java.lang.Boolean t)
Whether or not to always replace the metadata key.- Parameters:
t- the alwaysReplaceMetadata to set, default is true.
-
getResetStatement
public java.lang.String getResetStatement()
- Returns:
- the resetStatement
-
setResetStatement
public void setResetStatement(java.lang.String s)
Set the statement that will be executed to reset the sequence number when the overflow behaviour ofResetToOneis triggered.- Parameters:
s- the resetStatement to set, default if not specified is "UPDATE SEQUENCES SET SEQ_NUMBER = ? WHERE ID = ?"
-
getOverflowBehaviour
public AbstractJdbcSequenceNumberService.OverflowBehaviour getOverflowBehaviour()
- Returns:
- the wrapBehaviour
-
setOverflowBehaviour
public void setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour s)
Set the behaviour when the sequence number exceeds that specified by the number format.- Parameters:
s- the behaviour to set (default isAbstractJdbcSequenceNumberService.OverflowBehaviour.Continue)- See Also:
AbstractJdbcSequenceNumberService.OverflowBehaviour
-
getMaximumSequenceNumber
public java.lang.Long getMaximumSequenceNumber()
-
setMaximumSequenceNumber
public void setMaximumSequenceNumber(java.lang.Long l)
Set the maximum sequence number which will reset the count when reached.- Parameters:
l- the maximum sequence number, a value of null means there is no maximum (default).
-
getCreateDatabase
public java.lang.Boolean getCreateDatabase()
-
setCreateDatabase
public void setCreateDatabase(java.lang.Boolean b)
Specify whether or not to attempt to create a standard database table if one cannot be found.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.
- Parameters:
b- true to create the database; default is false.
-
prepareService
public void prepareService() throws CoreException- Specified by:
prepareServicein classJdbcService- Throws:
CoreException
-
-