Search in sources :

Example 71 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testPositiveTwoAllocationSizeNoopOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-11709")
public void testPositiveTwoAllocationSizeNoopOptimizer() {
    ServiceRegistryImplementor serviceRegistry = null;
    SessionFactoryImplementor sessionFactory = null;
    Session session = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(AvailableSettings.PREFERRED_POOLED_OPTIMIZER, "none").applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
        Triggerable triggerable = logInspection.watchForLogMessages("HHH000116");
        Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(PositiveTwoIncrementSize.class).buildMetadata();
        // NoopOptimizer is preferred (due to setting AvailableSettings.PREFERRED_POOLED_OPTIMIZER to "false")
        // PositiveTwoIncrementSize ID has allocationSize == 2, so warning should be triggered.
        assertEquals(true, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, PositiveTwoIncrementSize.class, NoopOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // (since NoopOptimizer positive default allocationSize is 1)
        for (Integer i = -5; i <= 5; i++) {
            PositiveTwoIncrementSize theEntity = new PositiveTwoIncrementSize();
            session.persist(theEntity);
            assertEquals(i, theEntity.id);
        }
    } finally {
        if (session != null) {
            session.getTransaction().rollback();
            session.close();
        }
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        if (serviceRegistry != null) {
            serviceRegistry.destroy();
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 72 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testPositiveTwoAllocationSizePooledOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-11709")
public void testPositiveTwoAllocationSizePooledOptimizer() {
    ServiceRegistryImplementor serviceRegistry = null;
    SessionFactoryImplementor sessionFactory = null;
    Session session = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
        Triggerable triggerable = logInspection.watchForLogMessages("HHH000116");
        Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(PositiveTwoIncrementSize.class).buildMetadata();
        // PositiveTwoIncrementSize ID has allocationSize == 2, so PooledOptimizer should be used.
        // Warning should not be triggered.
        assertEquals(false, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, PositiveTwoIncrementSize.class, PooledOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // (since NoopOptimizer positive default allocationSize is 1)
        for (Integer i = -5; i <= 5; i++) {
            PositiveTwoIncrementSize theEntity = new PositiveTwoIncrementSize();
            session.persist(theEntity);
            assertEquals(i, theEntity.id);
        }
    } finally {
        if (session != null) {
            session.getTransaction().rollback();
            session.close();
        }
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        if (serviceRegistry != null) {
            serviceRegistry.destroy();
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 73 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testNegativeTwoAllocationSizePositiveStartNoopOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-11712")
public void testNegativeTwoAllocationSizePositiveStartNoopOptimizer() {
    ServiceRegistryImplementor serviceRegistry = null;
    SessionFactoryImplementor sessionFactory = null;
    Session session = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
        Triggerable triggerable = logInspection.watchForLogMessages("HHH000116");
        Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(NegativeTwoIncrementSizePositiveInitialValue.class).buildMetadata();
        // NegativeTwoIncrementSizePositiveInitialValue ID has allocationSize == -2, so warning should be triggered.
        assertEquals(true, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, NegativeTwoIncrementSizePositiveInitialValue.class, NoopOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // (since negative NoopOptimizer negative default is -1)
        for (Integer i = 5; i <= -5; i--) {
            NegativeTwoIncrementSizePositiveInitialValue theEntity = new NegativeTwoIncrementSizePositiveInitialValue();
            session.persist(theEntity);
            assertEquals(i, theEntity.id);
        }
    } finally {
        if (session != null) {
            session.getTransaction().rollback();
            session.close();
        }
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        if (serviceRegistry != null) {
            serviceRegistry.destroy();
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 74 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class DiscriminatorMultiTenancyTest method setUp.

@Before
public void setUp() {
    Map settings = new HashMap();
    settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DISCRIMINATOR);
    settings.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantResolver);
    settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    settings.put(Environment.GENERATE_STATISTICS, "true");
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    MetadataSources ms = new MetadataSources(serviceRegistry);
    ms.addAnnotatedClass(Customer.class);
    Metadata metadata = ms.buildMetadata();
    final PersistentClass customerMapping = metadata.getEntityBinding(Customer.class.getName());
    customerMapping.setCached(true);
    ((RootClass) customerMapping).setCacheConcurrencyStrategy("read-write");
    HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
    tool.injectServices(serviceRegistry);
    connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
    final GenerationTargetToDatabase target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProvider));
    new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, target);
    new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, target);
    target.release();
    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    sessionFactory = (SessionFactoryImplementor) sfb.build();
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) Customer(org.hibernate.test.multitenancy.schema.Customer) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) 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) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HashMap(java.util.HashMap) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) Before(org.junit.Before)

Example 75 with Metadata

use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.

the class AbstractSchemaBasedMultiTenancyTest method setUp.

@Before
public void setUp() {
    T 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();
    final PersistentClass customerMapping = metadata.getEntityBinding(Customer.class.getName());
    customerMapping.setCached(true);
    ((RootClass) customerMapping).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) 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) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HashMap(java.util.HashMap) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) Before(org.junit.Before)

Aggregations

Metadata (org.hibernate.boot.Metadata)148 MetadataSources (org.hibernate.boot.MetadataSources)124 Test (org.junit.Test)103 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)73 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)56 PersistentClass (org.hibernate.mapping.PersistentClass)46 TestForIssue (org.hibernate.testing.TestForIssue)31 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)18 Session (org.hibernate.Session)14 HashMap (java.util.HashMap)13 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)13 Property (org.hibernate.mapping.Property)12 RootClass (org.hibernate.mapping.RootClass)12 Map (java.util.Map)11 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 SessionFactory (org.hibernate.SessionFactory)10 Collection (org.hibernate.mapping.Collection)10 ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)10 ServiceRegistry (org.hibernate.service.ServiceRegistry)8 Before (org.junit.Before)8