Package org.springframework.orm.hibernate4

Examples of org.springframework.orm.hibernate4.HibernateTransactionManager


      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


      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

      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

  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

    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

                .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

    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

TOP

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

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.