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


Java SessionHolder类代码示例

本文整理汇总了Java中org.springframework.orm.hibernate3.SessionHolder的典型用法代码示例。如果您正苦于以下问题:Java SessionHolder类的具体用法?Java SessionHolder怎么用?Java SessionHolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SessionHolder类属于org.springframework.orm.hibernate3包,在下文中一共展示了SessionHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invoke

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的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: postHandle

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
/**
 * Flush the Hibernate {@code Session} before view rendering, if necessary.
 * <p>Note that this just applies in {@link #isSingleSession() single session mode}!
 * <p>The default is {@code FLUSH_NEVER} to avoid this extra flushing,
 * assuming that service layer transactions have flushed their changes on commit.
 * @see #setFlushMode
 */
@Override
public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
	if (isSingleSession()) {
		// Only potentially flush in single session mode.
		SessionHolder sessionHolder =
				(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
		logger.debug("Flushing single Hibernate Session in OpenSessionInViewInterceptor");
		try {
			flushIfNecessary(sessionHolder.getSession(), false);
		}
		catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:OpenSessionInViewInterceptor.java

示例3: afterCompletion

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的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

示例4: afterCompletion

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的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

示例5: openReadOnlyConnection

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
private void openReadOnlyConnection(final HttpServletRequest request) {
    if (noTransaction(request)) {
        return;
    }
    logDebug(request, "Opening read-only transaction for include");

    final Connection connection = (Connection) TransactionSynchronizationManager.getResource(connectionProvider);

    final SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    final Session session = holder.getSession();
    session.setFlushMode(FlushMode.MANUAL);
    session.setDefaultReadOnly(true);
    session.reconnect(connection);

    TransactionSynchronizationManager.setCurrentTransactionReadOnly(true);
}
 
开发者ID:crypto-coder,项目名称:open-cyclos,代码行数:17,代码来源:CyclosRequestProcessor.java

示例6: unbindSession

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的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

示例7: preHandle

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:OpenSessionInViewInterceptor.java

示例8: doGetActivePersistenceContext

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
@Override
   protected Session doGetActivePersistenceContext(Object testObject) {
	SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(getPersistenceUnit(testObject));
   	if (sessionHolder != null && sessionHolder.getSession() != null && sessionHolder.getSession().isOpen()) {
   		return sessionHolder.getSession();
   	}
   	return null;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:9,代码来源:HibernateModule.java

示例9: tearDown

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的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

示例10: setUp

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
public void setUp()
	throws Exception
{
	SessionFactory sf = (SessionFactory) this.context.getBean("sessionFactory");
	//Session s = SessionFactoryUtils.getSession(sessionFactory, true);
	// open and bind the session for this test thread.
	Session s = sf.openSession();
	TransactionSynchronizationManager.bindResource(sf, new SessionHolder(s));
}
 
开发者ID:iwethey,项目名称:iwethey,代码行数:10,代码来源:HibernateTestHarness.java

示例11: tearDown

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
public void tearDown()
	throws Exception
{
	SessionFactory sf = (SessionFactory) this.context.getBean("sessionFactory");
	SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
	Session s = holder.getSession(); 
	s.flush();
	TransactionSynchronizationManager.unbindResource(sf);
	//SessionFactoryUtils.closeSessionIfNecessary(s, sf);
	SessionFactoryUtils.releaseSession(s, sf);
}
 
开发者ID:iwethey,项目名称:iwethey,代码行数:12,代码来源:HibernateTestHarness.java

示例12: openSession

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
public static boolean openSession(SessionFactory sessionFactory) {
boolean participate = TransactionSynchronizationManager.hasResource(sessionFactory);
if (!participate) {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(org.hibernate.FlushMode.ALWAYS);
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
}
return participate;
   }
 
开发者ID:EsupPortail,项目名称:esup-smsu,代码行数:10,代码来源:HibernateUtils.java

示例13: openSession

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
@Before
public void openSession()  throws Exception {
    session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(FlushMode.MANUAL);//MANUAL
    TransactionSynchronizationManager.bindResource(sessionFactory,new SessionHolder(session));
   

}
 
开发者ID:VonChange,项目名称:haloDao-Hibernate3,代码行数:9,代码来源:BaseServiceTestCase.java

示例14: preHandle

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:45,代码来源:OpenSessionInViewInterceptor.java

示例15: postHandle

import org.springframework.orm.hibernate3.SessionHolder; //导入依赖的package包/类
/**
 * Flush the Hibernate {@code Session} before view rendering, if necessary.
 * <p>Note that this just applies in {@link #isSingleSession() single session mode}!
 * <p>The default is {@code FLUSH_NEVER} to avoid this extra flushing,
 * assuming that service layer transactions have flushed their changes on commit.
 * @see #setFlushMode
 */
public void postHandle(WebRequest request, ModelMap model) throws DataAccessException {
	if (isSingleSession()) {
		// Only potentially flush in single session mode.
		SessionHolder sessionHolder =
				(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
		logger.debug("Flushing single Hibernate Session in OpenSessionInViewInterceptor");
		try {
			flushIfNecessary(sessionHolder.getSession(), false);
		}
		catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:OpenSessionInViewInterceptor.java


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