Class AbstractJdbcSequenceNumberService

    • 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
    • Constructor Detail

      • AbstractJdbcSequenceNumberService

        public AbstractJdbcSequenceNumberService()
    • Method Detail

      • stopService

        protected void stopService()
        Description copied from class: JdbcService
        Stop the service.

        This is called after before the connection is stopped

        Specified by:
        stopService in class JdbcService
      • closeJdbcService

        protected void closeJdbcService()
        Description copied from class: JdbcService
        Close the service.

        This is called before the connection is closed

        Specified by:
        closeJdbcService in class JdbcService
      • 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
      • 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 of ResetToOne is triggered.
        Parameters:
        s - the resetStatement to set, default if not specified is "UPDATE SEQUENCES SET SEQ_NUMBER = ? WHERE ID = ?"
      • 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.