Java Code Examples for org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode

The following examples show how to use org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode. These examples are extracted from open source projects. 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
protected Properties additionalProperties() {
    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", hibernateDialect);
    properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
    properties.put(
        "hibernate.integrator_provider",
            (IntegratorProvider) () -> Collections.singletonList(
                new ClassImportIntegrator(Arrays.asList(PostDTO.class))
            )
    );
    properties.put(
        AvailableSettings.CONNECTION_HANDLING,
        //PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT
        PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION
    );
    return properties;
}
 
Example 2
/**
 * 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
 * @return Whether the same connection is needed for the whole session
 */
protected boolean isSameConnectionForEntireSession(Session session) {
    if (!(session instanceof SessionImplementor)) {
        // The best we can do is to assume we're safe.
        return true;
    }
    PhysicalConnectionHandlingMode releaseMode =
            ((SessionImplementor) session).getJdbcCoordinator()
                    .getLogicalConnection()
                    .getConnectionHandlingMode();
    return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_HOLD.equals(releaseMode);
}
 
Example 3
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 4
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Session openTemporarySession() throws HibernateException {
	return withOptions()
			.autoClose( false )
			.flushMode( FlushMode.MANUAL )
			.connectionHandlingMode( PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT )
			.openSession();
}
 
Example 5
@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 6
@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 7
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 8
protected void additionalProperties(Properties properties) {
    DataSource actualDataSource = (DataSource) properties
        .get(AvailableSettings.DATASOURCE);

    properties.put(
        AvailableSettings.CONNECTION_PROVIDER,
        new ThreadLocalDatasourceConnectionProvider(actualDataSource)
    );

    properties.put(
        AvailableSettings.CONNECTION_HANDLING,
        PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT
    );

    properties.put(
        AvailableSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT,
        Boolean.TRUE.toString()
    );

    properties.put(
        AvailableSettings.GENERATE_STATISTICS,
        Boolean.TRUE.toString()
    );

    properties.put(
        StatisticsInitiator.STATS_BUILDER,
        TransactionStatisticsFactory.class.getName()
    );
}
 
Example 9
@Override
public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() {
	return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION;
}
 
Example 10
@Override
public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() {
	// todo : I want to change this to PhysicalConnectionHandlingMode#IMMEDIATE_ACQUISITION_AND_HOLD
	return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
}
 
Example 11
@Override
public PhysicalConnectionHandlingMode getConnectionHandlingMode() {
	return PhysicalConnectionHandlingMode.IMMEDIATE_ACQUISITION_AND_HOLD;
}
 
Example 12
@Override
public PhysicalConnectionHandlingMode getConnectionHandlingMode() {
	return connectionHandlingMode;
}
 
Example 13
@Override
public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) {
	delegate.connectionHandlingMode( mode );
	return getThis();
}
 
Example 14
@Override
public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) {
	delegate.connectionHandlingMode( mode );
	return getThis();
}
 
Example 15
Source Project: lams   Source File: JdbcSessionContextImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
	return connectionHandlingMode;
}
 
Example 16
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
	return connectionHandlingMode;
}
 
Example 17
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
	return null;
}
 
Example 18
@Override
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
	return delegate.getPhysicalConnectionHandlingMode();
}
 
Example 19
@Override
public T applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) {
	delegate.applyConnectionHandlingMode( connectionHandlingMode );
	return getThis();
}
 
Example 20
@Override
public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {
	return connectionHandlingMode;
}
 
Example 21
public void applyConnectionHandlingMode(PhysicalConnectionHandlingMode mode) {
	this.connectionHandlingMode = mode;
}
 
Example 22
@Override
public SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) {
	this.optionsBuilder.applyConnectionHandlingMode( connectionHandlingMode );
	return this;
}
 
Example 23
Source Project: lams   Source File: SessionBuilder.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Signifies that the connection release mode from the original session should be used to create the new session.
 *
 * @param mode The connection handling mode to use.
 *
 * @return {@code this}, for method chaining
 */
T connectionHandlingMode(PhysicalConnectionHandlingMode mode);
 
Example 24
Source Project: lams   Source File: JdbcCoordinator.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * The mode for physical handling of the JDBC Connection
 *
 * @return The JDBC Connection handlng mode
 *
 * @deprecated (since 5.2) access via {@link #getLogicalConnection} instead
 */
@Deprecated
default PhysicalConnectionHandlingMode getConnectionHandlingMode() {
	return getLogicalConnection().getConnectionHandlingMode();
}
 
Example 25
Source Project: lams   Source File: SessionFactoryBuilder.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Apply the specified handling mode for JDBC connections
 *
 * @param connectionHandlingMode The handling mode to apply
 *
 * @return {@code this}, for method chaining
 *
 * @see org.hibernate.cfg.AvailableSettings#ACQUIRE_CONNECTIONS
 * @see org.hibernate.cfg.AvailableSettings#RELEASE_CONNECTIONS
 * @see org.hibernate.ConnectionAcquisitionMode
 * @see ConnectionReleaseMode
 */
SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode);
 
Example 26
PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode(); 
Example 27
PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode(); 
Example 28
PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode();