Search in sources :

Example 1 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class IndividuallySchemaValidatorImplTest method testMissingColumn.

@Test
public void testMissingColumn() throws Exception {
    MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(NoNameColumn.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    Map<String, Object> settings = new HashMap<>();
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
    connectionProvider.configure(properties());
    final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
    try {
        new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
        metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(NameColumn.class);
        metadata = (MetadataImplementor) metadataSources.buildMetadata();
        metadata.validate();
        try {
            getSchemaValidator(metadata);
            Assert.fail("SchemaManagementException expected");
        } catch (SchemaManagementException e) {
            assertEquals("Schema-validation: missing column [name] in table [SomeSchema.ColumnEntity]", e.getMessage());
        }
    } finally {
        new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
        serviceRegistry.destroy();
        connectionProvider.stop();
    }
}
Also used : JdbcConnectionAccessImpl(org.hibernate.testing.boot.JdbcConnectionAccessImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) DriverManagerConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Test(org.junit.Test)

Example 2 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class ConfigurationValidationTest method testInvalidConnectionProvider.

@Test(expected = ServiceException.class)
public void testInvalidConnectionProvider() {
    ServiceRegistryImplementor serviceRegistry = null;
    try {
        serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySetting(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA).applySetting(Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath").build();
        new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory().close();
    } finally {
        if (serviceRegistry != null) {
            try {
                StandardServiceRegistryBuilder.destroy(serviceRegistry);
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) ServiceException(org.hibernate.service.spi.ServiceException) Test(org.junit.Test)

Example 3 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class NonRootEntityWithCacheAnnotationTest method testCacheOnNonRootEntity.

@Test
public void testCacheOnNonRootEntity() {
    Map settings = new HashMap();
    settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
    assertTrue(triggerable.wasTriggered());
    assertFalse(metadata.getEntityBinding(AEntity.class.getName()).isCached());
    serviceRegistry.destroy();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class NonRootEntityWithCacheableAnnotationTest method testCacheableOnNonRootEntity.

@Test
public void testCacheableOnNonRootEntity() {
    Map settings = new HashMap();
    settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
    settings.put(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write");
    settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
    ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
    Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
    assertFalse(metadata.getEntityBinding(ABase.class.getName()).isCached());
    assertTrue(metadata.getEntityBinding(AEntity.class.getName()).isCached());
    assertFalse(triggerable.wasTriggered());
    serviceRegistry.destroy();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) ServiceRegistryImplementor(org.hibernate.service.spi.ServiceRegistryImplementor) Triggerable(org.hibernate.testing.logger.Triggerable) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ServiceRegistryImplementor

use of org.hibernate.service.spi.ServiceRegistryImplementor in project hibernate-orm by hibernate.

the class NegativeValueSequenceTest method testNegativeTwoAllocationSizeNoopOptimizer.

@Test
@TestForIssue(jiraKey = "HHH-5933")
public void testNegativeTwoAllocationSizeNoopOptimizer() {
    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(NegativeTwoIncrementSize.class).buildMetadata();
        // NegativeTwoIncrementSize ID has allocationSize == -2, so warning should be triggered.
        assertEquals(true, triggerable.wasTriggered());
        sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
        assertOptimizer(sessionFactory, NegativeTwoIncrementSize.class, NoopOptimizer.class);
        session = sessionFactory.openSession();
        session.getTransaction().begin();
        // (since negative NoopOptimizer negative default is -1)
        for (Integer i = -10; i >= -15; i--) {
            NegativeTwoIncrementSize theEntity = new NegativeTwoIncrementSize();
            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)

Aggregations

ServiceRegistryImplementor (org.hibernate.service.spi.ServiceRegistryImplementor)16 MetadataSources (org.hibernate.boot.MetadataSources)15 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)15 Test (org.junit.Test)13 Metadata (org.hibernate.boot.Metadata)10 Triggerable (org.hibernate.testing.logger.Triggerable)8 HashMap (java.util.HashMap)6 Session (org.hibernate.Session)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 TestForIssue (org.hibernate.testing.TestForIssue)6 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)5 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)5 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)5 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)5 Map (java.util.Map)3 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)3 JdbcConnectionAccessImpl (org.hibernate.testing.boot.JdbcConnectionAccessImpl)3 CachingRegionFactory (org.hibernate.testing.cache.CachingRegionFactory)3 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)2