Examples of SessionHolder


Examples of org.springframework.orm.hibernate3.SessionHolder

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

Examples of org.springframework.orm.hibernate3.SessionHolder

      }
    }
    else {
      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());
      }
View Full Code Here

Examples of org.springframework.orm.hibernate3.SessionHolder

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

          AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(sessionFactory, sessionHolder);
          asyncManager.registerCallableInterceptor(key, interceptor);
          asyncManager.registerDeferredResultInterceptor(key, interceptor);
        }
      }
    }
    else {
      // deferred close mode
      Assert.state(!isAsyncStarted(request), "Deferred close mode is not supported on async dispatches");
      if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
        // Do not modify deferred close: just set the participate flag.
        participate = true;
      }
      else {
        SessionFactoryUtils.initDeferredClose(sessionFactory);
      }
    }

    try {
      filterChain.doFilter(request, response);
    }
    finally {
      if (!participate) {
        if (isSingleSession()) {
          // single session mode
          SessionHolder sessionHolder =
              (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
          if (!isAsyncStarted(request)) {
            logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");
            closeSession(sessionHolder.getSession(), sessionFactory);
          }
        }
        else {
          // deferred close mode
          SessionFactoryUtils.processDeferredClose(sessionFactory);
View Full Code Here

Examples of org.springframework.orm.hibernate3.SessionHolder

    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

Examples of org.springframework.orm.hibernate4.SessionHolder

      participate = true;
    }
    else {
      logger.debug("Opening Hibernate Session in OpenSessionInViewFilter");
      Session session = openSession(sessionFactory);
      TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    }

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

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

Examples of org.springframework.orm.hibernate4.SessionHolder

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

Examples of org.springframework.orm.hibernate4.SessionHolder

      else {
        request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
      }
    }
    else {
      SessionHolder sessionHolder =
          (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
      logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor");
      SessionFactoryUtils.closeSession(sessionHolder.getSession());
    }
  }
View Full Code Here

Examples of org.springframework.orm.hibernate4.SessionHolder

  private SessionFactory sessionFactory;

  @Test(expectedExceptions = IllegalTransactionStateException.class)
  public void testTransactionless() {
    Session session = sessionFactory.openSession();
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
    try {
      assert bookDao.all().isEmpty();
    } finally {
      TransactionSynchronizationManager.unbindResource(sessionFactory);
      SessionFactoryUtils.closeSession(session);
View Full Code Here

Examples of org.springframework.orm.hibernate4.SessionHolder

    session.getScope().put(PERSISTENCE_CONTEXT_ATTRIBUTE, hibernateSession);
  }

  private void bind(Session session) {
    Object sessionHolder = (hibernate3Present ?
        new org.springframework.orm.hibernate3.SessionHolder(session) : new SessionHolder(session));
    TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
  }
View Full Code Here

Examples of org.springframework.orm.hibernate4.SessionHolder

                .getResource(this.sessionFactory);

        if (value instanceof Session) {
            return (Session) value;
        } else if (value instanceof SessionHolder) {
            SessionHolder sessionHolder = (SessionHolder) value;
            Session session = sessionHolder.getSession();

            if (TransactionSynchronizationManager.isSynchronizationActive()
                    && !sessionHolder.isSynchronizedWithTransaction()) {
                TransactionSynchronizationManager
                        .registerSynchronization(new SpringSessionSynchronization(
                                sessionHolder, this.sessionFactory));
                sessionHolder.setSynchronizedWithTransaction(true);

                // Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
                // with FlushMode.MANUAL, which needs to allow flushing within the transaction.
                FlushMode flushMode = session.getFlushMode();

                if (FlushMode.isManualFlushMode(flushMode)
                        && !TransactionSynchronizationManager
                                .isCurrentTransactionReadOnly()) {
                    session.setFlushMode(FlushMode.AUTO);
                    sessionHolder.setPreviousFlushMode(flushMode);
                }
            }

            return session;
        } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.