camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/7] camel git commit: CAMEL-9474: camel-jpa - Add consumer options to component docs
Date Mon, 04 Jan 2016 12:44:16 GMT
CAMEL-9474: camel-jpa - Add consumer options to component docs


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c74fdf5c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c74fdf5c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c74fdf5c

Branch: refs/heads/master
Commit: c74fdf5cc659040c414718285fa6c97ba7d9fbdc
Parents: d865573
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jan 4 13:42:23 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jan 4 13:42:23 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/component/jpa/JpaEndpoint.java | 149 +++++++++++++++++++
 1 file changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c74fdf5c/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
index 1ce4838..6cd7097 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jpa;
 import java.util.Map;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.LockModeType;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
@@ -70,6 +71,27 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
     @UriParam(label = "consumer")
     private int maxMessagesPerPoll;
 
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private String query;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private String namedQuery;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private String nativeQuery;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.", defaultValue = "PESSIMISTIC_WRITE")
+    private LockModeType lockModeType = LockModeType.PESSIMISTIC_WRITE;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.", multiValue = true)
+    private Map<String, Object> parameters;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private Class<?> resultClass;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private boolean transacted;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private boolean skipLockedEntity;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private DeleteHandler<Object> deleteHandler;
+    @UriParam(label = "consumer", optionalPrefix = "consumer.")
+    private DeleteHandler<Object> preDeleteHandler;
+
     @UriParam(label = "producer", defaultValue = "true")
     private boolean flushOnSend = true;
     @UriParam(label = "producer")
@@ -82,6 +104,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
     @UriParam(label = "advanced", prefix = "emf.", multiValue = true)
     private Map<String, Object> entityManagerProperties;
 
+
     public JpaEndpoint() {
     }
 
@@ -127,6 +150,16 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
         validate();
         JpaConsumer consumer = new JpaConsumer(this, processor);
         consumer.setMaxMessagesPerPoll(getMaxMessagesPerPoll());
+        consumer.setQuery(getQuery());
+        consumer.setNamedQuery(getNamedQuery());
+        consumer.setNativeQuery(getNativeQuery());
+        consumer.setLockModeType(getLockModeType());
+        consumer.setParameters(getParameters());
+        consumer.setResultClass(getResultClass());
+        consumer.setTransacted(isTransacted());
+        consumer.setSkipLockedEntity(isSkipLockedEntity());
+        consumer.setDeleteHandler(getDeleteHandler());
+        consumer.setPreDeleteHandler(getPreDeleteHandler());
         configureConsumer(consumer);
         return consumer;
     }
@@ -347,6 +380,122 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
         this.sharedEntityManager = sharedEntityManager;
     }
 
+    public String getQuery() {
+        return query;
+    }
+
+    /**
+     * To use a custom query when consuming data.
+     */
+    public void setQuery(String query) {
+        this.query = query;
+    }
+
+    public String getNamedQuery() {
+        return namedQuery;
+    }
+
+    /**
+     * To use a named query when consuming data.
+     */
+    public void setNamedQuery(String namedQuery) {
+        this.namedQuery = namedQuery;
+    }
+
+    public String getNativeQuery() {
+        return nativeQuery;
+    }
+
+    /**
+     * To use a custom native query when consuming data. You may want to use the option consumer.resultClass
also when using native queries.
+     */
+    public void setNativeQuery(String nativeQuery) {
+        this.nativeQuery = nativeQuery;
+    }
+
+    public LockModeType getLockModeType() {
+        return lockModeType;
+    }
+
+    /**
+     * To configure the lock mode on the consumer.
+     */
+    public void setLockModeType(LockModeType lockModeType) {
+        this.lockModeType = lockModeType;
+    }
+
+    public Map<String, Object> getParameters() {
+        return parameters;
+    }
+
+    /**
+     * This key/value mapping is used for building the query parameters.
+     * It's is expected to be of the generic type java.util.Map<String, Object> where
the keys are the named parameters
+     * of a given JPA query and the values are their corresponding effective values you want
to select for.
+     */
+    public void setParameters(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+
+    public Class<?> getResultClass() {
+        return resultClass;
+    }
+
+    /**
+     * Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery,
resultClass)
+     * instead of entityManager.createNativeQuery(nativeQuery)). Without this option, we
will return an object array.
+     * Only has an affect when using in conjunction with native query when consuming data.
+     */
+    public void setResultClass(Class<?> resultClass) {
+        this.resultClass = resultClass;
+    }
+
+    public boolean isTransacted() {
+        return transacted;
+    }
+
+    /**
+     * Whether to run the consumer in transacted mode, by which all messages will either
commit or rollback,
+     * when the entire batch has been processed. The default behavior (false) is to commit
all the previously
+     * successfully processed messages, and only rollback the last failed message.
+     */
+    public void setTransacted(boolean transacted) {
+        this.transacted = transacted;
+    }
+
+    public boolean isSkipLockedEntity() {
+        return skipLockedEntity;
+    }
+
+    /**
+     * To configure whether to use NOWAIT on lock and silently skip the entity.
+     */
+    public void setSkipLockedEntity(boolean skipLockedEntity) {
+        this.skipLockedEntity = skipLockedEntity;
+    }
+
+    public DeleteHandler<Object> getDeleteHandler() {
+        return deleteHandler;
+    }
+
+    /**
+     * To use a custom DeleteHandler to delete the row after the consumer is done processing
the exchange
+     */
+    public void setDeleteHandler(DeleteHandler<Object> deleteHandler) {
+        this.deleteHandler = deleteHandler;
+    }
+
+    public DeleteHandler<Object> getPreDeleteHandler() {
+        return preDeleteHandler;
+    }
+
+    /**
+     * To use a custom Pre-DeleteHandler to delete the row after the consumer has read the
entity.
+     */
+    public void setPreDeleteHandler(DeleteHandler<Object> preDeleteHandler) {
+        this.preDeleteHandler = preDeleteHandler;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 


Mime
View raw message