Java 类org.hibernate.context.spi.CurrentSessionContext 实例源码

项目: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;
        }
    }
}