Java 类org.hibernate.ConnectionReleaseMode 实例源码

项目:lams    文件:TransactionCoordinatorImpl.java   
public TransactionCoordinatorImpl(
        Connection userSuppliedConnection,
        TransactionContext transactionContext) {
    this.transactionContext = transactionContext;
    this.jdbcCoordinator = new JdbcCoordinatorImpl( userSuppliedConnection, this );
    this.transactionEnvironment = transactionContext.getTransactionEnvironment();
    this.transactionFactory = this.transactionEnvironment.getTransactionFactory();
    this.observers = new ArrayList<TransactionObserver>();
    this.synchronizationRegistry = new SynchronizationRegistryImpl();
    reset();

    final boolean registerSynchronization = transactionContext.isAutoCloseSessionEnabled()
            || transactionContext.isFlushBeforeCompletionEnabled()
            || transactionContext.getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION;
    if ( registerSynchronization ) {
        pulse();
    }
}
项目:lams    文件:LogicalConnectionImpl.java   
/**
 * Constructs a LogicalConnectionImpl
 *
 * @param userSuppliedConnection The user-supplied connection
 * @param connectionReleaseMode The connection release mode to use
 * @param jdbcServices JdbcServices
 * @param jdbcConnectionAccess JDBC Connection access
 */
public LogicalConnectionImpl(
        Connection userSuppliedConnection,
        ConnectionReleaseMode connectionReleaseMode,
        JdbcServices jdbcServices,
        JdbcConnectionAccess jdbcConnectionAccess) {
    this(
            connectionReleaseMode,
            jdbcServices,
            jdbcConnectionAccess,
            (userSuppliedConnection != null),
            false,
            new ArrayList<ConnectionObserver>()
    );
    this.physicalConnection = userSuppliedConnection;
}
项目:lams    文件:LogicalConnectionImpl.java   
/**
 * Constructs a LogicalConnectionImpl.  This for used from deserialization
 */
private LogicalConnectionImpl(
        ConnectionReleaseMode connectionReleaseMode,
        JdbcServices jdbcServices,
        JdbcConnectionAccess jdbcConnectionAccess,
        boolean isUserSuppliedConnection,
        boolean isClosed,
        List<ConnectionObserver> observers) {
    this.connectionReleaseMode = determineConnectionReleaseMode(
            jdbcConnectionAccess, isUserSuppliedConnection, connectionReleaseMode
    );
    this.jdbcServices = jdbcServices;
    this.jdbcConnectionAccess = jdbcConnectionAccess;
    this.observers = observers;

    this.isUserSuppliedConnection = isUserSuppliedConnection;
    this.isClosed = isClosed;
}
项目:lams    文件:LogicalConnectionImpl.java   
private static ConnectionReleaseMode determineConnectionReleaseMode(
        JdbcConnectionAccess jdbcConnectionAccess,
        boolean isUserSuppliedConnection,
        ConnectionReleaseMode connectionReleaseMode) {
    if ( isUserSuppliedConnection ) {
        return ConnectionReleaseMode.ON_CLOSE;
    }
    else if ( connectionReleaseMode == ConnectionReleaseMode.AFTER_STATEMENT &&
            ! jdbcConnectionAccess.supportsAggressiveRelease() ) {
        LOG.debug( "Connection provider reports to not support aggressive release; overriding" );
        return ConnectionReleaseMode.AFTER_TRANSACTION;
    }
    else {
        return connectionReleaseMode;
    }
}
项目:cacheonix-core    文件:JDBCContext.java   
public JDBCContext(Context owner, Connection connection, Interceptor interceptor) {
    this.owner = owner;
    this.connectionManager = new ConnectionManager(
            owner.getFactory(),
            this,
            owner.getConnectionReleaseMode(),
            connection,
            interceptor
        );

    final boolean registerSynchronization = owner.isAutoCloseSessionEnabled()
            || owner.isFlushBeforeCompletionEnabled()
            || owner.getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION;
    if ( registerSynchronization ) {
        registerSynchronizationIfPossible();
    }
}
项目:cacheonix-core    文件:ConnectionManager.java   
/**
 * Constructs a ConnectionManager.
 * <p/>
 * This is the form used internally.
 * 
 * @param factory The SessionFactory.
 * @param callback An observer for internal state change.
 * @param releaseMode The mode by which to release JDBC connections.
 * @param connection An externally supplied connection.
 */ 
public ConnectionManager(
        SessionFactoryImplementor factory,
        Callback callback,
        ConnectionReleaseMode releaseMode,
        Connection connection,
        Interceptor interceptor) {
    this.factory = factory;
    this.callback = callback;

    this.interceptor = interceptor;
    this.batcher = factory.getSettings().getBatcherFactory().createBatcher( this, interceptor );

    this.connection = connection;
    wasConnectionSupplied = ( connection != null );

    this.releaseMode = wasConnectionSupplied ? ConnectionReleaseMode.ON_CLOSE : releaseMode;
}
项目:cacheonix-core    文件:ConnectionManager.java   
/**
 * Private constructor used exclusively from custom serialization
 */
private ConnectionManager(
        SessionFactoryImplementor factory,
        Callback callback,
        ConnectionReleaseMode releaseMode,
        Interceptor interceptor,
        boolean wasConnectionSupplied,
        boolean isClosed) {
    this.factory = factory;
    this.callback = callback;

    this.interceptor = interceptor;
    this.batcher = factory.getSettings().getBatcherFactory().createBatcher( this, interceptor );

    this.wasConnectionSupplied = wasConnectionSupplied;
    this.isClosed = isClosed;
    this.releaseMode = wasConnectionSupplied ? ConnectionReleaseMode.ON_CLOSE : releaseMode;
}
项目:cacheonix-core    文件:ConnectionManager.java   
/**
 * Will connections be released after each statement execution?
 * <p/>
 * Connections will be released after each statement if either:<ul>
 * <li>the defined release-mode is {@link ConnectionReleaseMode#AFTER_STATEMENT}; or
 * <li>the defined release-mode is {@link ConnectionReleaseMode#AFTER_TRANSACTION} but
 * we are in auto-commit mode.
 * <p/>
 * release-mode = {@link ConnectionReleaseMode#ON_CLOSE} should [b]never[/b] release
 * a connection.
 *
 * @return True if the connections will be released after each statement; false otherwise.
 */
public boolean isAggressiveRelease() {
    if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
        return true;
    }
    else if ( releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION ) {
        boolean inAutoCommitState;
        try {
            inAutoCommitState = isAutoCommit()&& !callback.isTransactionInProgress();
        }
        catch( SQLException e ) {
            // assume we are in an auto-commit state
            inAutoCommitState = true;
        }
        return inAutoCommitState;
    }
    return false;
}
项目:cacheonix-core    文件:ConnectionManager.java   
/**
 * Modified version of {@link #isAggressiveRelease} which does not force a
 * transaction check.  This is solely used from our {@link #afterTransaction}
 * callback, so no need to do the check; plus it seems to cause problems on
 * websphere (god i love websphere ;)
 * </p>
 * It uses this information to decide if an aggressive release was skipped
 * do to open resources, and if so forces a release.
 *
 * @return True if the connections will be released after each statement; false otherwise.
 */
private boolean isAggressiveReleaseNoTransactionCheck() {
    if ( releaseMode == ConnectionReleaseMode.AFTER_STATEMENT ) {
        return true;
    }
    else {
        boolean inAutoCommitState;
        try {
            inAutoCommitState = isAutoCommit();
        }
        catch( SQLException e ) {
            // assume we are in an auto-commit state
            inAutoCommitState = true;
        }
        return releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION && inAutoCommitState;
    }
}
项目:cacheonix-core    文件:SessionFactoryImpl.java   
public org.hibernate.classic.Session openSession(
        final Connection connection,
        final boolean flushBeforeCompletionEnabled,
        final boolean autoCloseSessionEnabled,
        final ConnectionReleaseMode connectionReleaseMode) throws HibernateException {
    return new SessionImpl(
            connection,
            this,
            true,
            settings.getCacheProvider().nextTimestamp(),
            interceptor,
            settings.getDefaultEntityMode(),
            flushBeforeCompletionEnabled,
            autoCloseSessionEnabled,
            connectionReleaseMode
        );
}
项目:hibernate-examples    文件:AbstractJpaConfiguration.java   
/**
 * JPA 환경 설정 정보
 *
 * @return 설정 정보
 */
public Properties jpaProperties() {
    Properties props = new Properties();

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.HBM2DDL_AUTO, "create"); // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, "100");

    //        props.put(Environment.CACHE_REGION_PREFIX, "hibernate:");

    // NOTE: Naming Strategy (JPA 에서는 HibernatePersistence 를 사용해야 합니다)
    // props.put(HibernatePersistence.NAMING_STRATEGY, getNamingStrategy());

    return props;
}
项目:spring-batch-experiments    文件:JpaConfigBase.java   
public Properties jpaProperties() {
    Properties props = new Properties();

    props.put(Environment.HBM2DDL_AUTO, "create");    // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, 100);
    props.put(Environment.DIALECT, getDialect());

    props.put("jpaDialect", HibernateJpaDialect.class.getName());

    return props;
}
项目:lams    文件:JdbcCoordinatorImpl.java   
@Override
public void afterStatementExecution() {
    LOG.tracev( "Starting after statement execution processing [{0}]", connectionReleaseMode() );
    if ( connectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) {
        if ( ! releasesEnabled ) {
            LOG.debug( "Skipping aggressive release due to manual disabling" );
            return;
        }
        if ( hasRegisteredResources() ) {
            LOG.debug( "Skipping aggressive release due to registered resources" );
            return;
        }
        getLogicalConnection().releaseConnection();
    }
}
项目:lams    文件:JdbcCoordinatorImpl.java   
@Override
public void afterTransaction() {
    transactionTimeOutInstant = -1;
    if ( connectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ||
            connectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION ) {
        if ( hasRegisteredResources() ) {
            LOG.forcingContainerResourceCleanup();
            releaseResources();
        }
        getLogicalConnection().aggressiveRelease();
    }
}
项目:lams    文件:SessionImpl.java   
/**
 * Used by JDK serialization...
 *
 * @param ois The input stream from which we are being read...
 * @throws IOException Indicates a general IO stream exception
 * @throws ClassNotFoundException Indicates a class resolution issue
 */
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    LOG.trace( "Deserializing session" );

    ois.defaultReadObject();

    entityNameResolver = new CoordinatingEntityNameResolver();

    connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
    autoClear = ois.readBoolean();
    autoJoinTransactions = ois.readBoolean();
    flushMode = FlushMode.valueOf( ( String ) ois.readObject() );
    cacheMode = CacheMode.valueOf( ( String ) ois.readObject() );
    flushBeforeCompletionEnabled = ois.readBoolean();
    autoCloseSessionEnabled = ois.readBoolean();
    interceptor = ( Interceptor ) ois.readObject();

    factory = SessionFactoryImpl.deserialize( ois );
    sessionOwner = ( SessionOwner ) ois.readObject();

    transactionCoordinator = TransactionCoordinatorImpl.deserialize( ois, this );

    persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
    actionQueue = ActionQueue.deserialize( ois, this );

    loadQueryInfluencers = (LoadQueryInfluencers) ois.readObject();

    // LoadQueryInfluencers.getEnabledFilters() tries to validate each enabled
    // filter, which will fail when called before FilterImpl.afterDeserialize( factory );
    // Instead lookup the filter by name and then call FilterImpl.afterDeserialize( factory ).
    for ( String filterName : loadQueryInfluencers.getEnabledFilterNames() ) {
        ((FilterImpl) loadQueryInfluencers.getEnabledFilter( filterName )).afterDeserialize( factory );
    }
}
项目:lams    文件:SessionFactoryImpl.java   
public Session openTemporarySession() throws HibernateException {
    return withOptions()
            .autoClose( false )
            .flushBeforeCompletion( false )
            .connectionReleaseMode( ConnectionReleaseMode.AFTER_STATEMENT )
            .openSession();
}
项目:spring4-understanding    文件:HibernateTransactionManager.java   
/**
 * Return whether the given Hibernate Session will always hold the same
 * JDBC Connection. This is used to check whether the transaction manager
 * can safely prepare and clean up the JDBC Connection used for a transaction.
 * <p>The default implementation checks the Session's connection release mode
 * to be "on_close".
 * @param session the Hibernate Session to check
 * @see ConnectionReleaseMode#ON_CLOSE
 */
protected boolean isSameConnectionForEntireSession(Session session) {
    if (!(session instanceof SessionImplementor)) {
        // The best we can do is to assume we're safe.
        return true;
    }
    ConnectionReleaseMode releaseMode =
            ((SessionImplementor) session).getJdbcCoordinator().getConnectionReleaseMode();
    return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode);
}
项目:cacheonix-core    文件:ConnectionManager.java   
public static ConnectionManager deserialize(
        ObjectInputStream ois,
        SessionFactoryImplementor factory,
        Interceptor interceptor,
        ConnectionReleaseMode connectionReleaseMode,
        JDBCContext jdbcContext) throws IOException {
    return new ConnectionManager(
            factory,
            jdbcContext,
            connectionReleaseMode,
            interceptor,
            ois.readBoolean(),
            ois.readBoolean()
    );
}
项目:cacheonix-core    文件:SessionImpl.java   
/**
 * Constructor used for openSession(...) processing, as well as construction
 * of sessions for getCurrentSession().
 *
 * @param connection The user-supplied connection to use for this session.
 * @param factory The factory from which this session was obtained
 * @param autoclose NOT USED
 * @param timestamp The timestamp for this session
 * @param interceptor The interceptor to be applied to this session
 * @param entityMode The entity-mode for this session
 * @param flushBeforeCompletionEnabled Should we auto flush before completion of transaction
 * @param autoCloseSessionEnabled Should we auto close after completion of transaction
 * @param connectionReleaseMode The mode by which we should release JDBC connections.
 */
SessionImpl(
        final Connection connection,
        final SessionFactoryImpl factory,
        final boolean autoclose,
        final long timestamp,
        final Interceptor interceptor,
        final EntityMode entityMode,
        final boolean flushBeforeCompletionEnabled,
        final boolean autoCloseSessionEnabled,
        final ConnectionReleaseMode connectionReleaseMode) {
    super( factory );
    this.rootSession = null;
    this.timestamp = timestamp;
    this.entityMode = entityMode;
    this.interceptor = interceptor;
    this.listeners = factory.getEventListeners();
    this.actionQueue = new ActionQueue( this );
    this.persistenceContext = new StatefulPersistenceContext( this );
    this.flushBeforeCompletionEnabled = flushBeforeCompletionEnabled;
    this.autoCloseSessionEnabled = autoCloseSessionEnabled;
    this.connectionReleaseMode = connectionReleaseMode;
    this.jdbcContext = new JDBCContext( this, connection, interceptor );

    if ( factory.getStatistics().isStatisticsEnabled() ) {
        factory.getStatisticsImplementor().openSession();
    }

    if ( log.isDebugEnabled() ) {
        log.debug( "opened session at timestamp: " + timestamp );
    }
}
项目:cacheonix-core    文件:SessionFactoryImpl.java   
public org.hibernate.classic.Session openTemporarySession() throws HibernateException {
    return new SessionImpl(
            null,
            this,
            true,
            settings.getCacheProvider().nextTimestamp(),
            interceptor,
            settings.getDefaultEntityMode(),
            false,
            false,
            ConnectionReleaseMode.AFTER_STATEMENT
        );
}
项目:cacheonix-core    文件:CMTTest.java   
public void configure(Configuration cfg) {
    cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
    cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
    cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
    cfg.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
    cfg.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
    cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
    cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
    cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
    cfg.setProperty( Environment.DEFAULT_ENTITY_MODE, EntityMode.MAP.toString() );
}
项目:cacheonix-core    文件:AggressiveReleaseTest.java   
public void configure(Configuration cfg) {
    super.configure( cfg );
    cfg.setProperty( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() );
    cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
    cfg.setProperty( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() );
    cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
    cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
    cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
}
项目:hibernate-examples    文件:AbstractHibernateConfiguration.java   
/**
 * Hibernate 환경 설정 정보
 *
 * @return Hibernate 환경 설정 정보를 담은 {@link Properties}
 */
public Properties hibernateProperties() {
    Properties props = new Properties();

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.HBM2DDL_AUTO, "create"); // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.CACHE_REGION_PREFIX, "hibernate:");
    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, "100");

    return props;
}
项目:debop4j    文件:HibernateConfigBase.java   
/** Hibernate 설정 값 */
protected Properties hibernateProperties() {

    Properties props = new Properties();

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.HBM2DDL_AUTO, "create"); // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, "30");

    return props;
}
项目:spring-batch-experiments    文件:JpaConfigBase.java   
public Properties jpaProperties() {
    Properties props = new Properties();

    props.put(Environment.HBM2DDL_AUTO, "create");    // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, 100);
    props.put(Environment.DIALECT, getDialect());

    return props;
}
项目:spring-batch-experiments    文件:JpaConfigBase.java   
public Properties jpaProperties() {
    Properties props = new Properties();

    props.put(Environment.HBM2DDL_AUTO, "create");    // create | spawn | spawn-drop | update | validate | none

    props.put(Environment.FORMAT_SQL, "true");
    props.put(Environment.SHOW_SQL, "true");
    props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE);
    props.put(Environment.AUTOCOMMIT, "true");
    props.put(Environment.STATEMENT_BATCH_SIZE, 100);
    props.put(Environment.DIALECT, getDialect());

    return props;
}
项目:lams    文件:Settings.java   
public ConnectionReleaseMode getConnectionReleaseMode() {
    return connectionReleaseMode;
}
项目:lams    文件:Settings.java   
void setConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
    this.connectionReleaseMode = connectionReleaseMode;
}
项目:lams    文件:JdbcTransactionFactory.java   
@Override
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.ON_CLOSE;
}
项目:lams    文件:JtaTransactionFactory.java   
@Override
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_STATEMENT;
}
项目:lams    文件:CMTTransactionFactory.java   
@Override
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_STATEMENT;
}
项目:lams    文件:JdbcCoordinatorImpl.java   
private ConnectionReleaseMode connectionReleaseMode() {
    return getLogicalConnection().getConnectionReleaseMode();
}
项目:lams    文件:LogicalConnectionImpl.java   
@Override
public ConnectionReleaseMode getConnectionReleaseMode() {
    return connectionReleaseMode;
}
项目:lams    文件:SessionImpl.java   
@Override
public ConnectionReleaseMode getConnectionReleaseMode() {
    return connectionReleaseMode;
}
项目:lams    文件:StatelessSessionImpl.java   
@Override
public ConnectionReleaseMode getConnectionReleaseMode() {
    return factory.getSettings().getConnectionReleaseMode();
}
项目:cacheonix-core    文件:Settings.java   
public ConnectionReleaseMode getConnectionReleaseMode() {
    return connectionReleaseMode;
}
项目:cacheonix-core    文件:Settings.java   
void setConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
    this.connectionReleaseMode = connectionReleaseMode;
}
项目:cacheonix-core    文件:JTATransactionFactory.java   
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_STATEMENT;
}
项目:cacheonix-core    文件:JDBCTransactionFactory.java   
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_TRANSACTION;
}
项目:cacheonix-core    文件:CMTTransactionFactory.java   
public ConnectionReleaseMode getDefaultReleaseMode() {
    return ConnectionReleaseMode.AFTER_STATEMENT;
}