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

The following examples show how to use org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess. 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: GlobalTemporaryTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #2
Source File: AbstractSharedSessionContract.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #3
Source File: SessionFactoryImpl.java    From lams with 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
Source File: JdbcCoordinatorImpl.java    From lams with 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 #5
Source File: DdlTransactionIsolatorProvidedConnectionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #6
Source File: PersistentTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 File: LogicalConnectionManagedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #8
Source File: JtaIsolationDelegate.java    From lams with 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 #9
Source File: ConnectionAccessLogger.java    From lams with 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 #10
Source File: InlineIdsSubSelectValueListBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #11
Source File: PersistentTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) {
	if ( ! dropIdTables ) {
		return;
	}

	IdTableHelper.INSTANCE.executeIdTableDropStatements( dropTableStatements, jdbcServices, connectionAccess );
}
 
Example #12
Source File: InlineIdsOrClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #13
Source File: JdbcEnvironmentInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #14
Source File: JdbcEnvironmentInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: CteValuesListBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #16
Source File: InlineIdsInClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #17
Source File: HibernateSchemaManagementTool.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #18
Source File: GlobalTemporaryTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	if ( ! dropIdTables ) {
		return;
	}

	IdTableHelper.INSTANCE.executeIdTableDropStatements( dropTableStatements, jdbcServices, connectionAccess );
}
 
Example #19
Source File: ExtractionContextImpl.java    From lams with 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 #20
Source File: LogicalConnectionManagedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #21
Source File: LogicalConnectionManagedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private LogicalConnectionManagedImpl(
		JdbcConnectionAccess jdbcConnectionAccess,
		JdbcSessionContext jdbcSessionContext,
		boolean closed) {
	this( jdbcConnectionAccess, jdbcSessionContext, new ResourceRegistryStandardImpl() );
	this.closed = closed;
}
 
Example #22
Source File: LogicalConnectionManagedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #23
Source File: InlineIdsInClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	// nothing to do
}
 
Example #24
Source File: InlineIdsOrClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	// nothing to do
}
 
Example #25
Source File: InlineIdsSubSelectValueListBulkIdStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	// nothing to do
}
 
Example #26
Source File: AbstractProxySharedSessionContractImplementor.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	return target.getJdbcConnectionAccess();
}
 
Example #27
Source File: AbstractMultiTableBulkIdStrategyImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		SessionFactoryOptions sessionFactoryOptions) {
	// build/get Table representation of the bulk-id tables - subclasses need hooks
	// for each:
	// 		handle DDL
	// 		build insert-select
	//		build id-subselect

	final CT context =  buildPreparationContext();

	initialize( metadata.getMetadataBuildingOptions(), sessionFactoryOptions );

	final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();

	for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
		if ( !IdTableHelper.INSTANCE.needsIdTable( entityBinding ) ) {
			continue;
		}

		final String idTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
				determineIdTableName( jdbcEnvironment, entityBinding ),
				jdbcEnvironment.getDialect()
		);
		final Table idTable = new Table();
		idTable.setName( idTableName );
		idTable.setComment( "Used to hold id values for the " + entityBinding.getEntityName() + " entity" );

		Iterator itr = entityBinding.getTable().getPrimaryKey().getColumnIterator();
		while( itr.hasNext() ) {
			Column column = (Column) itr.next();
			idTable.addColumn( column.clone()  );
		}
		augmentIdTableDefinition( idTable );

		final TT idTableInfo = buildIdTableInfo( entityBinding, idTable, jdbcServices, metadata, context );
		idTableInfoMap.put( entityBinding.getEntityName(), idTableInfo );
	}

	finishPreparation( jdbcServices, connectionAccess, metadata, context );
}
 
Example #28
Source File: AbstractMultiTableBulkIdStrategyImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void finishPreparation(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		CT context) {
}
 
Example #29
Source File: JdbcIsolationDelegate.java    From lams with 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 #30
Source File: CteValuesListBulkIdStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void release(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess) {
	// nothing to do
}