JDO PersistenceManager synchronization performs close attempt after completion (if necessary; SPR-8846)

This commit is contained in:
Juergen Hoeller 2011-11-28 19:38:28 +00:00
parent c9b36fb4e6
commit e7d1b5e0ee
2 changed files with 19 additions and 3 deletions

View File

@ -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);

View File

@ -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<H extends ResourceHolder, K>
releaseNecessary = true;
}
else {
releaseNecessary = !shouldReleaseBeforeCompletion();
releaseNecessary = shouldReleaseAfterCompletion(this.resourceHolder);
}
if (releaseNecessary) {
releaseResource(this.resourceHolder, this.resourceKey);
@ -128,6 +128,17 @@ public abstract class ResourceHolderSynchronization<H extends ResourceHolder, K>
return true;
}
/**
* Return whether this holder's resource should be released after
* transaction completion (<code>true</code>).
* <p>The default implementation returns <code>!shouldReleaseBeforeCompletion()</code>,
* 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