Search in sources :

Example 76 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class HiloOptimizerConcurrencyTest method testTwoSessionsSerialGeneration.

@Test
public void testTwoSessionsSerialGeneration() {
    createSchema = true;
    rebuildSessionFactory();
    StandardServiceRegistry serviceRegistry = serviceRegistry();
    SessionFactoryImplementor sessionFactory = sessionFactory();
    try {
        final Session session1 = openSession();
        try {
            session1.beginTransaction();
            HibPerson p = new HibPerson();
            session1.save(p);
        } finally {
            session1.getTransaction().commit();
        }
        createSchema = false;
        buildResources();
        final Session session2 = openSession();
        session2.beginTransaction();
        try {
            HibPerson p = new HibPerson();
            session2.save(p);
        } finally {
            session2.getTransaction().commit();
        }
        for (int i = 2; i < 6; i++) {
            session1.beginTransaction();
            try {
                HibPerson p = new HibPerson();
                session1.save(p);
            } finally {
                session1.getTransaction().commit();
            }
        }
        session2.beginTransaction();
        try {
            HibPerson p = new HibPerson();
            session2.save(p);
        } finally {
            session2.getTransaction().commit();
        }
        session1.beginTransaction();
        try {
            HibPerson p = new HibPerson();
            session1.save(p);
        } finally {
            session1.getTransaction().commit();
        }
    } catch (ConstraintViolationException cve) {
        fail("ConstraintViolationException: " + cve.getMessage());
    } finally {
        releaseResources(serviceRegistry, sessionFactory);
    }
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) Test(org.junit.Test)

Example 77 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class SmokeTest method testEhcacheShortName.

@Test
public void testEhcacheShortName() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.CACHE_REGION_FACTORY, "ehcache").build();
    assertThat(registry.getService(RegionFactory.class), instanceOf(EhcacheRegionFactory.class));
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SingletonEhcacheRegionFactory(org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory) RegionFactory(org.hibernate.cache.spi.RegionFactory) EhcacheRegionFactory(org.hibernate.cache.ehcache.internal.EhcacheRegionFactory) SingletonEhcacheRegionFactory(org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory) EhcacheRegionFactory(org.hibernate.cache.ehcache.internal.EhcacheRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 78 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class SqlServerQuoteSchemaTest method test.

@Test
public void test() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
    try {
        output.deleteOnExit();
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
        metadata.validate();
        new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
    try {
        String fileContent = new String(Files.readAllBytes(output.toPath()));
        Pattern fileContentPattern = Pattern.compile("create table \\[my\\-schema\\]\\.\\[my_entity\\]");
        Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
        assertThat(fileContentMatcher.find(), is(true));
    } catch (IOException e) {
        fail(e.getMessage());
    }
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntityUpdated.class).buildMetadata();
        metadata.validate();
        new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
    try {
        String fileContent = new String(Files.readAllBytes(output.toPath()));
        Pattern fileContentPattern = Pattern.compile("alter table .*?\\.\\[my\\-schema\\]\\.\\[my_entity\\]");
        Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
        assertThat(fileContentMatcher.find(), is(true));
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
Also used : Pattern(java.util.regex.Pattern) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Matcher(java.util.regex.Matcher) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) IOException(java.io.IOException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 79 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class SchemaUpdateFormatterTest method testSetFormat.

@Test
public void testSetFormat() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
    try {
        File output = File.createTempFile("update_script", ".sql");
        output.deleteOnExit();
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
        metadata.validate();
        new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(DELIMITER).setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
        String outputContent = new String(Files.readAllBytes(output.toPath()));
        // Old Macs use \r as a new line delimiter
        outputContent = outputContent.replaceAll("\r", "\n");
        // On Windows, \r\n would become \n\n, so we eliminate duplicates
        outputContent = outputContent.replaceAll("\n\n", "\n");
        Assert.assertTrue(Pattern.compile(AFTER_FORMAT).matcher(outputContent).matches());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) File(java.io.File) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 80 with StandardServiceRegistry

use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.

the class GeometryConverterTest method testConverterUsage.

@Test
public void testConverterUsage() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, GeoDBDialect.class).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(GeometryConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        try (final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataBuilder.build().buildSessionFactory()) {
            final TypeConfiguration typeConfiguration = sessionFactory.getMetamodel().getTypeConfiguration();
            assertThat(typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(Geometry.class), sameInstance(GeolatteGeometryJavaTypeDescriptor.INSTANCE));
            // todo (5.3) : what to assert wrt to SqlTypeDescriptor?  Anything?
            final EntityPersister entityPersister = sessionFactory.getMetamodel().entityPersister(MyEntity.class);
            final AttributeConverterTypeAdapter geometryAttributeType = assertTyping(AttributeConverterTypeAdapter.class, entityPersister.getPropertyType("geometry"));
            final JpaAttributeConverter converter = assertTyping(JpaAttributeConverter.class, geometryAttributeType.getAttributeConverter());
            assert GeometryConverter.class.equals(converter.getConverterBean().getBeanClass());
        }
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) Geometry(org.geolatte.geom.Geometry) EntityPersister(org.hibernate.persister.entity.EntityPersister) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverter(org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Aggregations

StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)169 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)152 Test (org.junit.Test)121 MetadataSources (org.hibernate.boot.MetadataSources)118 Metadata (org.hibernate.boot.Metadata)56 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)39 PersistentClass (org.hibernate.mapping.PersistentClass)39 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)25 TestForIssue (org.hibernate.testing.TestForIssue)24 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)23 Properties (java.util.Properties)20 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)15 SessionFactory (org.hibernate.SessionFactory)14 Column (org.hibernate.mapping.Column)14 Property (org.hibernate.mapping.Property)14 Session (org.hibernate.Session)13 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)12 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 RootClass (org.hibernate.mapping.RootClass)11