Author: rhauch
Date: 2010-01-09 22:07:50 -0500 (Sat, 09 Jan 2010)
New Revision: 1579
Modified:
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicJpaConnection.java
Log:
DNA-617 BasicJpaConnection no longer needs the EntityManager field, since a new one is
always checked out and checked in within the execute(...) method. The same behavior was
added to the ping(...) method.
Modified:
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicJpaConnection.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicJpaConnection.java 2010-01-10
00:38:45 UTC (rev 1578)
+++
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/model/basic/BasicJpaConnection.java 2010-01-10
03:07:50 UTC (rev 1579)
@@ -48,7 +48,6 @@
private final String name;
private final CachePolicy cachePolicy;
private final EntityManagers entityManagers;
- private EntityManager entityManager;
private final UUID rootNodeUuid;
private final String nameOfDefaultWorkspace;
private final String[] predefinedWorkspaceNames;
@@ -76,8 +75,6 @@
this.name = sourceName;
this.cachePolicy = cachePolicy; // may be null
this.entityManagers = entityManagers;
- // this.entityManager = entityManagers.checkout();
- // assert this.entityManagers != null;
this.rootNodeUuid = rootNodeUuid;
this.largeValueMinimumSizeInBytes = largeValueMinimumSizeInBytes;
this.compressData = compressData;
@@ -121,7 +118,12 @@
*/
public boolean ping( long time,
TimeUnit unit ) {
- return entityManager != null ? entityManager.isOpen() : false;
+ EntityManager entityManager = entityManagers.checkout();
+ try {
+ return entityManager != null ? entityManager.isOpen() : false;
+ } finally {
+ entityManagers.checkin(entityManager);
+ }
}
/**
@@ -141,10 +143,10 @@
}
RequestProcessor processor = null;
+ EntityManager entityManager = null;
boolean commit = true;
-
try {
- this.entityManager = entityManagers.checkout();
+ entityManager = entityManagers.checkout();
if (entityManager == null) {
throw new
RepositorySourceException(JpaConnectorI18n.connectionIsNoLongerOpen.text(name));
@@ -161,37 +163,39 @@
commit = false;
}
} finally {
- try {
- processor.close();
- } finally {
- // Now commit or rollback ...
+ if (processor != null) {
try {
- EntityTransaction txn = entityManager.getTransaction();
- if (txn != null) {
- if (commit) {
- // Now commit the transaction ...
- txn.commit();
- } else {
- // Need to rollback the changes made to the repository ...
- txn.rollback();
+ processor.close();
+ } finally {
+ // Now commit or rollback ...
+ try {
+ EntityTransaction txn = entityManager.getTransaction();
+ if (txn != null) {
+ if (commit) {
+ // Now commit the transaction ...
+ txn.commit();
+ } else {
+ // Need to rollback the changes made to the repository
...
+ txn.rollback();
+ }
}
+ } catch (Throwable commitOrRollbackError) {
+ if (commit && !request.hasError()) {
+ // Record the error on the request ...
+ request.setError(commitOrRollbackError);
+ }
+ commit = false; // couldn't do it
}
- } catch (Throwable commitOrRollbackError) {
- if (commit && !request.hasError()) {
- // Record the error on the request ...
- request.setError(commitOrRollbackError);
+ if (commit) {
+ // Now that we're not in a transaction anymore, notify the
observer of the committed changes ...
+ processor.notifyObserverOfChanges();
}
- commit = false; // couldn't do it
}
- if (commit) {
- // Now that we're not in a transaction anymore, notify the
observer of the committed changes ...
- processor.notifyObserverOfChanges();
- }
}
// Do this only once ...
try {
- entityManagers.checkin(entityManager);
+ entityManagers.checkin(entityManager); // even if null
} finally {
entityManager = null;
}