You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/20 01:56:37 UTC

[james-project] 09/49: [Refactoring] JPADomainList should not open transactions upon read

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a01d4499387092fd5e2873cd71285145f73fc346
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Nov 18 14:15:17 2019 +0700

    [Refactoring] JPADomainList should not open transactions upon read
---
 .../apache/james/domainlist/jpa/JPADomainList.java  | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java b/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
index 40cd999..0aaca0d 100644
--- a/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
+++ b/server/data/data-jpa/src/main/java/org/apache/james/domainlist/jpa/JPADomainList.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.domainlist.jpa;
 
-import java.util.ArrayList;
 import java.util.List;
 
 import javax.annotation.PostConstruct;
@@ -39,7 +38,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.steveash.guavate.Guavate;
-import com.google.common.collect.ImmutableList;
 
 /**
  * JPA implementation of the DomainList.<br>
@@ -62,8 +60,6 @@ public class JPADomainList extends AbstractDomainList {
 
     /**
      * Set the entity manager to use.
-     *
-     * @param entityManagerFactory
      */
     @Inject
     @PersistenceUnit(unitName = "James")
@@ -79,41 +75,30 @@ public class JPADomainList extends AbstractDomainList {
     @SuppressWarnings("unchecked")
     @Override
     protected List<Domain> getDomainListInternal() throws DomainListException {
-        List<Domain> domains = new ArrayList<>();
         EntityManager entityManager = entityManagerFactory.createEntityManager();
-        final EntityTransaction transaction = entityManager.getTransaction();
         try {
-            transaction.begin();
             List<String> resultList = entityManager
                     .createNamedQuery("listDomainNames")
                     .getResultList();
-            domains = resultList
+            return resultList
                     .stream()
-                    .map(domainAsString -> Domain.of(domainAsString))
+                    .map(Domain::of)
                     .collect(Guavate.toImmutableList());
-            transaction.commit();
         } catch (PersistenceException e) {
             LOGGER.error("Failed to list domains", e);
-            rollback(transaction);
             throw new DomainListException("Unable to retrieve domains", e);
         } finally {
             entityManager.close();
         }
-        return ImmutableList.copyOf(domains);
     }
 
     @Override
     protected boolean containsDomainInternal(Domain domain) throws DomainListException {
         EntityManager entityManager = entityManagerFactory.createEntityManager();
-        final EntityTransaction transaction = entityManager.getTransaction();
         try {
-            transaction.begin();
-            boolean result = containsDomainInternal(domain, entityManager);
-            transaction.commit();
-            return result;
+            return containsDomainInternal(domain, entityManager);
         } catch (PersistenceException e) {
             LOGGER.error("Failed to find domain", e);
-            rollback(transaction);
             throw new DomainListException("Unable to retrieve domains", e);
         } finally {
             entityManager.close();


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org