org.hibernate.ConnectionReleaseMode Java Examples
The following examples show how to use
org.hibernate.ConnectionReleaseMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcCoordinatorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private 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; } }
Example #2
Source File: SessionFactoryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
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 ); }
Example #3
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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; } }
Example #4
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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; }
Example #5
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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; }
Example #6
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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; }
Example #7
Source File: JDBCContext.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
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(); } }
Example #8
Source File: SessionFactoryOptionsBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") private PhysicalConnectionHandlingMode interpretConnectionHandlingMode( Map configurationSettings, StandardServiceRegistry serviceRegistry) { final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) ); if ( specifiedHandlingMode != null ) { return specifiedHandlingMode; } final TransactionCoordinatorBuilder transactionCoordinatorBuilder = serviceRegistry.getService( TransactionCoordinatorBuilder.class ); // see if the deprecated ConnectionAcquisitionMode/ConnectionReleaseMode were used.. final ConnectionAcquisitionMode specifiedAcquisitionMode = ConnectionAcquisitionMode.interpret( configurationSettings.get( ACQUIRE_CONNECTIONS ) ); final ConnectionReleaseMode specifiedReleaseMode = ConnectionReleaseMode.interpret( configurationSettings.get( RELEASE_CONNECTIONS ) ); if ( specifiedAcquisitionMode != null || specifiedReleaseMode != null ) { return interpretConnectionHandlingMode( specifiedAcquisitionMode, specifiedReleaseMode, configurationSettings, transactionCoordinatorBuilder ); } return transactionCoordinatorBuilder.getDefaultConnectionHandlingMode(); }
Example #9
Source File: HibernateTransactionManager.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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); }
Example #10
Source File: SessionFactoryOptionsBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") private PhysicalConnectionHandlingMode interpretConnectionHandlingMode( ConnectionAcquisitionMode specifiedAcquisitionMode, ConnectionReleaseMode specifiedReleaseMode, Map configurationSettings, TransactionCoordinatorBuilder transactionCoordinatorBuilder) { DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings(); final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null ? ConnectionAcquisitionMode.AS_NEEDED : specifiedAcquisitionMode; final ConnectionReleaseMode effectiveReleaseMode; if ( specifiedReleaseMode == null ) { // check the actual setting. If we get in here it *should* be "auto" or null final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" ); assert "auto".equalsIgnoreCase( releaseModeName ); // nothing was specified (or someone happened to configure the "magic" value) if ( effectiveAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) { effectiveReleaseMode = ConnectionReleaseMode.ON_CLOSE; } else { effectiveReleaseMode = transactionCoordinatorBuilder.getDefaultConnectionReleaseMode(); } } else { effectiveReleaseMode = specifiedReleaseMode; } return PhysicalConnectionHandlingMode.interpret( effectiveAcquisitionMode, effectiveReleaseMode ); }
Example #11
Source File: SessionFactoryOptionsBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
public void applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) { if ( this.connectionHandlingMode == null ) { this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( ConnectionAcquisitionMode.AS_NEEDED, connectionReleaseMode ); } else { this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( this.connectionHandlingMode.getAcquisitionMode(), connectionReleaseMode ); } }
Example #12
Source File: HibernateTransactionManager.java From spring-analysis-note with MIT License | 5 votes |
/** * 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 */ @SuppressWarnings("deprecation") 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); }
Example #13
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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() ); }
Example #14
Source File: SessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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 ); } }
Example #15
Source File: SessionFactoryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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 ); }
Example #16
Source File: CMTTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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() ); }
Example #17
Source File: AggressiveReleaseTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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" ); }
Example #18
Source File: HibernateTransactionManager.java From java-technology-stack with MIT License | 5 votes |
/** * 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 */ @SuppressWarnings("deprecation") 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); }
Example #19
Source File: LogicalConnectionManagedImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void afterTransaction() { super.afterTransaction(); if ( connectionHandlingMode.getReleaseMode() != ConnectionReleaseMode.ON_CLOSE ) { // NOTE : we check for !ON_CLOSE here (rather than AFTER_TRANSACTION) to also catch AFTER_STATEMENT cases // that were circumvented due to held resources log.debug( "Initiating JDBC connection release from afterTransaction" ); releaseConnection(); } }
Example #20
Source File: LogicalConnectionManagedImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void afterStatement() { super.afterStatement(); if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) { if ( getResourceRegistry().hasRegisteredResources() ) { log.debug( "Skipping aggressive release of JDBC Connection after-statement due to held resources" ); } else { log.debug( "Initiating JDBC connection release from afterStatement" ); releaseConnection(); } } }
Example #21
Source File: LogicalConnectionManagedImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private PhysicalConnectionHandlingMode determineConnectionHandlingMode( PhysicalConnectionHandlingMode connectionHandlingMode, JdbcConnectionAccess jdbcConnectionAccess) { if ( connectionHandlingMode.getReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT && !jdbcConnectionAccess.supportsAggressiveRelease() ) { return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION; } return connectionHandlingMode; }
Example #22
Source File: JdbcCoordinatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void afterStatementExecution() { LOG.tracev( "Starting after statement execution processing [{0}]", getConnectionReleaseMode() ); if ( getConnectionReleaseMode() == 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().afterStatement(); } }
Example #23
Source File: JdbcCoordinatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void afterTransaction() { transactionTimeOutInstant = -1; if ( getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT || getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION ) { this.logicalConnection.afterTransaction(); } }
Example #24
Source File: HibernateTransactionManager.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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 */ @SuppressWarnings("deprecation") 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); }
Example #25
Source File: SessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * 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" ); boolean isRootSession = ois.readBoolean(); connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() ); entityMode = EntityMode.parse( ( String ) ois.readObject() ); autoClear = ois.readBoolean(); flushMode = FlushMode.parse( ( String ) ois.readObject() ); cacheMode = CacheMode.parse( ( String ) ois.readObject() ); flushBeforeCompletionEnabled = ois.readBoolean(); autoCloseSessionEnabled = ois.readBoolean(); fetchProfile = ( String ) ois.readObject(); interceptor = ( Interceptor ) ois.readObject(); factory = SessionFactoryImpl.deserialize( ois ); listeners = factory.getEventListeners(); if ( isRootSession ) { jdbcContext = JDBCContext.deserialize( ois, this, interceptor ); } persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); actionQueue = ActionQueue.deserialize( ois, this ); enabledFilters = ( Map ) ois.readObject(); childSessionsByEntityMode = ( Map ) ois.readObject(); Iterator iter = enabledFilters.values().iterator(); while ( iter.hasNext() ) { ( ( FilterImpl ) iter.next() ).afterDeserialize(factory); } if ( isRootSession && childSessionsByEntityMode != null ) { iter = childSessionsByEntityMode.values().iterator(); while ( iter.hasNext() ) { final SessionImpl child = ( ( SessionImpl ) iter.next() ); child.rootSession = this; child.jdbcContext = this.jdbcContext; } } }
Example #26
Source File: SessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public ConnectionReleaseMode getConnectionReleaseMode() { checkTransactionSynchStatus(); return connectionReleaseMode; }
Example #27
Source File: StatelessSessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public ConnectionReleaseMode getConnectionReleaseMode() { return factory.getSettings().getConnectionReleaseMode(); }
Example #28
Source File: Settings.java From lams with GNU General Public License v2.0 | 4 votes |
public ConnectionReleaseMode getConnectionReleaseMode() { return sessionFactoryOptions.getConnectionReleaseMode(); }
Example #29
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isOnCloseRelease() { return releaseMode == ConnectionReleaseMode.ON_CLOSE; }
Example #30
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isAfterTransactionRelease() { return releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION; }