Search in sources :

Example 1 with AbstractMultiTenantConnectionProvider

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();
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 2 with AbstractMultiTenantConnectionProvider

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();
        }
    });
}
Also used : AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) XaConnectionProvider(org.hibernate.test.cache.infinispan.tm.XaConnectionProvider) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider)

Example 3 with AbstractMultiTenantConnectionProvider

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()));
}
Also used : AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

AbstractMultiTenantConnectionProvider (org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider)3 MultiTenantConnectionProvider (org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)1 RootClass (org.hibernate.mapping.RootClass)1 XaConnectionProvider (org.hibernate.test.cache.infinispan.tm.XaConnectionProvider)1 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)1 TestForIssue (org.hibernate.testing.TestForIssue)1 CachingRegionFactory (org.hibernate.testing.cache.CachingRegionFactory)1 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)1 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)1 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)1 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)1 Before (org.junit.Before)1 Test (org.junit.Test)1