当前位置: 首页>>代码示例>>Java>>正文


Java SessionFactoryUtils.closeSession方法代码示例

本文整理汇总了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();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:OpenSessionInterceptor.java

示例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());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:OpenSessionInViewInterceptor.java

示例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());
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:OpenSessionInViewInterceptor.java

示例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());
    }
}
 
开发者ID:psramkumar,项目名称:grails-jsf2-plugin,代码行数:17,代码来源:GrailsHibernatePhaseListener.java

示例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;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:15,代码来源:HibernateDao.java

示例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();
	}
}
 
开发者ID:MobileManAG,项目名称:Project-H-Backend,代码行数:18,代码来源:TestCaseBase.java

示例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());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:AsyncRequestInterceptor.java

示例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());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:7,代码来源:AsyncRequestInterceptor.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:OpenSessionInViewFilter.java


注:本文中的org.springframework.orm.hibernate3.SessionFactoryUtils.closeSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。