BAEL-399 A Guide to Multitenancy in Hibernate 5 (#3323)
* BAEL-399: A Guide to Multitenancy in Hibernate 5 * Removed unused properties in profile 2 * Changes after code review
This commit is contained in:
parent
8de8770eec
commit
23f7f658e4
|
@ -8,12 +8,15 @@ import java.util.Properties;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
|
public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
|
||||||
|
|
||||||
private final ConnectionProvider connectionProvider = initConnectionProvider();
|
private final ConnectionProvider connectionProvider;
|
||||||
|
|
||||||
|
public SchemaMultiTenantConnectionProvider() throws IOException {
|
||||||
|
connectionProvider = initConnectionProvider();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionProvider getAnyConnectionProvider() {
|
protected ConnectionProvider getAnyConnectionProvider() {
|
||||||
|
@ -33,13 +36,9 @@ public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConn
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnectionProvider initConnectionProvider() {
|
private ConnectionProvider initConnectionProvider() throws IOException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
|
||||||
properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties"));
|
properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties"));
|
||||||
} catch (IOException e) {
|
|
||||||
Assert.fail("Error loading resource. Cause: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
|
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
|
||||||
connectionProvider.configure(properties);
|
connectionProvider.configure(properties);
|
||||||
|
|
Loading…
Reference in New Issue