private static DriverManagerConnectionProviderImpl buildConnectionProvider(Properties props, final boolean allowAggressiveRelease) { DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() { public boolean supportsAggressiveRelease() { return allowAggressiveRelease; } }; connectionProvider.configure( props ); return connectionProvider; }
protected void registerConnectionProvider(String tenantIdentifier, TimeZone timeZone) { Properties properties = properties(); properties.put( Environment.URL, tenantUrl( properties.getProperty( Environment.URL ), tenantIdentifier ) ); DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( properties ); connectionProviderMap.put( tenantIdentifier, connectionProvider ); timeZoneTenantMap.put( tenantIdentifier, timeZone ); } //end::multitenacy-hibernate-timezone-configuration-registerConnectionProvider-example[]
@Override public void configure(Map configurationValues) { Properties connectionSettings = new Properties(); transferSetting( Environment.DRIVER, configurationValues, connectionSettings ); transferSetting( Environment.URL, configurationValues, connectionSettings ); transferSetting( Environment.USER, configurationValues, connectionSettings ); transferSetting( Environment.PASS, configurationValues, connectionSettings ); transferSetting( Environment.ISOLATION, configurationValues, connectionSettings ); Properties passThroughSettings = ConnectionProviderInitiator.getConnectionProperties( configurationValues ); if ( passThroughSettings != null ) { for ( String setting : passThroughSettings.stringPropertyNames() ) { transferSetting( Environment.CONNECTION_PREFIX + '.' + setting, configurationValues, connectionSettings ); } } connectionSettings.setProperty( Environment.AUTOCOMMIT, "false" ); delegate = new DriverManagerConnectionProviderImpl(); delegate.configure( connectionSettings ); }
protected void registerConnectionProvider(String tenantIdentifier) { Properties properties = properties(); properties.put( Environment.URL, tenantUrl(properties.getProperty( Environment.URL ), tenantIdentifier) ); DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( properties ); connectionProviderMap.put( tenantIdentifier, connectionProvider ); } //end::multitenacy-hibernate-MultiTenantConnectionProvider-example[]
@Override public void buildEntityManagerFactory() { connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( Environment.getProperties() ); try(Connection connection = connectionProvider.getConnection(); Statement statement = connection.createStatement()) { statement.execute( "DROP TABLE IF EXISTS roles CASCADE" ); statement.execute( "CREATE TABLE roles ( id BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY )" ); } catch (SQLException e) { fail(e.getMessage()); } super.buildEntityManagerFactory(); }
@Before public void setUp() throws Exception { connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( properties() ); connection = connectionProvider.getConnection(); ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.HBM2DDL_CONNECTION, connection ) .build(); tool = (HibernateSchemaManagementTool) ssr.getService( SchemaManagementTool.class ); configurationValues = ssr.getService( ConfigurationService.class ).getSettings(); executionOptions = new ExecutionOptions() { @Override public boolean shouldManageNamespaces() { return true; } @Override public Map getConfigurationValues() { return configurationValues; } @Override public ExceptionHandler getExceptionHandler() { return ExceptionHandlerLoggedImpl.INSTANCE; } }; }
connectionProvider.configure( properties() );
private ConnectionProvider buildConnectionProvider(String dbName) { Properties props = new Properties( null ); props.put( "hibernate.connection.driver_class", DRIVER ); // Inject dbName into connection url string. props.put( "hibernate.connection.url", String.format( URL, dbName ) ); props.put( "hibernate.connection.username", USER ); props.put( "hibernate.connection.password", PASS ); // Note that DriverManagerConnectionProviderImpl is an internal class. However, rather than creating // a ConnectionProvider, I'm using it for simplicity's sake. // DriverManagerConnectionProviderImpl obtains a Connection through the JDBC Driver#connect DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); connectionProvider.configure( props ); return connectionProvider; }