camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] branch camel-2.x updated: CAMEL-13951: Allow to set custom transaction propagation for camel-sql aggregation repository, which can be needed for Postgres with optimistick locking.
Date Fri, 06 Sep 2019 18:24:36 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.x by this push:
     new 497a9f1  CAMEL-13951: Allow to set custom transaction propagation for camel-sql aggregation
repository, which can be needed for Postgres with optimistick locking.
497a9f1 is described below

commit 497a9f1e48e5403d0d1380c77522f5a94e8722f5
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Fri Sep 6 20:22:23 2019 +0200

    CAMEL-13951: Allow to set custom transaction propagation for camel-sql aggregation repository,
which can be needed for Postgres with optimistick locking.
---
 .../aggregate/jdbc/JdbcAggregationRepository.java  | 53 +++++++++++-----------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
index a3facf5..4fdca6f 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/processor/aggregate/jdbc/JdbcAggregationRepository.java
@@ -66,6 +66,7 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     private DataSource dataSource;
     private TransactionTemplate transactionTemplate;
     private TransactionTemplate transactionTemplateReadOnly;
+    private int propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRED;
     private JdbcTemplate jdbcTemplate;
     private LobHandler lobHandler = new DefaultLobHandler();
     private String repositoryName;
@@ -95,7 +96,7 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     }
 
     /**
-     * @param repositoryName the repositoryName to set
+     * Sets the name of the repository
      */
     public final void setRepositoryName(String repositoryName) {
         this.repositoryName = repositoryName;
@@ -105,15 +106,15 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
         this.transactionManager = transactionManager;
 
         transactionTemplate = new TransactionTemplate(transactionManager);
-        transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+        transactionTemplate.setPropagationBehavior(propagationBehavior);
 
         transactionTemplateReadOnly = new TransactionTemplate(transactionManager);
-        transactionTemplateReadOnly.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+        transactionTemplateReadOnly.setPropagationBehavior(propagationBehavior);
         transactionTemplateReadOnly.setReadOnly(true);
     }
 
     /**
-     * @param dataSource The DataSource to use for accessing the database
+     * Sets the DataSource to use for accessing the database
      */
     public final void setDataSource(DataSource dataSource) {
         this.dataSource = dataSource;
@@ -177,7 +178,6 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
      * @param key            the correlation key
      * @param exchange       the aggregated exchange
      * @param repositoryName The name of the table
-     * @throws Exception
      */
     protected void update(final CamelContext camelContext, final String key, final Exchange
exchange, String repositoryName) throws Exception {
         StringBuilder queryBuilder = new StringBuilder()
@@ -208,7 +208,6 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
      * @param correlationId  the correlation key
      * @param exchange       the aggregated exchange to insert. The headers will be persisted
but not the properties.
      * @param repositoryName The name of the table
-     * @throws Exception
      */
     protected void insert(final CamelContext camelContext, final String correlationId, final
Exchange exchange, String repositoryName) throws Exception {
         // The default totalParameterIndex is 2 for ID and Exchange. Depending on logic this
will be increased
@@ -380,8 +379,6 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     /**
      *  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.
-     * @param interval  the interval
-     * @param timeUnit  the time unit
      */
     public void setRecoveryInterval(long interval, TimeUnit timeUnit) {
         this.recoveryInterval = timeUnit.toMillis(interval);
@@ -400,9 +397,8 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     }
 
     /**
-     *
-     * @param 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 resubmittedd
+     * 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.
      */
     public void setUseRecovery(boolean useRecovery) {
         this.useRecovery = useRecovery;
@@ -421,11 +417,9 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     }
 
     /**
-     *
-     * @param 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 !
+     * 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 !
      */
     public void setDeadLetterUri(String deadLetterUri) {
         this.deadLetterUri = deadLetterUri;
@@ -436,10 +430,8 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     }
 
     /**
-     *
-     * @param 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
+     * 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.
      */
     public void setReturnOldExchange(boolean returnOldExchange) {
         this.returnOldExchange = returnOldExchange;
@@ -456,6 +448,7 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     /**
      * Allows to store headers as String which is human readable. By default this option
is disabled,
      * storing the headers in binary format.
+     *
      * @param headersToStoreAsText the list of headers to store as String
      */
     public void setHeadersToStoreAsText(List<String> headersToStoreAsText) {
@@ -463,9 +456,8 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
     }
 
     /**
-     *
-     * @param 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.
+     * Whether to store the message body as String which is human readable.
+     * By default this option is false storing the body in binary format.
      */
     public void setStoreBodyAsText(boolean storeBodyAsText) {
         this.storeBodyAsText = storeBodyAsText;
@@ -479,15 +471,24 @@ public class JdbcAggregationRepository extends ServiceSupport implements
Recover
         this.allowSerializedHeaders = allowSerializedHeaders;
     }
 
-   /**
-     * @return the lobHandler
+    public int getPropagationBehavior() {
+        return propagationBehavior;
+    }
+
+    /**
+     * Sets propagation behavior to use with spring transaction template which are used for
database access.
+     * The default is TransactionDefinition.PROPAGATION_REQUIRED.
      */
+    public void setPropagationBehavior(int propagationBehavior) {
+        this.propagationBehavior = propagationBehavior;
+    }
+
     public LobHandler getLobHandler() {
         return lobHandler;
     }
 
     /**
-     * @param lobHandler the lobHandler to set
+     * Sets a custom LobHandler to use
      */
     public void setLobHandler(LobHandler lobHandler) {
         this.lobHandler = lobHandler;


Mime
View raw message