You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2015/06/11 22:27:22 UTC
[1/4] camel git commit: CAMEL-8855 camel-jpa - Add support for JPA
producer to delete records
Repository: camel
Updated Branches:
refs/heads/master 3faef3f8a -> 5c435e0b3
CAMEL-8855 camel-jpa - Add support for JPA producer to delete records
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cdbb91c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cdbb91c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cdbb91c6
Branch: refs/heads/master
Commit: cdbb91c648efe4acb08b55c4e39c23d76730655a
Parents: 3faef3f
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu Jun 11 21:54:07 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Jun 11 21:54:07 2015 +0200
----------------------------------------------------------------------
.../apache/camel/component/jpa/JpaEndpoint.java | 10 +++++++
.../apache/camel/component/jpa/JpaProducer.java | 30 ++++++++++++++++++--
2 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/cdbb91c6/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 e725758..84fa7ee 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
@@ -74,6 +74,8 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
private boolean usePersist;
@UriParam(label = "producer")
private boolean usePassedInEntityManager;
+ @UriParam(label = "producer")
+ private boolean isRemove;
public JpaEndpoint() {
}
@@ -290,6 +292,14 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
this.usePersist = usePersist;
}
+ public boolean isRemove() {
+ return isRemove;
+ }
+
+ public void setRemove(boolean isRemove) {
+ this.isRemove = isRemove;
+ }
+
public boolean isJoinTransaction() {
return joinTransaction;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/cdbb91c6/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
index cf96488..72532b6 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaProducer.java
@@ -68,15 +68,28 @@ public class JpaProducer extends DefaultProducer {
if (values.getClass().isArray()) {
Object[] array = (Object[])values;
for (Object element : array) {
- save(element);
+ if (!getEndpoint().isRemove()) {
+ save(element);
+ } else {
+ remove(element);
+ }
}
} else if (values instanceof Collection) {
Collection<?> collection = (Collection<?>)values;
for (Object entity : collection) {
- save(entity);
+ if (!getEndpoint().isRemove()) {
+ save(entity);
+ } else {
+ remove(entity);
+ }
}
} else {
- Object managedEntity = save(values);
+ Object managedEntity = null;
+ if (!getEndpoint().isRemove()) {
+ managedEntity = save(values);
+ } else {
+ managedEntity = remove(values);
+ }
if (!getEndpoint().isUsePersist()) {
exchange.getIn().setBody(managedEntity);
}
@@ -103,6 +116,17 @@ public class JpaProducer extends DefaultProducer {
return entityManager.merge(entity);
}
}
+
+ /**
+ * Remove the given entity end return the managed entity
+ *
+ * @return the managed entity
+ */
+ private Object remove(final Object entity) {
+ LOG.debug("remove: {}", entity);
+ entityManager.remove(entity);
+ return entity;
+ }
});
}
}
[4/4] camel git commit: Fixed CS
Posted by ac...@apache.org.
Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5c435e0b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5c435e0b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5c435e0b
Branch: refs/heads/master
Commit: 5c435e0b384d3d1f047a11dc6059e9eaffcedd97
Parents: d5d4472
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu Jun 11 22:24:11 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Jun 11 22:24:11 2015 +0200
----------------------------------------------------------------------
.../apache/camel/processor/jpa/JpaProducerRemoveTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5c435e0b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
index bc5f9c8..69f03ac 100644
--- a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
@@ -81,9 +81,9 @@ public class JpaProducerRemoveTest extends AbstractJpaTest {
return "org/apache/camel/processor/jpa/springJpaRouteTest.xml";
}
- @Override
- protected String selectAllString() {
- return SELECT_ALL_STRING;
- }
+ @Override
+ protected String selectAllString() {
+ return SELECT_ALL_STRING;
+ }
}
[2/4] camel git commit: CAMEL-8855 Added entity remove test
Posted by ac...@apache.org.
CAMEL-8855 Added entity remove test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8e37d25d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8e37d25d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8e37d25d
Branch: refs/heads/master
Commit: 8e37d25d6ed9005813d7661ccb1ac3a231dce2ea
Parents: cdbb91c
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu Jun 11 22:19:20 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Jun 11 22:19:20 2015 +0200
----------------------------------------------------------------------
.../apache/camel/component/jpa/JpaEndpoint.java | 6 +-
.../processor/jpa/JpaProducerRemoveTest.java | 89 ++++++++++++++++++++
2 files changed, 92 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8e37d25d/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 84fa7ee..405d1ad 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
@@ -75,7 +75,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
@UriParam(label = "producer")
private boolean usePassedInEntityManager;
@UriParam(label = "producer")
- private boolean isRemove;
+ private boolean remove;
public JpaEndpoint() {
}
@@ -293,11 +293,11 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
}
public boolean isRemove() {
- return isRemove;
+ return remove;
}
public void setRemove(boolean isRemove) {
- this.isRemove = isRemove;
+ this.remove = isRemove;
}
public boolean isJoinTransaction() {
http://git-wip-us.apache.org/repos/asf/camel/blob/8e37d25d/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
new file mode 100644
index 0000000..bc5f9c8
--- /dev/null
+++ b/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaProducerRemoveTest.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jpa.JpaConstants;
+import org.apache.camel.component.jpa.JpaEndpoint;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class JpaProducerRemoveTest extends AbstractJpaTest {
+ protected static final String SELECT_ALL_STRING = "select x from " + SendEmail.class.getName() + " x";
+
+ @Test
+ public void testRouteJpa() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ context.startRoute("foo");
+ context.startRoute("foo1");
+ JpaEndpoint jpa = context.getEndpoint("jpa://" + SendEmail.class.getName(), JpaEndpoint.class);
+ EntityManagerFactory emf = jpa.getEntityManagerFactory();
+
+ EntityManager entityManager = emf.createEntityManager();
+ template.sendBody("direct:start", new SendEmail("foo@beer.org"));
+ Exchange exchange = mock.getReceivedExchanges().get(0);
+ SendEmail persistedEntity = exchange.getIn().getBody(SendEmail.class);
+ SendEmail emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
+ assertNotSame(emfindEntity, persistedEntity);
+ entityManager.close();
+ mock.reset();
+
+ entityManager = emf.createEntityManager();
+ template.sendBody("direct:remove", new SendEmail("foo@beer.org"));
+ exchange = mock.getReceivedExchanges().get(0);
+ persistedEntity = exchange.getIn().getBody(SendEmail.class);
+ emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
+ assertNull(emfindEntity);
+ entityManager.close();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new SpringRouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .id("foo")
+ .to("jpa://" + SendEmail.class.getName() + "?usePassedInEntityManager=true")
+ .to("mock:result");
+ from("direct:remove")
+ .id("foo1")
+ .to("jpa://" + SendEmail.class.getName() + "?remove=true&usePassedInEntityManager=true")
+ .to("mock:result");
+ }
+ };
+ }
+
+ @Override
+ protected String routeXml() {
+ return "org/apache/camel/processor/jpa/springJpaRouteTest.xml";
+ }
+
+ @Override
+ protected String selectAllString() {
+ return SELECT_ALL_STRING;
+ }
+
+}
[3/4] camel git commit: Camel-Jpa Component docs
Posted by ac...@apache.org.
Camel-Jpa Component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d5d4472f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d5d4472f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d5d4472f
Branch: refs/heads/master
Commit: d5d4472f246a2b7dc9c3cc4395fb52815eb6dcf6
Parents: 8e37d25
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu Jun 11 22:20:58 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu Jun 11 22:20:58 2015 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d5d4472f/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 405d1ad..655845e 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
@@ -296,6 +296,9 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
return remove;
}
+ /**
+ * Indicates to use entityManager.remove(entity).
+ */
public void setRemove(boolean isRemove) {
this.remove = isRemove;
}