Class AbstractJdbcMessageIdRepository

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.IdempotentRepository, org.apache.camel.StatefulService, org.apache.camel.SuspendableService
    Direct Known Subclasses:
    JdbcMessageIdRepository

    @ManagedResource(description="JDBC IdempotentRepository")
    public abstract class AbstractJdbcMessageIdRepository
    extends org.apache.camel.support.service.ServiceSupport
    implements org.apache.camel.spi.IdempotentRepository
    Base class for JDBC-based idempotent repositories that allows the schema to be changed.

    Subclasses need only implement theses methods:

    These methods should perform the named database operation.

    Important: Implementations of this should use String as the generic type as that is what is required by Camel to allow using the idempotent repository with the Idempotent Consumer EIP and also as file consumer read-lock. It was a mistake to make IdempotentRepository parameterized, as it should have been a pre-configured to use a String type.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected DataSource dataSource  
      protected org.springframework.jdbc.core.JdbcTemplate jdbcTemplate  
      protected org.slf4j.Logger log  
      protected String processorName  
      protected org.springframework.transaction.support.TransactionTemplate transactionTemplate  
      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(String key)  
      void clear()  
      boolean confirm​(String key)  
      boolean contains​(String key)  
      protected static org.springframework.transaction.support.TransactionTemplate createTransactionTemplate​(DataSource dataSource)
      Creates the transaction template
      protected abstract int delete()
      Operations that deletes all the rows
      protected abstract int delete​(String key)
      Operations that deletes the key if it exists
      protected void doStart()  
      protected void doStop()  
      DataSource getDataSource()  
      org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()  
      String getProcessorName()  
      org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()  
      protected abstract int insert​(String key)
      Operation that inserts the key if it does not already exist
      protected abstract int queryForInt​(String key)
      Operation that returns the number of rows, if any, for the specified key
      boolean remove​(String key)  
      void setDataSource​(DataSource dataSource)  
      void setJdbcTemplate​(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)  
      void setProcessorName​(String processorName)  
      void setTransactionTemplate​(org.springframework.transaction.support.TransactionTemplate transactionTemplate)  
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.spi.IdempotentRepository

        add, confirm, contains, remove
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Field Detail

      • jdbcTemplate

        protected org.springframework.jdbc.core.JdbcTemplate jdbcTemplate
      • processorName

        protected String processorName
      • transactionTemplate

        protected org.springframework.transaction.support.TransactionTemplate transactionTemplate
      • log

        protected org.slf4j.Logger log
    • Constructor Detail

      • AbstractJdbcMessageIdRepository

        public AbstractJdbcMessageIdRepository()
      • AbstractJdbcMessageIdRepository

        public AbstractJdbcMessageIdRepository​(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
                                               org.springframework.transaction.support.TransactionTemplate transactionTemplate)
      • AbstractJdbcMessageIdRepository

        public AbstractJdbcMessageIdRepository​(DataSource dataSource,
                                               org.springframework.transaction.support.TransactionTemplate transactionTemplate,
                                               String processorName)
      • AbstractJdbcMessageIdRepository

        public AbstractJdbcMessageIdRepository​(DataSource dataSource,
                                               String processorName)
    • Method Detail

      • queryForInt

        protected abstract int queryForInt​(String key)
        Operation that returns the number of rows, if any, for the specified key
        Parameters:
        key - the key
        Returns:
        int number of rows
      • insert

        protected abstract int insert​(String key)
        Operation that inserts the key if it does not already exist
        Parameters:
        key - the key
        Returns:
        int number of rows inserted
      • delete

        protected abstract int delete​(String key)
        Operations that deletes the key if it exists
        Parameters:
        key - the key
        Returns:
        int number of rows deleted
      • delete

        protected abstract int delete()
        Operations that deletes all the rows
        Returns:
        int number of rows deleted
      • createTransactionTemplate

        protected static org.springframework.transaction.support.TransactionTemplate createTransactionTemplate​(DataSource dataSource)
        Creates the transaction template
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • add

        @ManagedOperation(description="Adds the key to the store")
        public boolean add​(String key)
        Specified by:
        add in interface org.apache.camel.spi.IdempotentRepository
      • contains

        @ManagedOperation(description="Does the store contain the given key")
        public boolean contains​(String key)
        Specified by:
        contains in interface org.apache.camel.spi.IdempotentRepository
      • remove

        @ManagedOperation(description="Remove the key from the store")
        public boolean remove​(String key)
        Specified by:
        remove in interface org.apache.camel.spi.IdempotentRepository
      • clear

        @ManagedOperation(description="Clear the store")
        public void clear()
        Specified by:
        clear in interface org.apache.camel.spi.IdempotentRepository
      • confirm

        public boolean confirm​(String key)
        Specified by:
        confirm in interface org.apache.camel.spi.IdempotentRepository
      • getJdbcTemplate

        public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
      • setJdbcTemplate

        public void setJdbcTemplate​(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
      • getProcessorName

        public String getProcessorName()
      • setProcessorName

        public void setProcessorName​(String processorName)
      • getTransactionTemplate

        public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
      • setTransactionTemplate

        public void setTransactionTemplate​(org.springframework.transaction.support.TransactionTemplate transactionTemplate)
      • getDataSource

        public DataSource getDataSource()
      • setDataSource

        public void setDataSource​(DataSource dataSource)