Polish (minor) async support in filters

Issue: SPR-9895
This commit is contained in:
Rossen Stoyanchev
2012-10-27 07:20:41 -04:00
parent f7ec738857
commit d952da2338
7 changed files with 59 additions and 80 deletions

View File

@@ -169,13 +169,13 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
}
/**
* The default value is "true" so that the filter may re-bind the opened
* The default value is "false" so that the filter may re-bind the opened
* {@code Session} to each asynchronously dispatched thread and postpone
* closing it until the very last asynchronous dispatch.
*/
@Override
protected boolean shouldFilterAsyncDispatches() {
return true;
protected boolean shouldNotFilterAsyncDispatch() {
return false;
}
@Override
@@ -187,7 +187,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
boolean participate = false;
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
boolean isFirstRequest = !isAsyncDispatch(request);
boolean isFirstRequest = !asyncManager.hasConcurrentResult();
String key = getAlreadyFilteredAttributeName();
if (isSingleSession()) {
@@ -210,7 +210,8 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
}
else {
// deferred close mode
Assert.state(isLastRequestThread(request), "Deferred close mode is not supported on async dispatches");
Assert.state(!asyncManager.isConcurrentHandlingStarted(),
"Deferred close mode is not supported on async dispatches");
if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
// Do not modify deferred close: just set the participate flag.
participate = true;
@@ -229,7 +230,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
// single session mode
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
if (isLastRequestThread(request)) {
if (!asyncManager.isConcurrentHandlingStarted()) {
logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");
closeSession(sessionHolder.getSession(), sessionFactory);
}

View File

@@ -102,13 +102,13 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
}
/**
* The default value is "true" so that the filter may re-bind the opened
* The default value is "false" so that the filter may re-bind the opened
* {@code Session} to each asynchronously dispatched thread and postpone
* closing it until the very last asynchronous dispatch.
*/
@Override
protected boolean shouldFilterAsyncDispatches() {
return true;
protected boolean shouldNotFilterAsyncDispatch() {
return false;
}
@Override
@@ -120,7 +120,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
boolean participate = false;
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
boolean isFirstRequest = !isAsyncDispatch(request);
boolean isFirstRequest = !asyncManager.hasConcurrentResult();
String key = getAlreadyFilteredAttributeName();
if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
@@ -147,7 +147,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
if (!participate) {
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
if (isLastRequestThread(request)) {
if (!asyncManager.isConcurrentHandlingStarted()) {
logger.debug("Closing Hibernate Session in OpenSessionInViewFilter");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}

View File

@@ -126,13 +126,13 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
}
/**
* The default value is "true" so that the filter may re-bind the opened
* The default value is "false" so that the filter may re-bind the opened
* {@code EntityManager} to each asynchronously dispatched thread and postpone
* closing it until the very last asynchronous dispatch.
*/
@Override
protected boolean shouldFilterAsyncDispatches() {
return true;
protected boolean shouldNotFilterAsyncDispatch() {
return false;
}
@Override
@@ -144,7 +144,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
boolean participate = false;
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
boolean isFirstRequest = !isAsyncDispatch(request);
boolean isFirstRequest = !asyncManager.hasConcurrentResult();
String key = getAlreadyFilteredAttributeName();
if (TransactionSynchronizationManager.hasResource(emf)) {
@@ -175,7 +175,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
if (!participate) {
EntityManagerHolder emHolder = (EntityManagerHolder)
TransactionSynchronizationManager.unbindResource(emf);
if (isLastRequestThread(request)) {
if (!asyncManager.isConcurrentHandlingStarted()) {
logger.debug("Closing JPA EntityManager in OpenEntityManagerInViewFilter");
EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}