Author: eric
Date: Fri Sep 17 13:19:05 2010
New Revision: 998114
URL: http://svn.apache.org/viewvc?rev=998114&view=rev
Log:
Always start/commit(/rollback) transactions - correct the commit phase.
Modified:
james/server/trunk/core-function/src/main/java/org/apache/james/domain/JPADomainList.java
james/server/trunk/user-function/src/main/java/org/apache/james/vut/JPAVirtualUserTable.java
Modified:
james/server/trunk/core-function/src/main/java/org/apache/james/domain/JPADomainList.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/domain/JPADomainList.java?rev=998114&r1=998113&r2=998114&view=diff
==============================================================================
---
james/server/trunk/core-function/src/main/java/org/apache/james/domain/JPADomainList.java
(original)
+++
james/server/trunk/core-function/src/main/java/org/apache/james/domain/JPADomainList.java
Fri Sep 17 13:19:05 2010
@@ -75,13 +75,13 @@ public class JPADomainList extends Abstr
try {
transaction.begin();
domains =
entityManager.createNamedQuery("listDomainNames").getResultList();
+ transaction.commit();
} catch (PersistenceException e) {
getLogger().debug("Failed to list domains", e);
if (transaction.isActive()) {
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
if (domains.size() == 0) {
@@ -100,6 +100,7 @@ public class JPADomainList extends Abstr
try {
transaction.begin();
JPADomain jpaDomain = (JPADomain)
entityManager.createNamedQuery("findDomainByName").setParameter("name",
domain).getSingleResult();
+ transaction.commit();
return (jpaDomain != null) ? true : false;
} catch (PersistenceException e) {
getLogger().debug("Failed to find domain", e);
@@ -107,7 +108,6 @@ public class JPADomainList extends Abstr
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
@@ -123,6 +123,7 @@ public class JPADomainList extends Abstr
transaction.begin();
JPADomain jpaDomain = new JPADomain(domain);
entityManager.persist(jpaDomain);
+ transaction.commit();
return true;
} catch (PersistenceException e) {
getLogger().debug("Failed to save domain", e);
@@ -130,7 +131,6 @@ public class JPADomainList extends Abstr
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
@@ -145,6 +145,7 @@ public class JPADomainList extends Abstr
try {
transaction.begin();
entityManager.createNamedQuery("deleteDomainByName").setParameter("name",
domain).executeUpdate();
+ transaction.commit();
return true;
} catch (PersistenceException e) {
getLogger().debug("Failed to remove domain", e);
@@ -152,7 +153,6 @@ public class JPADomainList extends Abstr
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
Modified:
james/server/trunk/user-function/src/main/java/org/apache/james/vut/JPAVirtualUserTable.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/user-function/src/main/java/org/apache/james/vut/JPAVirtualUserTable.java?rev=998114&r1=998113&r2=998114&view=diff
==============================================================================
---
james/server/trunk/user-function/src/main/java/org/apache/james/vut/JPAVirtualUserTable.java
(original)
+++
james/server/trunk/user-function/src/main/java/org/apache/james/vut/JPAVirtualUserTable.java
Fri Sep 17 13:19:05 2010
@@ -83,6 +83,7 @@ public class JPAVirtualUserTable extends
List<JPAVirtualUser> virtualUsers =
entityManager.createNamedQuery("selectMappings")
.setParameter("user", user)
.setParameter("domain", domain).getResultList();
+ transaction.commit();
if(virtualUsers.size() > 0) {
return virtualUsers.get(0).getTargetAddress();
}
@@ -92,7 +93,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return null;
@@ -109,6 +109,7 @@ public class JPAVirtualUserTable extends
List<JPAVirtualUser> virtualUsers =
entityManager.createNamedQuery("selectUserDomainMapping")
.setParameter("user", user)
.setParameter("domain", domain).getResultList();
+ transaction.commit();
if (virtualUsers.size() > 0) {
return
VirtualUserTableUtil.mappingToCollection(virtualUsers.get(0).getTargetAddress());
}
@@ -118,7 +119,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return null;
@@ -134,6 +134,7 @@ public class JPAVirtualUserTable extends
try {
transaction.begin();
List<JPAVirtualUser> virtualUsers =
entityManager.createNamedQuery("selectAllMappings").getResultList();
+ transaction.commit();
for (JPAVirtualUser virtualUser: virtualUsers) {
mapping.put(virtualUser.getUser()+ "@" +
virtualUser.getDomain(),
VirtualUserTableUtil.mappingToCollection(virtualUser.getTargetAddress()));
}
@@ -144,7 +145,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return null;
@@ -182,6 +182,7 @@ public class JPAVirtualUserTable extends
.setParameter("targetAddress", mapping)
.setParameter("user", user)
.setParameter("domain", domain).executeUpdate();
+ transaction.commit();
if (updated > 0) {
return true;
}
@@ -191,7 +192,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
@@ -215,6 +215,7 @@ public class JPAVirtualUserTable extends
.setParameter("user", user)
.setParameter("domain", domain)
.setParameter("targetAddress", mapping).executeUpdate();
+ transaction.commit();
if (deleted > 0) {
return true;
}
@@ -224,7 +225,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
@@ -245,6 +245,7 @@ public class JPAVirtualUserTable extends
transaction.begin();
JPAVirtualUser jpaVirtualUser = new JPAVirtualUser(user, domain,
mapping);
entityManager.persist(jpaVirtualUser);
+ transaction.commit();
return true;
} catch (PersistenceException e) {
getLogger().debug("Failed to save virtual user", e);
@@ -252,7 +253,6 @@ public class JPAVirtualUserTable extends
transaction.rollback();
}
} finally {
- transaction.commit();
entityManager.close();
}
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]