use of org.hibernate.mapping.Table in project hibernate-orm by hibernate.
the class SingleAuditParentsTest method testCreatedAuditTable.
@Test
public void testCreatedAuditTable() {
Set<String> expectedColumns = TestTools.makeSet("child", "grandparent", "id");
Set<String> unexpectedColumns = TestTools.makeSet("parent", "relation_id", "notAudited");
Table table = metadata().getEntityBinding("org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD").getTable();
for (String columnName : expectedColumns) {
// Check whether expected column exists.
Assert.assertNotNull(table.getColumn(new Column(columnName)));
}
for (String columnName : unexpectedColumns) {
// Check whether unexpected column does not exist.
Assert.assertNull(table.getColumn(new Column(columnName)));
}
}
use of org.hibernate.mapping.Table in project hibernate-orm by hibernate.
the class ModelBinder method bindUnionSubclassEntity.
private void bindUnionSubclassEntity(SubclassEntitySourceImpl entitySource, UnionSubclass entityDescriptor) {
MappingDocument mappingDocument = entitySource.sourceMappingDocument();
bindBasicEntityValues(mappingDocument, entitySource, entityDescriptor);
final Table primaryTable = bindEntityTableSpecification(mappingDocument, entitySource.getPrimaryTable(), entityDescriptor.getSuperclass().getTable(), entitySource, entityDescriptor);
entityDescriptor.setTable(primaryTable);
if (log.isDebugEnabled()) {
log.debugf("Mapping union-subclass: %s -> %s", entityDescriptor.getEntityName(), primaryTable.getName());
}
// todo : tooling hints
bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
bindUnionSubclassEntities(entitySource, entityDescriptor);
}
use of org.hibernate.mapping.Table in project hibernate-orm by hibernate.
the class BinderHelper method makeIdGenerator.
/**
* apply an id generator to a SimpleValue
*/
public static void makeIdGenerator(SimpleValue id, String generatorType, String generatorName, MetadataBuildingContext buildingContext, Map<String, IdentifierGeneratorDefinition> localGenerators) {
Table table = id.getTable();
table.setIdentifierValue(id);
//generator settings
id.setIdentifierGeneratorStrategy(generatorType);
Properties params = new Properties();
//always settable
params.setProperty(PersistentIdentifierGenerator.TABLE, table.getName());
final String implicitCatalogName = buildingContext.getBuildingOptions().getMappingDefaults().getImplicitCatalogName();
if (implicitCatalogName != null) {
params.put(PersistentIdentifierGenerator.CATALOG, implicitCatalogName);
}
final String implicitSchemaName = buildingContext.getBuildingOptions().getMappingDefaults().getImplicitSchemaName();
if (implicitSchemaName != null) {
params.put(PersistentIdentifierGenerator.SCHEMA, implicitSchemaName);
}
if (id.getColumnSpan() == 1) {
params.setProperty(PersistentIdentifierGenerator.PK, ((org.hibernate.mapping.Column) id.getColumnIterator().next()).getName());
}
// YUCK! but cannot think of a clean way to do this given the string-config based scheme
params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, buildingContext.getObjectNameNormalizer());
if (!isEmptyAnnotationValue(generatorName)) {
//we have a named generator
IdentifierGeneratorDefinition gen = getIdentifierGenerator(generatorName, localGenerators, buildingContext);
if (gen == null) {
throw new AnnotationException("Unknown Id.generator: " + generatorName);
}
//This is quite vague in the spec but a generator could override the generate choice
String identifierGeneratorStrategy = gen.getStrategy();
//yuk! this is a hack not to override 'AUTO' even if generator is set
final boolean avoidOverriding = identifierGeneratorStrategy.equals("identity") || identifierGeneratorStrategy.equals("seqhilo") || identifierGeneratorStrategy.equals(MultipleHiLoPerTableGenerator.class.getName());
if (generatorType == null || !avoidOverriding) {
id.setIdentifierGeneratorStrategy(identifierGeneratorStrategy);
}
//checkIfMatchingGenerator(gen, generatorType, generatorName);
for (Object o : gen.getParameters().entrySet()) {
Map.Entry elt = (Map.Entry) o;
params.setProperty((String) elt.getKey(), (String) elt.getValue());
}
}
if ("assigned".equals(generatorType)) {
id.setNullValue("undefined");
}
id.setIdentifierGeneratorProperties(params);
}
use of org.hibernate.mapping.Table in project hibernate-orm by hibernate.
the class TableBinder method buildAndFillTable.
public static Table buildAndFillTable(String schema, String catalog, Identifier logicalName, boolean isAbstract, List<UniqueConstraintHolder> uniqueConstraints, List<JPAIndexHolder> jpaIndexHolders, String constraints, MetadataBuildingContext buildingContext, String subselect, InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
schema = BinderHelper.isEmptyOrNullAnnotationValue(schema) ? extract(buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getSchema()) : schema;
catalog = BinderHelper.isEmptyOrNullAnnotationValue(catalog) ? extract(buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getCatalog()) : catalog;
final Table table;
if (denormalizedSuperTableXref != null) {
table = buildingContext.getMetadataCollector().addDenormalizedTable(schema, catalog, logicalName.render(), isAbstract, subselect, denormalizedSuperTableXref.getPrimaryTable());
} else {
table = buildingContext.getMetadataCollector().addTable(schema, catalog, logicalName.render(), subselect, isAbstract);
}
if (CollectionHelper.isNotEmpty(uniqueConstraints)) {
buildingContext.getMetadataCollector().addUniqueConstraintHolders(table, uniqueConstraints);
}
if (CollectionHelper.isNotEmpty(jpaIndexHolders)) {
buildingContext.getMetadataCollector().addJpaIndexHolders(table, jpaIndexHolders);
}
if (constraints != null) {
table.addCheckConstraint(constraints);
}
buildingContext.getMetadataCollector().addTableNameBinding(logicalName, table);
return table;
}
use of org.hibernate.mapping.Table in project hibernate-orm by hibernate.
the class Db2GenerationTest method testLegacyGeneratorTableCreationOnDb2.
@Test
@TestForIssue(jiraKey = "HHH-9850")
public void testLegacyGeneratorTableCreationOnDb2() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, DB2Dialect.class.getName()).build();
try {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
assertEquals(0, metadata.getDatabase().getDefaultNamespace().getTables().size());
MultipleHiLoPerTableGenerator generator = new MultipleHiLoPerTableGenerator();
Properties properties = new Properties();
generator.configure(IntegerType.INSTANCE, properties, ssr);
generator.registerExportables(metadata.getDatabase());
assertEquals(1, metadata.getDatabase().getDefaultNamespace().getTables().size());
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings(table, metadata);
assertContains("sequence_name varchar(255) not null", createCommands[0]);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations