You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/04 13:44:19 UTC
[7/7] camel git commit: CAMEL-9474: camel-jpa - Add consumer options
to component docs
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/609c2136
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/609c2136
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/609c2136
Branch: refs/heads/camel-2.16.x
Commit: 609c21366498b7c5e10fee2fb06a21b442f400c4
Parents: 6081591
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jan 4 13:42:23 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 4 13:44:01 2016 +0100
----------------------------------------------------------------------
.../apache/camel/component/jpa/JpaEndpoint.java | 149 +++++++++++++++++++
1 file changed, 149 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/609c2136/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 64dd9836..b1839f1 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;
@@ -67,6 +68,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")
@@ -79,6 +101,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
@UriParam(label = "advanced", prefix = "emf.", multiValue = true)
private Map<String, Object> entityManagerProperties;
+
public JpaEndpoint() {
}
@@ -124,6 +147,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;
}
@@ -344,6 +377,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
// -------------------------------------------------------------------------