下面列出了怎么用org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public ConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
ConnectionProvider provider = ConnectionProviderInitiator.INSTANCE.initiateService(configurationValues, registry);
if (provider instanceof DriverManagerConnectionProviderImpl) {
registry.getService( SchemaManagementTool.class )
.setCustomDatabaseGenerationTarget( new ReactiveGenerationTarget(registry) );
return NoJdbcConnectionProvider.INSTANCE;
}
return provider;
}
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;
}
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;
}
private void initConnectionProviderForTenant(String tenantId) throws IOException {
Properties properties = new Properties();
properties.load(getClass().getResourceAsStream(String.format("/hibernate-database-%s.properties", tenantId)));
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties);
this.connectionProviderMap.put(tenantId, connectionProvider);
}
private ConnectionProvider initConnectionProvider() throws IOException {
Properties properties = new Properties();
properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties"));
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties);
return connectionProvider;
}