Package org.hibernate.classic

Examples of org.hibernate.classic.Session


  public ThreadLocalSessionContext(SessionFactoryImplementor factory) {
    this.factory = factory;
  }

  public final Session currentSession() throws HibernateException {
    Session current = existingSession( factory );
    if (current == null) {
      current = buildOrObtainSession();
      // register a cleanup synch
      current.getTransaction().registerSynchronization( buildCleanupSynch() );
      // wrap the session in the transaction-protection proxy
      if ( needsWrapping( current ) ) {
        current = wrap( current );
      }
      // then bind it
View Full Code Here


    return factory.getSettings().getConnectionReleaseMode();
  }

  protected Session wrap(Session session) {
    TransactionProtectionWrapper wrapper = new TransactionProtectionWrapper( session );
    Session wrapped = ( Session ) Proxy.newProxyInstance(
        Session.class.getClassLoader(),
            SESS_PROXY_INTERFACES,
            wrapper
      );
    // yick!  need this for proper serialization/deserialization handling...
View Full Code Here

    cleanupAnyOrphanedSession( factory );
    doBind( session, factory );
  }

  private static void cleanupAnyOrphanedSession(SessionFactory factory) {
    Session orphan = doUnbind( factory, false );
    if ( orphan != null ) {
      log.warn( "Already session bound on call to bind(); make sure you clean up your sessions!" );
      try {
        if ( orphan.getTransaction() != null && orphan.getTransaction().isActive() ) {
          try {
            orphan.getTransaction().rollback();
          }
          catch( Throwable t ) {
            log.debug( "Unable to rollback transaction for orphaned session", t );
          }
        }
        orphan.close();
      }
      catch( Throwable t ) {
        log.debug( "Unable to close orphaned session", t );
      }
    }
View Full Code Here

    sessionMap.put( factory, session );
  }

  private static Session doUnbind(SessionFactory factory, boolean releaseMapIfEmpty) {
    Map sessionMap = sessionMap();
    Session session = null;
    if ( sessionMap != null ) {
      session = ( Session ) sessionMap.remove( factory );
      if ( releaseMapIfEmpty && sessionMap.isEmpty() ) {
        context.set( null );
      }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public Session currentSession() {
    Session current = existingSession( factory );
    if ( current == null ) {
      throw new HibernateException( "No session currently bound to execution context" );
    }
    return current;
  }
View Full Code Here

   *
   * @param factory The factory for which to unbind the current session.
   * @return The bound session if one, else null.
   */
  public static Session unbind(SessionFactory factory) {
    Session existing = null;
    Map sessionMap = sessionMap();
    if ( sessionMap != null ) {
      existing = ( Session ) sessionMap.remove( factory );
      doCleanup();
    }
View Full Code Here

    final Object txnIdentifier = factory.getSettings().getTransactionManagerLookup() == null
        ? txn
        : factory.getSettings().getTransactionManagerLookup().getTransactionIdentifier( txn );

    Session currentSession = ( Session ) currentSessionMap.get( txnIdentifier );

    if ( currentSession == null ) {
      currentSession = buildOrObtainSession();

      try {
        txn.registerSynchronization( buildCleanupSynch( txnIdentifier ) );
      }
      catch ( Throwable t ) {
        try {
          currentSession.close();
        }
        catch ( Throwable ignore ) {
          log.debug( "Unable to release generated current-session on failed synch registration", ignore );
        }
        throw new HibernateException( "Unable to register cleanup Synchronization with TransactionManager" );
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public final Session currentSession() throws HibernateException {
    Session current = existingSession( factory );
    if (current == null) {
      current = buildOrObtainSession();
      // register a cleanup synch
      current.getTransaction().registerSynchronization( buildCleanupSynch() );
      // wrap the session in the transaction-protection proxy
      if ( needsWrapping( current ) ) {
        current = wrap( current );
      }
      // then bind it
View Full Code Here

    return factory.getSettings().getConnectionReleaseMode();
  }

  protected Session wrap(Session session) {
    TransactionProtectionWrapper wrapper = new TransactionProtectionWrapper( session );
    Session wrapped = ( Session ) Proxy.newProxyInstance(
        Session.class.getClassLoader(),
            SESS_PROXY_INTERFACES,
            wrapper
      );
    // yick!  need this for proper serialization/deserialization handling...
View Full Code Here

    cleanupAnyOrphanedSession( factory );
    doBind( session, factory );
  }

  private static void cleanupAnyOrphanedSession(SessionFactory factory) {
    Session orphan = doUnbind( factory, false );
    if ( orphan != null ) {
      log.warn( "Already session bound on call to bind(); make sure you clean up your sessions!" );
      try {
        if ( orphan.getTransaction() != null && orphan.getTransaction().isActive() ) {
          try {
            orphan.getTransaction().rollback();
          }
          catch( Throwable t ) {
            log.debug( "Unable to rollback transaction for orphaned session", t );
          }
        }
        orphan.close();
      }
      catch( Throwable t ) {
        log.debug( "Unable to close orphaned session", t );
      }
    }
View Full Code Here

TOP

Related Classes of org.hibernate.classic.Session

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.