/** * 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; }
/** * 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; }
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; } }
@Override public JdbcConnectionAccess getJdbcConnectionAccess() { if ( jdbcConnectionAccess == null ) { if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) { jdbcConnectionAccess = new NonContextualJdbcConnectionAccess( getEventListenerManager(), factory.getServiceRegistry().getService( ConnectionProvider.class ) ); } else { jdbcConnectionAccess = new ContextualJdbcConnectionAccess( getEventListenerManager(), factory.getServiceRegistry().getService( MultiTenantConnectionProvider.class ) ); } } return jdbcConnectionAccess; }
private JdbcConnectionAccess buildLocalConnectionAccess() { return new JdbcConnectionAccess() { @Override public Connection obtainConnection() throws SQLException { return settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE ? serviceRegistry.getService( ConnectionProvider.class ).getConnection() : serviceRegistry.getService( MultiTenantConnectionProvider.class ).getAnyConnection(); } @Override public void releaseConnection(Connection connection) throws SQLException { if ( settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE ) { serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection ); } else { serviceRegistry.getService( MultiTenantConnectionProvider.class ).releaseAnyConnection( connection ); } } @Override public boolean supportsAggressiveRelease() { return false; } }; }
private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues) { final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues ); if ( MultiTenancyStrategy.NONE == multiTenancyStrategy ) { connectionProvider = serviceRegistry.getService( ConnectionProvider.class ); return new ConnectionProviderJdbcConnectionAccess( connectionProvider ); } else { connectionProvider = null; final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class ); return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider ); } }
@Override public void prepare( JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings) { this.catalog = ConfigurationHelper.getString( CATALOG, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_CATALOG, settings ) ); this.schema = ConfigurationHelper.getString( SCHEMA, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_SCHEMA, settings ) ); this.cleanUpTables = ConfigurationHelper.getBoolean( CLEAN_UP_ID_TABLES, settings, false ); final Iterator<PersistentClass> entityMappings = mappings.iterateClasses(); final List<Table> idTableDefinitions = new ArrayList<Table>(); while ( entityMappings.hasNext() ) { final PersistentClass entityMapping = entityMappings.next(); final Table idTableDefinition = generateIdTableDefinition( entityMapping ); idTableDefinitions.add( idTableDefinition ); } exportTableDefinitions( idTableDefinitions, jdbcServices, connectionAccess, mappings, mapping ); }
private JdbcConnectionAccess buildLocalConnectionAccess() { return new JdbcConnectionAccess() { @Override public Connection obtainConnection() throws SQLException { return settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE ? serviceRegistry .getService(ConnectionProvider.class).getConnection() : serviceRegistry.getService( MultiTenantConnectionProvider.class) .getAnyConnection(); } @Override public void releaseConnection(Connection connection) throws SQLException { if (settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE) { serviceRegistry.getService(ConnectionProvider.class) .closeConnection(connection); } else { serviceRegistry.getService( MultiTenantConnectionProvider.class) .releaseAnyConnection(connection); } } @Override public boolean supportsAggressiveRelease() { return false; } }; }
protected JdbcConnectionAccess jdbcConnectionAccess() { return transactionCoordinator.getTransactionContext().getJdbcConnectionAccess(); }
@Override public JdbcConnectionAccess getJdbcConnectionAccess() { return sessionImplementor.getJdbcConnectionAccess(); }
@Override public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings) { // nothing to do }
@Override public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) { // nothing to do }
@Override public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings arg2, Mapping arg3, Map arg4) { // nothing to do }
/** * Provides access to JDBC connections * * @return The contract for accessing JDBC connections. */ public JdbcConnectionAccess getJdbcConnectionAccess();
/** * Prepare the strategy. Called as the SessionFactory is being built. Intended patterns here include:<ul> * <li>Adding tables to the passed Mappings, to be picked by by "schema management tools"</li> * <li>Manually creating the tables immediately through the passed JDBC Connection access</li> * </ul> * * @param jdbcServices The JdbcService object * @param connectionAccess Access to the JDBC Connection * @param mappings The Hibernate Mappings object, for access to O/RM mapping information * @param mapping The Hibernate Mapping contract, mainly for use in DDL generation * @param settings Configuration settings */ public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings);
/** * Release the strategy. Called as the SessionFactory is being shut down. * * @param jdbcServices The JdbcService object * @param connectionAccess Access to the JDBC Connection */ public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess);
public JdbcConnectionAccess getJdbcConnectionAccess();