本文整理汇总了Java中org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession方法的典型用法代码示例。如果您正苦于以下问题:Java SessionFactoryUtils.closeSession方法的具体用法?Java SessionFactoryUtils.closeSession怎么用?Java SessionFactoryUtils.closeSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.orm.hibernate3.SessionFactoryUtils
的用法示例。
在下文中一共展示了SessionFactoryUtils.closeSession方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
SessionFactory sf = getSessionFactory();
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return invocation.proceed();
}
finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
}
else {
// Pre-bound Session found -> simply proceed.
return invocation.proceed();
}
}
示例2: afterCompletion
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
* Unbind the Hibernate {@code Session} from the thread and close it (in
* single session mode), or process deferred close for all sessions that have
* been opened during the current request (in deferred close mode).
* @see org.springframework.transaction.support.TransactionSynchronizationManager
*/
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
if (isSingleSession()) {
// single session mode
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
else {
// deferred close mode
SessionFactoryUtils.processDeferredClose(getSessionFactory());
}
}
}
示例3: afterCompletion
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
* Unbind the Hibernate {@code Session} from the thread and close it (in
* single session mode), or process deferred close for all sessions that have
* been opened during the current request (in deferred close mode).
* @see org.springframework.transaction.support.TransactionSynchronizationManager
*/
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
if (!decrementParticipateCount(request)) {
if (isSingleSession()) {
// single session mode
SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
else {
// deferred close mode
SessionFactoryUtils.processDeferredClose(getSessionFactory());
}
}
}
示例4: unbindSession
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
private void unbindSession() {
if (sessionFactory == null) {
throw new IllegalStateException("No sessionFactory property provided");
}
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
try {
if (!FlushMode.MANUAL.equals(sessionHolder.getSession().getFlushMode())) {
sessionHolder.getSession().flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
}
示例5: queryForBean
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
public List<Object> queryForBean(Object bean,SqlConfig hqlConfig) {
HqlQuery hqlQuery = HibernateClassUtils.getHql(bean, hqlConfig);
String queryString = hqlQuery.getQueryString();
Map<String,Object> nameKeyMap = hqlQuery.getNameKeyMap();
Session session = openSession();
Query query = session.createQuery(queryString);
if (nameKeyMap != null && nameKeyMap.size() > 0) {
query.setProperties(nameKeyMap);
}
List<Object> resultList = query.list();
SessionFactoryUtils.closeSession(session);
return resultList;
}
示例6: tearDown
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
* @throws Exception
*/
@After
public void tearDown() throws Exception {
if (sessionOwner && session != null) {
SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
Session s = holder.getSession();
s.flush();
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSession(s);
}
if (wiser != null) {
wiser.stop();
}
}
示例7: closeAfterTimeout
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
private void closeAfterTimeout() {
if (this.timeoutInProgress) {
logger.debug("Closing Hibernate Session after async request timeout");
SessionFactoryUtils.closeSession(sessionHolder.getSession());
}
}
示例8: closeAfterTimeout
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
private void closeAfterTimeout() {
if (this.timeoutInProgress) {
logger.debug("Closing Hibernate Session after async request timeout");
SessionFactoryUtils.closeSession(this.sessionHolder.getSession());
}
}
示例9: closeSession
import org.springframework.orm.hibernate3.SessionFactoryUtils; //导入方法依赖的package包/类
/**
* Close the given Session.
* Note that this just applies in single session mode!
* <p>Can be overridden in subclasses, e.g. for flushing the Session before
* closing it. See class-level javadoc for a discussion of flush handling.
* Note that you should also override getSession accordingly, to set
* the flush mode to something else than NEVER.
* @param session the Session used for filtering
* @param sessionFactory the SessionFactory that this filter uses
*/
protected void closeSession(Session session, SessionFactory sessionFactory) {
SessionFactoryUtils.closeSession(session);
}