diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/PersistenceManagerFactoryUtils.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/PersistenceManagerFactoryUtils.java index edf161162f0..b6983a4c5c1 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/PersistenceManagerFactoryUtils.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/PersistenceManagerFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -323,6 +323,11 @@ public abstract class PersistenceManagerFactoryUtils { return this.newPersistenceManager; } + @Override + protected boolean shouldReleaseAfterCompletion(PersistenceManagerHolder resourceHolder) { + return !resourceHolder.getPersistenceManager().isClosed(); + } + @Override protected void releaseResource(PersistenceManagerHolder resourceHolder, PersistenceManagerFactory resourceKey) { releasePersistenceManager(resourceHolder.getPersistenceManager(), resourceKey); diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/support/ResourceHolderSynchronization.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/support/ResourceHolderSynchronization.java index 3becfb0d4cf..be46efbfa08 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/support/ResourceHolderSynchronization.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/support/ResourceHolderSynchronization.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,7 +92,7 @@ public abstract class ResourceHolderSynchronization releaseNecessary = true; } else { - releaseNecessary = !shouldReleaseBeforeCompletion(); + releaseNecessary = shouldReleaseAfterCompletion(this.resourceHolder); } if (releaseNecessary) { releaseResource(this.resourceHolder, this.resourceKey); @@ -128,6 +128,17 @@ public abstract class ResourceHolderSynchronization return true; } + /** + * Return whether this holder's resource should be released after + * transaction completion (true). + *

The default implementation returns !shouldReleaseBeforeCompletion(), + * releasing after completion if no attempt was made before completion. + * @see #releaseResource + */ + protected boolean shouldReleaseAfterCompletion(H resourceHolder) { + return !shouldReleaseBeforeCompletion(); + } + /** * Flush callback for the given resource holder. * @param resourceHolder the resource holder to flush