use of org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method setUp.
@Before
public void setUp() {
AbstractMultiTenantConnectionProvider multiTenantConnectionProvider = buildMultiTenantConnectionProvider();
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).addService(MultiTenantConnectionProvider.class, multiTenantConnectionProvider).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
ms.addAnnotatedClass(Invoice.class);
Metadata metadata = ms.buildMetadata();
((RootClass) metadata.getEntityBinding(Customer.class.getName())).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase acmeTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, acmeProvider));
final GenerationTargetToDatabase jbossTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, jbossProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
configure(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider in project hibernate-orm by hibernate.
the class MultiTenancyTest method configureStandardServiceRegistryBuilder.
@Override
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) {
super.configureStandardServiceRegistryBuilder(ssrb);
ssrb.addService(MultiTenantConnectionProvider.class, new AbstractMultiTenantConnectionProvider() {
@Override
protected ConnectionProvider getAnyConnectionProvider() {
return db1;
}
@Override
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
if (DB1.equals(tenantIdentifier))
return db1;
if (DB2.equals(tenantIdentifier))
return db2;
throw new IllegalArgumentException();
}
});
}
use of org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method testUnwrappingAbstractMultiTenantConnectionProvider.
@Test
@TestForIssue(jiraKey = "HHH-11651")
public void testUnwrappingAbstractMultiTenantConnectionProvider() {
final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService(MultiTenantConnectionProvider.class);
final AbstractMultiTenantConnectionProvider connectionProvider = multiTenantConnectionProvider.unwrap(AbstractMultiTenantConnectionProvider.class);
assertThat(connectionProvider, is(notNullValue()));
}
Aggregations