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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations