Java Code Examples for org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess

The following examples show how to use org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess. 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
@Override
public void release() {
	JdbcConnectionAccess connectionAccess = jdbcContext.getJdbcConnectionAccess();
	if( !( connectionAccess instanceof JdbcConnectionAccessProvidedConnectionImpl ) ) {
		throw new IllegalStateException(
			"DdlTransactionIsolatorProvidedConnectionImpl should always use a JdbcConnectionAccessProvidedConnectionImpl"
		);
	}
	try {
		// While passing the connection to the releaseConnection method might be suitable for other `JdbcConnectionAccess` implementations,
		// it has no meaning for JdbcConnectionAccessProvidedConnectionImpl because, in this case, the connection is wrapped
		// and we don't have access to it upon releasing via the DdlTransactionIsolatorProvidedConnectionImpl.
		connectionAccess.releaseConnection( null );
	}
	catch (SQLException ignore) {
		LOG.unableToReleaseIsolatedConnection( ignore );
	}
}
 
Example 2
Source Project: lams   Source File: JdbcCoordinatorImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 3
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private JdbcConnectionAccess buildLocalConnectionAccess() {
	return new JdbcConnectionAccess() {
		@Override
		public Connection obtainConnection() throws SQLException {
			return !settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider()
					? serviceRegistry.getService( ConnectionProvider.class ).getConnection()
					: serviceRegistry.getService( MultiTenantConnectionProvider.class ).getAnyConnection();
		}

		@Override
		public void releaseConnection(Connection connection) throws SQLException {
			if ( !settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ) {
				serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection );
			}
			else {
				serviceRegistry.getService( MultiTenantConnectionProvider.class ).releaseAnyConnection( connection );
			}
		}

		@Override
		public boolean supportsAggressiveRelease() {
			return false;
		}
	};
}
 
Example 4
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	// See class-level JavaDocs for a discussion of the concurrent-access safety of this method
	if ( jdbcConnectionAccess == null ) {
		if ( !factory.getSettings().getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ) {
			jdbcConnectionAccess = new NonContextualJdbcConnectionAccess(
					getEventListenerManager(),
					factory.getServiceRegistry().getService( ConnectionProvider.class )
			);
		}
		else {
			jdbcConnectionAccess = new ContextualJdbcConnectionAccess(
					getTenantIdentifier(),
					getEventListenerManager(),
					factory.getServiceRegistry().getService( MultiTenantConnectionProvider.class )
			);
		}
	}
	return jdbcConnectionAccess;
}
 
Example 5
@Override
protected void finishPreparation(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	IdTableHelper.INSTANCE.executeIdTableCreationStatements(
			context.creationStatements,
			jdbcServices,
			connectionAccess
	);

	this.dropTableStatements = dropIdTables
			? context.dropStatements.toArray( new String[ context.dropStatements.size() ] )
			: null;
}
 
Example 6
@Override
protected void finishPreparation(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	IdTableHelper.INSTANCE.executeIdTableCreationStatements(
			context.creationStatements,
			jdbcServices,
			connectionAccess
	);

	this.dropTableStatements = dropIdTables
			? context.dropStatements.toArray( new String[ context.dropStatements.size() ] )
			: null;
}
 
Example 7
Source Project: lams   Source File: JtaIsolationDelegate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public JtaIsolationDelegate(
		JdbcConnectionAccess connectionAccess,
		SqlExceptionHelper sqlExceptionHelper,
		TransactionManager transactionManager) {
	this.connectionAccess = connectionAccess;
	this.sqlExceptionHelper = sqlExceptionHelper;
	this.transactionManager = transactionManager;
}
 
Example 8
public LogicalConnectionManagedImpl(
		JdbcConnectionAccess jdbcConnectionAccess,
		JdbcSessionContext jdbcSessionContext,
		ResourceRegistry resourceRegistry) {
	this.jdbcConnectionAccess = jdbcConnectionAccess;
	this.observer = jdbcSessionContext.getObserver();
	this.resourceRegistry = resourceRegistry;

	this.connectionHandlingMode = determineConnectionHandlingMode(
			jdbcSessionContext.getPhysicalConnectionHandlingMode(),
			jdbcConnectionAccess

	);

	this.sqlExceptionHelper = jdbcSessionContext.getServiceRegistry()
			.getService( JdbcServices.class )
			.getSqlExceptionHelper();

	if ( connectionHandlingMode.getAcquisitionMode() == ConnectionAcquisitionMode.IMMEDIATELY ) {
		acquireConnectionIfNeeded();
	}

	this.providerDisablesAutoCommit = jdbcSessionContext.doesConnectionProviderDisableAutoCommit();
	if ( providerDisablesAutoCommit ) {
		log.debug(
				"`hibernate.connection.provider_disables_autocommit` was enabled.  This setting should only be " +
						"enabled when you are certain that the Connections given to Hibernate by the " +
						"ConnectionProvider have auto-commit disabled.  Enabling this setting when the " +
						"Connections do not have auto-commit disabled will lead to Hibernate executing " +
						"SQL operations outside of any JDBC/SQL transaction."
		);
	}
}
 
Example 9
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 10
private LogicalConnectionManagedImpl(
		JdbcConnectionAccess jdbcConnectionAccess,
		JdbcSessionContext jdbcSessionContext,
		boolean closed) {
	this( jdbcConnectionAccess, jdbcSessionContext, new ResourceRegistryStandardImpl() );
	this.closed = closed;
}
 
Example 11
public static LogicalConnectionManagedImpl deserialize(
		ObjectInputStream ois,
		JdbcConnectionAccess jdbcConnectionAccess,
		JdbcSessionContext jdbcSessionContext) throws IOException, ClassNotFoundException {
	final boolean isClosed = ois.readBoolean();
	return new LogicalConnectionManagedImpl( jdbcConnectionAccess, jdbcSessionContext, isClosed );
}
 
Example 12
Source Project: lams   Source File: ExtractionContextImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ExtractionContextImpl(
		ServiceRegistry serviceRegistry,
		JdbcEnvironment jdbcEnvironment,
		JdbcConnectionAccess jdbcConnectionAccess,
		DatabaseObjectAccess registeredTableAccess,
		Identifier defaultCatalogName,
		Identifier defaultSchemaName) {
	this.serviceRegistry = serviceRegistry;
	this.jdbcEnvironment = jdbcEnvironment;
	this.jdbcConnectionAccess = jdbcConnectionAccess;
	this.registeredTableAccess = registeredTableAccess;
	this.defaultCatalogName = defaultCatalogName;
	this.defaultSchemaName = defaultSchemaName;
}
 
Example 13
private JdbcContextImpl(
		JdbcConnectionAccess jdbcConnectionAccess,
		Dialect dialect,
		SqlStatementLogger sqlStatementLogger,
		SqlExceptionHelper sqlExceptionHelper,
		ServiceRegistry serviceRegistry) {
	this.jdbcConnectionAccess = jdbcConnectionAccess;
	this.dialect = dialect;
	this.sqlStatementLogger = sqlStatementLogger;
	this.sqlExceptionHelper = sqlExceptionHelper;
	this.serviceRegistry = serviceRegistry;
}
 
Example 14
private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues, ServiceRegistryImplementor registry) {
	final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy(
			configValues
	);
	if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
		ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
		return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
	}
	else {
		final MultiTenantConnectionProvider multiTenantConnectionProvider = registry.getService( MultiTenantConnectionProvider.class );
		return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
	}
}
 
Example 15
public static JdbcConnectionAccess buildBootstrapJdbcConnectionAccess(
		MultiTenancyStrategy multiTenancyStrategy,
		ServiceRegistryImplementor registry) {
	if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
		ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
		return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
	}
	else {
		final MultiTenantConnectionProvider multiTenantConnectionProvider = registry.getService( MultiTenantConnectionProvider.class );
		return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
	}
}
 
Example 16
Source Project: lams   Source File: ConnectionAccessLogger.java    License: GNU General Public License v2.0 5 votes vote down vote up
@LogMessage(level = INFO)
@Message(
		value = "Connection obtained from JdbcConnectionAccess [%s] for (non-JTA) DDL execution was not in auto-commit mode; " +
				"the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.",
		id = 10001501
)
void informConnectionLocalTransactionForNonJtaDdl(JdbcConnectionAccess jdbcConnectionAccess);
 
Example 17
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example 18
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	if ( ! dropIdTables ) {
		return;
	}

	IdTableHelper.INSTANCE.executeIdTableDropStatements( dropTableStatements, jdbcServices, connectionAccess );
}
 
Example 19
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example 20
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example 21
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example 22
@Override
public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) {
	if ( ! dropIdTables ) {
		return;
	}

	IdTableHelper.INSTANCE.executeIdTableDropStatements( dropTableStatements, jdbcServices, connectionAccess );
}
 
Example 23
Source Project: lams   Source File: JdbcIsolationDelegate.java    License: GNU General Public License v2.0 4 votes vote down vote up
public JdbcIsolationDelegate(JdbcConnectionAccess connectionAccess, SqlExceptionHelper sqlExceptionHelper) {
	this.connectionAccess = connectionAccess;
	this.sqlExceptionHelper = sqlExceptionHelper;
}
 
Example 24
Source Project: lams   Source File: JdbcIsolationDelegate.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected JdbcConnectionAccess jdbcConnectionAccess() {
	return this.connectionAccess;
}
 
Example 25
Source Project: lams   Source File: JtaIsolationDelegate.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected JdbcConnectionAccess jdbcConnectionAccess() {
	return this.connectionAccess;
}
 
Example 26
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	return jdbcConnectionAccess;
}
 
Example 27
Source Project: lams   Source File: SchemaDropperImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	return jdbcConnectionAccess;
}
 
Example 28
Source Project: lams   Source File: JdbcServicesImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public JdbcConnectionAccess getBootstrapJdbcConnectionAccess() {
	return JdbcEnvironmentInitiator.buildBootstrapJdbcConnectionAccess( multiTenancyStrategy, serviceRegistry );
}
 
Example 29
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	return delegate.getJdbcConnectionAccess();
}
 
Example 30
@Override
public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) {
	// nothing to do
}