Class JdbcAggregationRepository

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.AggregationRepository, org.apache.camel.spi.OptimisticLockingAggregationRepository, org.apache.camel.spi.RecoverableAggregationRepository, org.apache.camel.StatefulService, org.apache.camel.SuspendableService
    Direct Known Subclasses:
    ClusteredJdbcAggregationRepository, PostgresAggregationRepository

    public class JdbcAggregationRepository
    extends org.apache.camel.support.service.ServiceSupport
    implements org.apache.camel.spi.RecoverableAggregationRepository, org.apache.camel.spi.OptimisticLockingAggregationRepository
    JDBC based AggregationRepository JdbcAggregationRepository will only preserve any Serializable compatible data types. If a data type is not such a type its dropped and a WARN is logged. And it only persists the Message body and the Message headers. The Exchange properties are not persisted.
    • Field Detail

      • jdbcTemplate

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

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

        protected org.springframework.transaction.support.TransactionTemplate transactionTemplateReadOnly
      • allowSerializedHeaders

        protected boolean allowSerializedHeaders
    • Constructor Detail

      • JdbcAggregationRepository

        public JdbcAggregationRepository()
        Creates an aggregation repository
      • JdbcAggregationRepository

        public JdbcAggregationRepository​(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                         String repositoryName,
                                         DataSource dataSource)
        Creates an aggregation repository with the three mandatory parameters
    • Method Detail

      • setRepositoryName

        public final void setRepositoryName​(String repositoryName)
        Sets the name of the repository
      • setTransactionManager

        public final void setTransactionManager​(org.springframework.transaction.PlatformTransactionManager transactionManager)
      • setDataSource

        public void setDataSource​(DataSource dataSource)
        Sets the DataSource to use for accessing the database
      • add

        public org.apache.camel.Exchange add​(org.apache.camel.CamelContext camelContext,
                                             String correlationId,
                                             org.apache.camel.Exchange oldExchange,
                                             org.apache.camel.Exchange newExchange)
                                      throws org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException
        Specified by:
        add in interface org.apache.camel.spi.OptimisticLockingAggregationRepository
        Throws:
        org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException
      • add

        public org.apache.camel.Exchange add​(org.apache.camel.CamelContext camelContext,
                                             String correlationId,
                                             org.apache.camel.Exchange exchange)
        Specified by:
        add in interface org.apache.camel.spi.AggregationRepository
      • update

        protected void update​(org.apache.camel.CamelContext camelContext,
                              String key,
                              org.apache.camel.Exchange exchange,
                              String repositoryName,
                              Long version)
                       throws Exception
        Updates the current exchange details in the given repository table.
        Parameters:
        camelContext - Current CamelContext
        key - Correlation key
        exchange - Aggregated exchange
        repositoryName - Table's name
        version - Version identifier
        Throws:
        Exception
      • insert

        protected void insert​(org.apache.camel.CamelContext camelContext,
                              String correlationId,
                              org.apache.camel.Exchange exchange,
                              String repositoryName,
                              Long version)
                       throws Exception
        Inserts a new record into the given repository table. Note: the exchange properties are NOT persisted.
        Parameters:
        camelContext - Current CamelContext
        correlationId - Correlation key
        exchange - Aggregated exchange to insert
        repositoryName - Table's name
        version - Version identifier
        Throws:
        Exception
      • insertHelper

        protected int insertHelper​(org.apache.camel.CamelContext camelContext,
                                   String key,
                                   org.apache.camel.Exchange exchange,
                                   String sql,
                                   Long version)
                            throws Exception
        Throws:
        Exception
      • updateHelper

        protected int updateHelper​(org.apache.camel.CamelContext camelContext,
                                   String key,
                                   org.apache.camel.Exchange exchange,
                                   String sql,
                                   Long version)
                            throws Exception
        Throws:
        Exception
      • get

        public org.apache.camel.Exchange get​(org.apache.camel.CamelContext camelContext,
                                             String correlationId)
        Specified by:
        get in interface org.apache.camel.spi.AggregationRepository
      • remove

        public void remove​(org.apache.camel.CamelContext camelContext,
                           String correlationId,
                           org.apache.camel.Exchange exchange)
        Specified by:
        remove in interface org.apache.camel.spi.AggregationRepository
        Specified by:
        remove in interface org.apache.camel.spi.OptimisticLockingAggregationRepository
      • confirm

        public void confirm​(org.apache.camel.CamelContext camelContext,
                            String exchangeId)
        Specified by:
        confirm in interface org.apache.camel.spi.AggregationRepository
      • confirmWithResult

        public boolean confirmWithResult​(org.apache.camel.CamelContext camelContext,
                                         String exchangeId)
        Specified by:
        confirmWithResult in interface org.apache.camel.spi.RecoverableAggregationRepository
      • getKeys

        public Set<String> getKeys()
        Specified by:
        getKeys in interface org.apache.camel.spi.AggregationRepository
      • scan

        public Set<String> scan​(org.apache.camel.CamelContext camelContext)
        Specified by:
        scan in interface org.apache.camel.spi.RecoverableAggregationRepository
      • getKeys

        protected Set<String> getKeys​(String repositoryName)
        Returns the keys in the given repository
        Parameters:
        repositoryName - The name of the table
        Returns:
        Set of keys in the given repository name
      • recover

        public org.apache.camel.Exchange recover​(org.apache.camel.CamelContext camelContext,
                                                 String exchangeId)
        Specified by:
        recover in interface org.apache.camel.spi.RecoverableAggregationRepository
      • setRecoveryInterval

        public void setRecoveryInterval​(long interval,
                                        TimeUnit timeUnit)
        If recovery is enabled then a background task is run every x'th time to scan for failed exchanges to recover and resubmit. By default this interval is 5000 millis.
        Specified by:
        setRecoveryInterval in interface org.apache.camel.spi.RecoverableAggregationRepository
      • setRecoveryInterval

        public void setRecoveryInterval​(long interval)
        Specified by:
        setRecoveryInterval in interface org.apache.camel.spi.RecoverableAggregationRepository
      • getRecoveryIntervalInMillis

        public long getRecoveryIntervalInMillis()
        Specified by:
        getRecoveryIntervalInMillis in interface org.apache.camel.spi.RecoverableAggregationRepository
      • isUseRecovery

        public boolean isUseRecovery()
        Specified by:
        isUseRecovery in interface org.apache.camel.spi.RecoverableAggregationRepository
      • setUseRecovery

        public void setUseRecovery​(boolean useRecovery)
        Whether or not recovery is enabled. This option is by default true. When enabled the Camel Aggregator automatic recover failed aggregated exchange and have them resubmitted.
        Specified by:
        setUseRecovery in interface org.apache.camel.spi.RecoverableAggregationRepository
      • getMaximumRedeliveries

        public int getMaximumRedeliveries()
        Specified by:
        getMaximumRedeliveries in interface org.apache.camel.spi.RecoverableAggregationRepository
      • setMaximumRedeliveries

        public void setMaximumRedeliveries​(int maximumRedeliveries)
        Specified by:
        setMaximumRedeliveries in interface org.apache.camel.spi.RecoverableAggregationRepository
      • getDeadLetterUri

        public String getDeadLetterUri()
        Specified by:
        getDeadLetterUri in interface org.apache.camel.spi.RecoverableAggregationRepository
      • setDeadLetterUri

        public void setDeadLetterUri​(String deadLetterUri)
        An endpoint uri for a Dead Letter Channel where exhausted recovered Exchanges will be moved. If this option is used then the maximumRedeliveries option must also be provided. Important note : if the deadletter route throws an exception, it will be send again to DLQ until it succeed !
        Specified by:
        setDeadLetterUri in interface org.apache.camel.spi.RecoverableAggregationRepository
      • isReturnOldExchange

        public boolean isReturnOldExchange()
      • setReturnOldExchange

        public void setReturnOldExchange​(boolean returnOldExchange)
        Whether the get operation should return the old existing Exchange if any existed. By default this option is false to optimize as we do not need the old exchange when aggregating.
      • setJdbcCamelCodec

        public void setJdbcCamelCodec​(JdbcCamelCodec codec)
      • hasHeadersToStoreAsText

        public boolean hasHeadersToStoreAsText()
      • getHeadersToStoreAsText

        public List<String> getHeadersToStoreAsText()
      • setHeadersToStoreAsText

        public void setHeadersToStoreAsText​(List<String> headersToStoreAsText)
        Allows to store headers as String which is human readable. By default this option is disabled, storing the headers in binary format.
        Parameters:
        headersToStoreAsText - the list of headers to store as String
      • isStoreBodyAsText

        public boolean isStoreBodyAsText()
      • setStoreBodyAsText

        public void setStoreBodyAsText​(boolean storeBodyAsText)
        Whether to store the message body as String which is human readable. By default this option is false storing the body in binary format.
      • isAllowSerializedHeaders

        public boolean isAllowSerializedHeaders()
      • setAllowSerializedHeaders

        public void setAllowSerializedHeaders​(boolean allowSerializedHeaders)
      • getPropagationBehavior

        public int getPropagationBehavior()
      • setPropagationBehavior

        public void setPropagationBehavior​(int propagationBehavior)
        Sets propagation behavior to use with spring transaction templates which are used for database access. The default is TransactionDefinition.PROPAGATION_REQUIRED.
      • setPropagationBehaviorName

        public void setPropagationBehaviorName​(String propagationBehaviorName)
        Sets propagation behavior to use with spring transaction templates which are used for database access. The default is TransactionDefinition.PROPAGATION_REQUIRED. This setter accepts names of the constants, like "PROPAGATION_REQUIRED".
        Parameters:
        propagationBehaviorName -
      • getLobHandler

        public org.springframework.jdbc.support.lob.LobHandler getLobHandler()
      • setLobHandler

        public void setLobHandler​(org.springframework.jdbc.support.lob.LobHandler lobHandler)
        Sets a custom LobHandler to use
      • getRepositoryName

        public String getRepositoryName()
      • getRepositoryNameCompleted

        public String getRepositoryNameCompleted()
      • doInit

        protected void doInit()
                       throws Exception
        Overrides:
        doInit in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • 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