Search in sources :

Example 1 with Table

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)));
    }
}
Also used : Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) Test(org.junit.Test)

Example 2 with Table

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);
}
Also used : Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable)

Example 3 with Table

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);
}
Also used : Table(org.hibernate.mapping.Table) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) AnnotationException(org.hibernate.AnnotationException) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Table

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;
}
Also used : Table(org.hibernate.mapping.Table)

Example 5 with 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);
    }
}
Also used : MultipleHiLoPerTableGenerator(org.hibernate.id.MultipleHiLoPerTableGenerator) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Properties(java.util.Properties) DB2Dialect(org.hibernate.dialect.DB2Dialect) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Table (org.hibernate.mapping.Table)324 Test (org.junit.Test)230 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)204 Column (org.hibernate.mapping.Column)68 SimpleValue (org.hibernate.mapping.SimpleValue)58 RootClass (org.hibernate.mapping.RootClass)48 Method (java.lang.reflect.Method)40 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)29 PrimaryKey (org.hibernate.mapping.PrimaryKey)27 File (java.io.File)24 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)24 Before (org.junit.Before)24 Iterator (java.util.Iterator)22 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)20 Configuration (org.hibernate.cfg.Configuration)20 PersistentClass (org.hibernate.mapping.PersistentClass)20 Collection (org.hibernate.mapping.Collection)19 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)19 List (java.util.List)18