Java 类org.hibernate.context.internal.ThreadLocalSessionContext 实例源码

项目:lams    文件:SessionFactoryImpl.java   
private CurrentSessionContext buildCurrentSessionContext() {
    String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
    // for backward-compatibility
    if ( impl == null ) {
        if ( canAccessTransactionManager() ) {
            impl = "jta";
        }
        else {
            return null;
        }
    }

    if ( "jta".equals( impl ) ) {
        if ( ! transactionFactory().compatibleWithJtaSynchronization() ) {
            LOG.autoFlushWillNotWork();
        }
        return new JTASessionContext( this );
    }
    else if ( "thread".equals( impl ) ) {
        return new ThreadLocalSessionContext( this );
    }
    else if ( "managed".equals( impl ) ) {
        return new ManagedSessionContext( this );
    }
    else {
        try {
            Class implClass = serviceRegistry.getService( ClassLoaderService.class ).classForName( impl );
            return ( CurrentSessionContext ) implClass
                    .getConstructor( new Class[] { SessionFactoryImplementor.class } )
                    .newInstance( this );
        }
        catch( Throwable t ) {
            LOG.unableToConstructCurrentSessionContext( impl, t );
            return null;
        }
    }
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
private CurrentSessionContext buildCurrentSessionContext() {
    String impl = properties
            .getProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS);
    // for backward-compatibility
    if (impl == null) {
        if (canAccessTransactionManager()) {
            impl = "jta";
        } else {
            return null;
        }
    }

    if ("jta".equals(impl)) {
        if (!transactionFactory().compatibleWithJtaSynchronization()) {
            LOG.autoFlushWillNotWork();
        }
        return new JTASessionContext(this);
    } else if ("thread".equals(impl)) {
        return new ThreadLocalSessionContext(this);
    } else if ("managed".equals(impl)) {
        return new ManagedSessionContext(this);
    } else {
        try {
            Class implClass = serviceRegistry.getService(
                    ClassLoaderService.class).classForName(impl);
            return (CurrentSessionContext) implClass.getConstructor(
                    new Class[] { SessionFactoryImplementor.class })
                    .newInstance(this);
        } catch (Throwable t) {
            LOG.unableToConstructCurrentSessionContext(impl, t);
            return null;
        }
    }
}
项目:Gestion    文件:HibernateUtil.java   
public static void openSessionAndBindToThread() {
    Session session = sessionFactory.openSession();
    ThreadLocalSessionContext.bind(session);
}
项目:Gestion    文件:HibernateUtil.java   
public static void closeSessionAndUnbindFromThread() {
    Session session = ThreadLocalSessionContext.unbind(sessionFactory);
    if (session != null) {
        session.close();
    }
}