hb_s

public class FlushedOpenSessionInViewFilter extends OpenSessionInViewFilter {
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
logger.debug("FIX ME!!!access FlushedOpenSessionInViewFilter");
SessionFactory sessionFactory = lookupSessionFactory(request);
Session session = null;
boolean participate = false;

if (isSingleSession()) {
// single session mode
logger.debug("FIX ME!!!Single Hibernate Session");
if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
// Do not modify the Session: just set the participate flag.
try {
logger.debug("FIX ME!!!begin unbind sessionFactory");
TransactionSynchronizationManager
.unbindResource(sessionFactory);
logger.debug("FIX ME!!!end unbind sessionFactory");

if (TransactionSynchronizationManager.hasResource(lookupDataSource()))
{
logger.debug("FIX ME!!!begin unbind DataSource");
TransactionSynchronizationManager.unbindResource(lookupDataSource());
logger.debug("FIX ME!!!end unbind DataSource");
}

logger.debug("FIX ME!!!begin close hibernate session");
closeSession(session, sessionFactory);
logger.debug("FIX ME!!!end close hibernate session");
} catch (Exception e) {
logger.debug("FIX ME!!!unbind sessionFactory error",e);
}
}
logger.debug("FIX ME!!!begin opening single Hibernate session");
session = getSession(sessionFactory);
logger.debug("FIX ME!!!end opening single Hibernate session");

if (!TransactionSynchronizationManager.hasResource(sessionFactory)){
logger.debug("FIX ME!!!begin binding session");
TransactionSynchronizationManager.bindResource(sessionFactory,
new SessionHolder(session));
logger.debug("FIX ME!!!end binding session");
}
} else {
// deferred close mode
logger.debug("FIX ME!!!not single hibernate session");
if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
// Do not modify deferred close: just set the participate flag.
participate = true;
} else {
SessionFactoryUtils.initDeferredClose(sessionFactory);
}
}

try {
logger.debug("FIX ME!!!Now filter in FlushedOpenSessionInViewFilter");
filterChain.doFilter(request, response);
logger.debug("FIX ME!!!FlushedOpenSessionInViewFilter filter OK! ");
}
finally {
logger.debug("FIX ME!!!FlushedOpenSessionInViewFilter clean session ");
if (!participate) {
if (isSingleSession()) {
// single session mode
try {
logger.debug("FIX ME!!!unbind sessionFactory in OpenSessionInViewFilter");
TransactionSynchronizationManager
.unbindResource(sessionFactory);

/*if (TransactionSynchronizationManager.hasResource(lookupDataSource()))
{
logger.debug("FIX ME!!!Unbind DataSource in OpenSessionInViewFilter");
TransactionSynchronizationManager.unbindResource(lookupDataSource());
}*/

logger.debug("FIX ME!!!Closing single Hibernate session in OpenSessionInViewFilter");
closeSession(session, sessionFactory);
} catch (Exception e) {
logger.debug("FIX ME!!!unbind sessionFactory error",e);
}
} else {
// deferred close mode
SessionFactoryUtils.processDeferredClose(sessionFactory);
}
}
logger.debug("FIX ME!!!FlushedOpenSessionInViewFilter END ");
}
}

protected void closeSession(Session arg0, SessionFactory arg1) {
arg0.flush();
super.closeSession(arg0, arg1);
}

protected DataSource lookupDataSource() {
String dataSourceBeanName = "dataSource";
WebApplicationContext wac =
WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
return (DataSource) wac.getBean(dataSourceBeanName, DataSource.class);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值