Package org.springframework.orm.hibernate4

Examples of org.springframework.orm.hibernate4.HibernateTemplateTests


    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);
View Full Code Here


      request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
    }
    else {
      logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
      Session session = openSession();
      SessionHolder sessionHolder = new SessionHolder(session);
      TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

      AsyncRequestInterceptor asyncRequestInterceptor =
          new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
      asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
View Full Code Here

   * @see org.springframework.transaction.support.TransactionSynchronizationManager
   */
  @Override
  public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
    if (!decrementParticipateCount(request)) {
      SessionHolder sessionHolder =
          (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
      logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor");
      SessionFactoryUtils.closeSession(sessionHolder.getSession());

    }
  }
View Full Code Here

    else {
      boolean isFirstRequest = !isAsyncDispatch(request);
      if (isFirstRequest || !applySessionBindingInterceptor(asyncManager, key)) {
        logger.debug("Opening Hibernate Session in OpenSessionInViewFilter");
        Session session = openSession(sessionFactory);
        SessionHolder sessionHolder = new SessionHolder(session);
        TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);

        AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(sessionFactory, sessionHolder);
        asyncManager.registerCallableInterceptor(key, interceptor);
        asyncManager.registerDeferredResultInterceptor(key, interceptor);
      }
    }

    try {
      filterChain.doFilter(request, response);
    }

    finally {
      if (!participate) {
        SessionHolder sessionHolder =
            (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
        if (!isAsyncStarted(request)) {
          logger.debug("Closing Hibernate Session in OpenSessionInViewFilter");
          SessionFactoryUtils.closeSession(sessionHolder.getSession());
        }
      }
    }
  }
View Full Code Here

  private UserRepository userRepository;

  @Before
  public void openSession() {
    Session session = sessionFactory.openSession();
    TransactionSynchronizationManager.bindResource( sessionFactory, new SessionHolder( session ) );
  }
View Full Code Here

TOP

Related Classes of org.springframework.orm.hibernate4.HibernateTemplateTests

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.