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 2017/08/12 23:55:27 UTC

[1/9] camel git commit: surrounded with try/catch/finally to ensure entity manager always closes

Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 1a30497c2 -> 692b0f7d1
  refs/heads/camel-2.19.x 60a6bf951 -> ab36493a9
  refs/heads/master a1352b262 -> fd7d46b2d


surrounded with try/catch/finally to ensure entity manager always closes


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

Branch: refs/heads/master
Commit: 1232f4f014b1c98a6aea8b5b3518db25a28bf711
Parents: 4cbd85b
Author: mkcochran <mc...@redhat.com>
Authored: Fri Aug 11 11:30:49 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:48:37 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 103 +++++++++++++------
 1 file changed, 70 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1232f4f0/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index 1d9b717..fabef9f 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 
 import org.apache.camel.Exchange;
@@ -88,7 +89,6 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     @Override
     public boolean add(final Exchange exchange, final String messageId) {
         final EntityManager entityManager = getTargetEntityManager(exchange, entityManagerFactory, true, sharedEntityManager, true);
-
         // Run this in single transaction.
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>() {
             public Boolean doInTransaction(TransactionStatus status) {
@@ -96,18 +96,31 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
 
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    MessageProcessed processed = new MessageProcessed();
-                    processed.setProcessorName(processorName);
-                    processed.setMessageId(messageId);
-                    processed.setCreatedAt(new Date());
-                    entityManager.persist(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
-                } else {
-                    return Boolean.FALSE;
+                try {
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		MessageProcessed processed = new MessageProcessed();
+                		processed.setProcessorName(processorName);
+                		processed.setMessageId(messageId);
+                		processed.setCreatedAt(new Date());
+                		entityManager.persist(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	} else {
+                		return Boolean.FALSE;
+                	}
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to add message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -159,16 +172,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    return Boolean.FALSE;
-                } else {
-                    MessageProcessed processed = (MessageProcessed) list.get(0);
-                    entityManager.remove(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
+                try{
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		return Boolean.FALSE;
+                	} else {
+                		MessageProcessed processed = (MessageProcessed) list.get(0);
+                		entityManager.remove(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	}
+                } catch(Exception ex){
+                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                	try {
+                		if (entityManager.isOpen()) {
+                			entityManager.close();
+                		}
+                	} catch (Exception e) {
+                		// ignore
+                	}
                 }
             }
         });
@@ -197,18 +222,30 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = queryClear(entityManager);
-                if (!list.isEmpty()) {
-                    Iterator it = list.iterator();
-                    while (it.hasNext()) {
-                        Object item = it.next();
-                        entityManager.remove(item);
+                try {
+                	List<?> list = queryClear(entityManager);
+                	if (!list.isEmpty()) {
+                		Iterator it = list.iterator();
+                		while (it.hasNext()) {
+                			Object item = it.next();
+                			entityManager.remove(item);
+                		}
+                		entityManager.flush();
+                		entityManager.close();
+                	}
+                	return Boolean.TRUE;
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to clear the repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
                     }
-                    entityManager.flush();
-                    entityManager.close();
                 }
-                return Boolean.TRUE;
             }
         });
 


[9/9] camel git commit: CAMEL-11630: Fixed CS. This closes #1883.

Posted by da...@apache.org.
CAMEL-11630: Fixed CS. This closes #1883.


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

Branch: refs/heads/camel-2.18.x
Commit: 692b0f7d130c025f1b7fd5a192d65f7c4043e8d5
Parents: 5b183fd
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Aug 13 01:52:26 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:55:17 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 109 +++++++++----------
 1 file changed, 54 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/692b0f7d/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index fabef9f..36fb2e4 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -19,7 +19,6 @@ package org.apache.camel.processor.idempotent.jpa;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
@@ -97,22 +96,22 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 }
 
                 try {
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		MessageProcessed processed = new MessageProcessed();
-                		processed.setProcessorName(processorName);
-                		processed.setMessageId(messageId);
-                		processed.setCreatedAt(new Date());
-                		entityManager.persist(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	} else {
-                		return Boolean.FALSE;
-                	}
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to add message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        MessageProcessed processed = new MessageProcessed();
+                        processed.setProcessorName(processorName);
+                        processed.setMessageId(messageId);
+                        processed.setCreatedAt(new Date());
+                        entityManager.persist(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to add message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -172,28 +171,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-                try{
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		return Boolean.FALSE;
-                	} else {
-                		MessageProcessed processed = (MessageProcessed) list.get(0);
-                		entityManager.remove(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	}
-                } catch(Exception ex){
-                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                try {
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        return Boolean.FALSE;
+                    } else {
+                        MessageProcessed processed = (MessageProcessed) list.get(0);
+                        entityManager.remove(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
-                	try {
-                		if (entityManager.isOpen()) {
-                			entityManager.close();
-                		}
-                	} catch (Exception e) {
-                		// ignore
-                	}
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -223,20 +222,20 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
                 try {
-                	List<?> list = queryClear(entityManager);
-                	if (!list.isEmpty()) {
-                		Iterator it = list.iterator();
-                		while (it.hasNext()) {
-                			Object item = it.next();
-                			entityManager.remove(item);
-                		}
-                		entityManager.flush();
-                		entityManager.close();
-                	}
-                	return Boolean.TRUE;
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to clear the repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = queryClear(entityManager);
+                    if (!list.isEmpty()) {
+                        Iterator it = list.iterator();
+                        while (it.hasNext()) {
+                            Object item = it.next();
+                            entityManager.remove(item);
+                        }
+                        entityManager.flush();
+                        entityManager.close();
+                    }
+                    return Boolean.TRUE;
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to clear the repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -249,7 +248,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
             }
         });
 
-        LOG.debug("clear the store {}", MessageProcessed.class.getName());        
+        LOG.debug("clear the store {}", MessageProcessed.class.getName());
     }
 
     private List<?> query(final EntityManager entityManager, final String messageId) {
@@ -258,7 +257,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
         query.setParameter(2, messageId);
         return query.getResultList();
     }
-    
+
     private List<?> queryClear(final EntityManager entityManager) {
         Query query = entityManager.createQuery(QUERY_CLEAR_STRING);
         query.setParameter(1, processorName);
@@ -287,7 +286,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     public void setSharedEntityManager(boolean sharedEntityManager) {
         this.sharedEntityManager = sharedEntityManager;
     }
-    
+
     @Override
     protected void doStart() throws Exception {
         // noop


[8/9] camel git commit: surrounded with try/catch/finally to ensure entity manager always closes

Posted by da...@apache.org.
surrounded with try/catch/finally to ensure entity manager always closes


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

Branch: refs/heads/camel-2.18.x
Commit: 5b183fd460fe62a63ca92e082bdcc63cd1274fa4
Parents: a1da011
Author: mkcochran <mc...@redhat.com>
Authored: Fri Aug 11 11:30:49 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:55:11 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 103 +++++++++++++------
 1 file changed, 70 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5b183fd4/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index 1d9b717..fabef9f 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 
 import org.apache.camel.Exchange;
@@ -88,7 +89,6 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     @Override
     public boolean add(final Exchange exchange, final String messageId) {
         final EntityManager entityManager = getTargetEntityManager(exchange, entityManagerFactory, true, sharedEntityManager, true);
-
         // Run this in single transaction.
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>() {
             public Boolean doInTransaction(TransactionStatus status) {
@@ -96,18 +96,31 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
 
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    MessageProcessed processed = new MessageProcessed();
-                    processed.setProcessorName(processorName);
-                    processed.setMessageId(messageId);
-                    processed.setCreatedAt(new Date());
-                    entityManager.persist(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
-                } else {
-                    return Boolean.FALSE;
+                try {
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		MessageProcessed processed = new MessageProcessed();
+                		processed.setProcessorName(processorName);
+                		processed.setMessageId(messageId);
+                		processed.setCreatedAt(new Date());
+                		entityManager.persist(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	} else {
+                		return Boolean.FALSE;
+                	}
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to add message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -159,16 +172,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    return Boolean.FALSE;
-                } else {
-                    MessageProcessed processed = (MessageProcessed) list.get(0);
-                    entityManager.remove(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
+                try{
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		return Boolean.FALSE;
+                	} else {
+                		MessageProcessed processed = (MessageProcessed) list.get(0);
+                		entityManager.remove(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	}
+                } catch(Exception ex){
+                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                	try {
+                		if (entityManager.isOpen()) {
+                			entityManager.close();
+                		}
+                	} catch (Exception e) {
+                		// ignore
+                	}
                 }
             }
         });
@@ -197,18 +222,30 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = queryClear(entityManager);
-                if (!list.isEmpty()) {
-                    Iterator it = list.iterator();
-                    while (it.hasNext()) {
-                        Object item = it.next();
-                        entityManager.remove(item);
+                try {
+                	List<?> list = queryClear(entityManager);
+                	if (!list.isEmpty()) {
+                		Iterator it = list.iterator();
+                		while (it.hasNext()) {
+                			Object item = it.next();
+                			entityManager.remove(item);
+                		}
+                		entityManager.flush();
+                		entityManager.close();
+                	}
+                	return Boolean.TRUE;
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to clear the repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
                     }
-                    entityManager.flush();
-                    entityManager.close();
                 }
-                return Boolean.TRUE;
             }
         });
 


[4/9] camel git commit: closing entity manager

Posted by da...@apache.org.
closing entity manager


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

Branch: refs/heads/camel-2.19.x
Commit: 18f7de6275af06d359e199834616adb91e3d0444
Parents: 60a6bf9
Author: mkcochran <mc...@redhat.com>
Authored: Thu Aug 10 15:54:38 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:54:32 2017 +0200

----------------------------------------------------------------------
 .../camel/processor/idempotent/jpa/JpaMessageIdRepository.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/18f7de62/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index f992715..1d9b717 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -104,6 +104,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     processed.setCreatedAt(new Date());
                     entityManager.persist(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 } else {
                     return Boolean.FALSE;
@@ -166,6 +167,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     MessageProcessed processed = (MessageProcessed) list.get(0);
                     entityManager.remove(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 }
             }
@@ -204,6 +206,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                         entityManager.remove(item);
                     }
                     entityManager.flush();
+                    entityManager.close();
                 }
                 return Boolean.TRUE;
             }


[6/9] camel git commit: CAMEL-11630: Fixed CS. This closes #1883.

Posted by da...@apache.org.
CAMEL-11630: Fixed CS. This closes #1883.


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

Branch: refs/heads/camel-2.19.x
Commit: ab36493a966180ad5585c81bdecb3c8054cdf810
Parents: e620a24
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Aug 13 01:52:26 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:54:43 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 109 +++++++++----------
 1 file changed, 54 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ab36493a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index fabef9f..36fb2e4 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -19,7 +19,6 @@ package org.apache.camel.processor.idempotent.jpa;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
@@ -97,22 +96,22 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 }
 
                 try {
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		MessageProcessed processed = new MessageProcessed();
-                		processed.setProcessorName(processorName);
-                		processed.setMessageId(messageId);
-                		processed.setCreatedAt(new Date());
-                		entityManager.persist(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	} else {
-                		return Boolean.FALSE;
-                	}
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to add message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        MessageProcessed processed = new MessageProcessed();
+                        processed.setProcessorName(processorName);
+                        processed.setMessageId(messageId);
+                        processed.setCreatedAt(new Date());
+                        entityManager.persist(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to add message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -172,28 +171,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-                try{
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		return Boolean.FALSE;
-                	} else {
-                		MessageProcessed processed = (MessageProcessed) list.get(0);
-                		entityManager.remove(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	}
-                } catch(Exception ex){
-                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                try {
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        return Boolean.FALSE;
+                    } else {
+                        MessageProcessed processed = (MessageProcessed) list.get(0);
+                        entityManager.remove(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
-                	try {
-                		if (entityManager.isOpen()) {
-                			entityManager.close();
-                		}
-                	} catch (Exception e) {
-                		// ignore
-                	}
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -223,20 +222,20 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
                 try {
-                	List<?> list = queryClear(entityManager);
-                	if (!list.isEmpty()) {
-                		Iterator it = list.iterator();
-                		while (it.hasNext()) {
-                			Object item = it.next();
-                			entityManager.remove(item);
-                		}
-                		entityManager.flush();
-                		entityManager.close();
-                	}
-                	return Boolean.TRUE;
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to clear the repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = queryClear(entityManager);
+                    if (!list.isEmpty()) {
+                        Iterator it = list.iterator();
+                        while (it.hasNext()) {
+                            Object item = it.next();
+                            entityManager.remove(item);
+                        }
+                        entityManager.flush();
+                        entityManager.close();
+                    }
+                    return Boolean.TRUE;
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to clear the repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -249,7 +248,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
             }
         });
 
-        LOG.debug("clear the store {}", MessageProcessed.class.getName());        
+        LOG.debug("clear the store {}", MessageProcessed.class.getName());
     }
 
     private List<?> query(final EntityManager entityManager, final String messageId) {
@@ -258,7 +257,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
         query.setParameter(2, messageId);
         return query.getResultList();
     }
-    
+
     private List<?> queryClear(final EntityManager entityManager) {
         Query query = entityManager.createQuery(QUERY_CLEAR_STRING);
         query.setParameter(1, processorName);
@@ -287,7 +286,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     public void setSharedEntityManager(boolean sharedEntityManager) {
         this.sharedEntityManager = sharedEntityManager;
     }
-    
+
     @Override
     protected void doStart() throws Exception {
         // noop


[2/9] camel git commit: closing entity manager

Posted by da...@apache.org.
closing entity manager


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

Branch: refs/heads/master
Commit: 4cbd85b062e33beffb85b4756222ac888ec31a0c
Parents: a1352b2
Author: mkcochran <mc...@redhat.com>
Authored: Thu Aug 10 15:54:38 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:48:37 2017 +0200

----------------------------------------------------------------------
 .../camel/processor/idempotent/jpa/JpaMessageIdRepository.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4cbd85b0/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index f992715..1d9b717 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -104,6 +104,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     processed.setCreatedAt(new Date());
                     entityManager.persist(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 } else {
                     return Boolean.FALSE;
@@ -166,6 +167,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     MessageProcessed processed = (MessageProcessed) list.get(0);
                     entityManager.remove(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 }
             }
@@ -204,6 +206,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                         entityManager.remove(item);
                     }
                     entityManager.flush();
+                    entityManager.close();
                 }
                 return Boolean.TRUE;
             }


[7/9] camel git commit: closing entity manager

Posted by da...@apache.org.
closing entity manager


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

Branch: refs/heads/camel-2.18.x
Commit: a1da0113ce28253ea4d34203df9c86da0ef8948d
Parents: 1a30497
Author: mkcochran <mc...@redhat.com>
Authored: Thu Aug 10 15:54:38 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:55:04 2017 +0200

----------------------------------------------------------------------
 .../camel/processor/idempotent/jpa/JpaMessageIdRepository.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a1da0113/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index f992715..1d9b717 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -104,6 +104,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     processed.setCreatedAt(new Date());
                     entityManager.persist(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 } else {
                     return Boolean.FALSE;
@@ -166,6 +167,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     MessageProcessed processed = (MessageProcessed) list.get(0);
                     entityManager.remove(processed);
                     entityManager.flush();
+                    entityManager.close();
                     return Boolean.TRUE;
                 }
             }
@@ -204,6 +206,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                         entityManager.remove(item);
                     }
                     entityManager.flush();
+                    entityManager.close();
                 }
                 return Boolean.TRUE;
             }


[3/9] camel git commit: CAMEL-11630: Fixed CS. This closes #1883.

Posted by da...@apache.org.
CAMEL-11630: Fixed CS. This closes #1883.


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

Branch: refs/heads/master
Commit: fd7d46b2d193a7d12da7a6869ac92a971c3f7561
Parents: 1232f4f
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Aug 13 01:52:26 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:52:26 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 109 +++++++++----------
 1 file changed, 54 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fd7d46b2/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index fabef9f..36fb2e4 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -19,7 +19,6 @@ package org.apache.camel.processor.idempotent.jpa;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
@@ -97,22 +96,22 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 }
 
                 try {
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		MessageProcessed processed = new MessageProcessed();
-                		processed.setProcessorName(processorName);
-                		processed.setMessageId(messageId);
-                		processed.setCreatedAt(new Date());
-                		entityManager.persist(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	} else {
-                		return Boolean.FALSE;
-                	}
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to add message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        MessageProcessed processed = new MessageProcessed();
+                        processed.setProcessorName(processorName);
+                        processed.setMessageId(messageId);
+                        processed.setCreatedAt(new Date());
+                        entityManager.persist(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to add message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -172,28 +171,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-                try{
-                	List<?> list = query(entityManager, messageId);
-                	if (list.isEmpty()) {
-                		return Boolean.FALSE;
-                	} else {
-                		MessageProcessed processed = (MessageProcessed) list.get(0);
-                		entityManager.remove(processed);
-                		entityManager.flush();
-                		entityManager.close();
-                		return Boolean.TRUE;
-                	}
-                } catch(Exception ex){
-                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
-                	throw new PersistenceException(ex);
+                try {
+                    List<?> list = query(entityManager, messageId);
+                    if (list.isEmpty()) {
+                        return Boolean.FALSE;
+                    } else {
+                        MessageProcessed processed = (MessageProcessed) list.get(0);
+                        entityManager.remove(processed);
+                        entityManager.flush();
+                        entityManager.close();
+                        return Boolean.TRUE;
+                    }
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
-                	try {
-                		if (entityManager.isOpen()) {
-                			entityManager.close();
-                		}
-                	} catch (Exception e) {
-                		// ignore
-                	}
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -223,20 +222,20 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
                 try {
-                	List<?> list = queryClear(entityManager);
-                	if (!list.isEmpty()) {
-                		Iterator it = list.iterator();
-                		while (it.hasNext()) {
-                			Object item = it.next();
-                			entityManager.remove(item);
-                		}
-                		entityManager.flush();
-                		entityManager.close();
-                	}
-                	return Boolean.TRUE;
-                } catch(Exception ex) {
-                	LOG.error("Something went wrong trying to clear the repository {}", ex);
-                	throw new PersistenceException(ex);
+                    List<?> list = queryClear(entityManager);
+                    if (!list.isEmpty()) {
+                        Iterator it = list.iterator();
+                        while (it.hasNext()) {
+                            Object item = it.next();
+                            entityManager.remove(item);
+                        }
+                        entityManager.flush();
+                        entityManager.close();
+                    }
+                    return Boolean.TRUE;
+                } catch (Exception ex) {
+                    LOG.error("Something went wrong trying to clear the repository {}", ex);
+                    throw new PersistenceException(ex);
                 } finally {
                     try {
                         if (entityManager.isOpen()) {
@@ -249,7 +248,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
             }
         });
 
-        LOG.debug("clear the store {}", MessageProcessed.class.getName());        
+        LOG.debug("clear the store {}", MessageProcessed.class.getName());
     }
 
     private List<?> query(final EntityManager entityManager, final String messageId) {
@@ -258,7 +257,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
         query.setParameter(2, messageId);
         return query.getResultList();
     }
-    
+
     private List<?> queryClear(final EntityManager entityManager) {
         Query query = entityManager.createQuery(QUERY_CLEAR_STRING);
         query.setParameter(1, processorName);
@@ -287,7 +286,7 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     public void setSharedEntityManager(boolean sharedEntityManager) {
         this.sharedEntityManager = sharedEntityManager;
     }
-    
+
     @Override
     protected void doStart() throws Exception {
         // noop


[5/9] camel git commit: surrounded with try/catch/finally to ensure entity manager always closes

Posted by da...@apache.org.
surrounded with try/catch/finally to ensure entity manager always closes


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

Branch: refs/heads/camel-2.19.x
Commit: e620a2496edc8d75e4e2bb7a650f95d293cb07bb
Parents: 18f7de6
Author: mkcochran <mc...@redhat.com>
Authored: Fri Aug 11 11:30:49 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Aug 13 01:54:37 2017 +0200

----------------------------------------------------------------------
 .../idempotent/jpa/JpaMessageIdRepository.java  | 103 +++++++++++++------
 1 file changed, 70 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e620a249/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
index 1d9b717..fabef9f 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 
 import org.apache.camel.Exchange;
@@ -88,7 +89,6 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
     @Override
     public boolean add(final Exchange exchange, final String messageId) {
         final EntityManager entityManager = getTargetEntityManager(exchange, entityManagerFactory, true, sharedEntityManager, true);
-
         // Run this in single transaction.
         Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>() {
             public Boolean doInTransaction(TransactionStatus status) {
@@ -96,18 +96,31 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                     entityManager.joinTransaction();
                 }
 
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    MessageProcessed processed = new MessageProcessed();
-                    processed.setProcessorName(processorName);
-                    processed.setMessageId(messageId);
-                    processed.setCreatedAt(new Date());
-                    entityManager.persist(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
-                } else {
-                    return Boolean.FALSE;
+                try {
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		MessageProcessed processed = new MessageProcessed();
+                		processed.setProcessorName(processorName);
+                		processed.setMessageId(messageId);
+                		processed.setCreatedAt(new Date());
+                		entityManager.persist(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	} else {
+                		return Boolean.FALSE;
+                	}
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to add message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
+                    }
                 }
             }
         });
@@ -159,16 +172,28 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = query(entityManager, messageId);
-                if (list.isEmpty()) {
-                    return Boolean.FALSE;
-                } else {
-                    MessageProcessed processed = (MessageProcessed) list.get(0);
-                    entityManager.remove(processed);
-                    entityManager.flush();
-                    entityManager.close();
-                    return Boolean.TRUE;
+                try{
+                	List<?> list = query(entityManager, messageId);
+                	if (list.isEmpty()) {
+                		return Boolean.FALSE;
+                	} else {
+                		MessageProcessed processed = (MessageProcessed) list.get(0);
+                		entityManager.remove(processed);
+                		entityManager.flush();
+                		entityManager.close();
+                		return Boolean.TRUE;
+                	}
+                } catch(Exception ex){
+                	LOG.error("Something went wrong trying to remove message to repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                	try {
+                		if (entityManager.isOpen()) {
+                			entityManager.close();
+                		}
+                	} catch (Exception e) {
+                		// ignore
+                	}
                 }
             }
         });
@@ -197,18 +222,30 @@ public class JpaMessageIdRepository extends ServiceSupport implements ExchangeId
                 if (isJoinTransaction()) {
                     entityManager.joinTransaction();
                 }
-
-                List<?> list = queryClear(entityManager);
-                if (!list.isEmpty()) {
-                    Iterator it = list.iterator();
-                    while (it.hasNext()) {
-                        Object item = it.next();
-                        entityManager.remove(item);
+                try {
+                	List<?> list = queryClear(entityManager);
+                	if (!list.isEmpty()) {
+                		Iterator it = list.iterator();
+                		while (it.hasNext()) {
+                			Object item = it.next();
+                			entityManager.remove(item);
+                		}
+                		entityManager.flush();
+                		entityManager.close();
+                	}
+                	return Boolean.TRUE;
+                } catch(Exception ex) {
+                	LOG.error("Something went wrong trying to clear the repository {}", ex);
+                	throw new PersistenceException(ex);
+                } finally {
+                    try {
+                        if (entityManager.isOpen()) {
+                            entityManager.close();
+                        }
+                    } catch (Exception e) {
+                        // ignore
                     }
-                    entityManager.flush();
-                    entityManager.close();
                 }
-                return Boolean.TRUE;
             }
         });