use of org.hibernate.boot.model.relational.Database 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.model.relational.Database 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.model.relational.Database in project hibernate-orm by hibernate.
the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.
@Test
public void testCreateTableOnUpdate() throws SQLException {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
Database database = metadata.getDatabase();
TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
tableStructure.registerExportables(database);
// lets make sure the InitCommand is there
assertEquals(1, database.getDefaultNamespace().getTables().size());
Table table = database.getDefaultNamespace().getTables().iterator().next();
assertEquals(1, table.getInitCommands().size());
final TargetImpl target = new TargetImpl();
ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return ssr.getService(ConfigurationService.class).getSettings();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
}, new TargetDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return target;
}
});
assertTrue(target.found);
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.
@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
final Database database = metadata.getDatabase();
final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return configurationValues;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
};
new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
}, buildTargets());
}
use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.
the class SequenceStyleConfigUnitTest method testPreferredPooledOptimizerSetting.
@Test
public void testPreferredPooledOptimizerSetting() {
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, PooledSequenceDialect.class.getName()).build();
try {
Properties props = buildGeneratorPropertiesBase(serviceRegistry);
props.setProperty(SequenceStyleGenerator.INCREMENT_PARAM, "20");
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());
props.setProperty(Environment.PREFER_POOLED_VALUES_LO, "true");
generator = new SequenceStyleGenerator();
generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
assertClassAssignability(PooledLoOptimizer.class, generator.getOptimizer().getClass());
props.setProperty(Environment.PREFERRED_POOLED_OPTIMIZER, StandardOptimizerDescriptor.POOLED_LOTL.getExternalName());
generator = new SequenceStyleGenerator();
generator.configure(StandardBasicTypes.LONG, props, serviceRegistry);
generator.registerExportables(new Database(new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry)));
assertClassAssignability(SequenceStructure.class, generator.getDatabaseStructure().getClass());
assertClassAssignability(PooledLoThreadLocalOptimizer.class, generator.getOptimizer().getClass());
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
Aggregations