Search in sources :

Example 61 with StandardServiceRegistry

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

the class SequenceStyleConfigUnitTest method testDefaultOptimizerBasedOnIncrementBackedBySequence.

/**
 * Test default optimizer selection for sequence backed generators
 * based on the configured increment size; both in the case of the
 * dialect supporting pooled sequences (pooled) and not (hilo)
 */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
    // for dialects which do not support pooled sequences, we default to pooled+table
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, SequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(TableStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
    // for dialects which do support pooled sequences, we default to pooled+sequence
    serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, PooledSequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 62 with StandardServiceRegistry

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

the class SequenceStyleConfigUnitTest method testDefaultedSequenceBackedConfiguration.

/**
 * Test all params defaulted with a dialect supporting sequences
 */
@Test
public void testDefaultedSequenceBackedConfiguration() {
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, SequenceDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(NoopOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 63 with StandardServiceRegistry

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

the class SequenceStyleConfigUnitTest method testDefaultOptimizerBasedOnIncrementBackedByTable.

/**
 * Test default optimizer selection for table backed generators
 * based on the configured increment size.  Here we always prefer
 * pooled.
 */
@Test
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, TableDialect.class.getName()).build();
    try {
        Properties props = buildGeneratorPropertiesBase(serviceRegistry);
        props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "10");
        SequenceStyleGenerator generator = new SequenceStyleGenerator();
        generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
        generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
        assertClassAssignability(TableStructure.class, generator.getDatabaseStructure().getClass());
        assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
        assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Database(org.hibernate.boot.model.relational.Database) Properties(java.util.Properties) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 64 with StandardServiceRegistry

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

the class CustomTypeConverterTest method testConverterAppliedScopedRegistration.

@Test
public void testConverterAppliedScopedRegistration() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(MyCustomConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        // now the new scoped way
        final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
        bootTypeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor(MyCustomJavaTypeDescriptor.INSTANCE);
        bootTypeConfiguration.getSqlTypeDescriptorRegistry().addDescriptor(MyCustomSqlTypeDescriptor.INSTANCE);
        performAssertions(metadataBuilder, bootTypeConfiguration);
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 65 with StandardServiceRegistry

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

the class CustomTypeConverterTest method testConverterAppliedStaticRegistration.

@Test
public void testConverterAppliedStaticRegistration() {
    // this is how we told users to do it previously using the static reference -
    // make sure it still works for now
    org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(MyCustomJavaTypeDescriptor.INSTANCE);
    org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry.INSTANCE.addDescriptor(MyCustomSqlTypeDescriptor.INSTANCE);
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(MyCustomConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
        performAssertions(metadataBuilder, bootTypeConfiguration);
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) 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