use of org.hibernate.boot.model.relational.Database in project hibernate-orm by hibernate.
the class Ejb3Column method addColumnBinding.
protected void addColumnBinding(SimpleValue value) {
final String logicalColumnName;
if (StringHelper.isNotEmpty(this.logicalColumnName)) {
logicalColumnName = this.logicalColumnName;
} else {
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
final Database database = context.getMetadataCollector().getDatabase();
final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy();
final Identifier implicitName = normalizer.normalizeIdentifierQuoting(implicitNamingStrategy.determineBasicColumnName(new ImplicitBasicColumnNameSource() {
@Override
public AttributePath getAttributePath() {
return AttributePath.parse(propertyName);
}
@Override
public boolean isCollectionElement() {
return false;
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
}));
logicalColumnName = implicitName.render(database.getDialect());
}
context.getMetadataCollector().addColumnNameBinding(value.getTable(), logicalColumnName, getMappingColumn());
}
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 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 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.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);
}
}
Aggregations