Search in sources :

Example 1 with IdentifierCollection

use of org.hibernate.mapping.IdentifierCollection in project hibernate-orm by hibernate.

the class InFlightMetadataCollectorImpl method processExportableProducers.

private void processExportableProducers(MetadataBuildingContext buildingContext) {
    // for now we only handle id generators as ExportableProducers
    final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
    final String defaultCatalog = extractName(getDatabase().getDefaultNamespace().getName().getCatalog(), dialect);
    final String defaultSchema = extractName(getDatabase().getDefaultNamespace().getName().getSchema(), dialect);
    for (PersistentClass entityBinding : entityBindingMap.values()) {
        if (entityBinding.isInherited()) {
            continue;
        }
        handleIdentifierValueBinding(entityBinding.getIdentifier(), dialect, defaultCatalog, defaultSchema, (RootClass) entityBinding);
    }
    for (Collection collection : collectionBindingMap.values()) {
        if (!IdentifierCollection.class.isInstance(collection)) {
            continue;
        }
        handleIdentifierValueBinding(((IdentifierCollection) collection).getIdentifier(), dialect, defaultCatalog, defaultSchema, null);
    }
}
Also used : Dialect(org.hibernate.dialect.Dialect) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierCollection(org.hibernate.mapping.IdentifierCollection)

Example 2 with IdentifierCollection

use of org.hibernate.mapping.IdentifierCollection in project hibernate-orm by hibernate.

the class InFlightMetadataCollectorImpl method processExportableProducers.

private void processExportableProducers() {
    // for now we only handle id generators as ExportableProducers
    final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
    final String defaultCatalog = extractName(getDatabase().getDefaultNamespace().getName().getCatalog(), dialect);
    final String defaultSchema = extractName(getDatabase().getDefaultNamespace().getName().getSchema(), dialect);
    for (PersistentClass entityBinding : entityBindingMap.values()) {
        if (entityBinding.isInherited()) {
            continue;
        }
        handleIdentifierValueBinding(entityBinding.getIdentifier(), dialect, defaultCatalog, defaultSchema, (RootClass) entityBinding);
    }
    for (Collection collection : collectionBindingMap.values()) {
        if (!IdentifierCollection.class.isInstance(collection)) {
            continue;
        }
        handleIdentifierValueBinding(((IdentifierCollection) collection).getIdentifier(), dialect, defaultCatalog, defaultSchema, null);
    }
}
Also used : Dialect(org.hibernate.dialect.Dialect) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass) IdentifierCollection(org.hibernate.mapping.IdentifierCollection)

Example 3 with IdentifierCollection

use of org.hibernate.mapping.IdentifierCollection in project hibernate-orm by hibernate.

the class IdBagBinder method bindStarToManySecondPass.

@Override
protected boolean bindStarToManySecondPass(Map persistentClasses, XClass collType, Ejb3JoinColumn[] fkJoinColumns, Ejb3JoinColumn[] keyColumns, Ejb3JoinColumn[] inverseColumns, Ejb3Column[] elementColumns, boolean isEmbedded, XProperty property, boolean unique, TableBinder associationTableBinder, boolean ignoreNotFound, MetadataBuildingContext buildingContext) {
    boolean result = super.bindStarToManySecondPass(persistentClasses, collType, fkJoinColumns, keyColumns, inverseColumns, elementColumns, isEmbedded, property, unique, associationTableBinder, ignoreNotFound, getBuildingContext());
    CollectionId collectionIdAnn = property.getAnnotation(CollectionId.class);
    if (collectionIdAnn != null) {
        SimpleValueBinder simpleValue = new SimpleValueBinder();
        PropertyData propertyData = new WrappedInferredData(new PropertyInferredData(null, property, // default access should not be useful
        null, buildingContext.getBootstrapContext().getReflectionManager()), "id");
        Ejb3Column[] idColumns = Ejb3Column.buildColumnFromAnnotation(collectionIdAnn.columns(), null, Nullability.FORCED_NOT_NULL, propertyHolder, propertyData, Collections.EMPTY_MAP, buildingContext);
        // we need to make sure all id columns must be not-null.
        for (Ejb3Column idColumn : idColumns) {
            idColumn.setNullable(false);
        }
        Table table = collection.getCollectionTable();
        simpleValue.setTable(table);
        simpleValue.setColumns(idColumns);
        Type typeAnn = collectionIdAnn.type();
        if (typeAnn != null && !BinderHelper.isEmptyAnnotationValue(typeAnn.type())) {
            simpleValue.setExplicitType(typeAnn);
        } else {
            throw new AnnotationException("@CollectionId is missing type: " + StringHelper.qualify(propertyHolder.getPath(), propertyName));
        }
        simpleValue.setBuildingContext(getBuildingContext());
        SimpleValue id = simpleValue.make();
        ((IdentifierCollection) collection).setIdentifier(id);
        String generator = collectionIdAnn.generator();
        String generatorType;
        if ("identity".equals(generator) || "assigned".equals(generator) || "sequence".equals(generator) || "native".equals(generator)) {
            generatorType = generator;
            generator = "";
        } else {
            generatorType = null;
        }
        SecondPass secondPass = new IdGeneratorResolverSecondPass(id, property, generatorType, generator, getBuildingContext());
        buildingContext.getMetadataCollector().addSecondPass(secondPass);
    }
    return result;
}
Also used : IdGeneratorResolverSecondPass(org.hibernate.cfg.IdGeneratorResolverSecondPass) WrappedInferredData(org.hibernate.cfg.WrappedInferredData) PropertyData(org.hibernate.cfg.PropertyData) Table(org.hibernate.mapping.Table) PropertyInferredData(org.hibernate.cfg.PropertyInferredData) SimpleValue(org.hibernate.mapping.SimpleValue) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) Type(org.hibernate.annotations.Type) CollectionId(org.hibernate.annotations.CollectionId) IdGeneratorResolverSecondPass(org.hibernate.cfg.IdGeneratorResolverSecondPass) SecondPass(org.hibernate.cfg.SecondPass) AnnotationException(org.hibernate.AnnotationException) Ejb3Column(org.hibernate.cfg.Ejb3Column)

Aggregations

IdentifierCollection (org.hibernate.mapping.IdentifierCollection)3 Dialect (org.hibernate.dialect.Dialect)2 Collection (org.hibernate.mapping.Collection)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 AnnotationException (org.hibernate.AnnotationException)1 CollectionId (org.hibernate.annotations.CollectionId)1 Type (org.hibernate.annotations.Type)1 Ejb3Column (org.hibernate.cfg.Ejb3Column)1 IdGeneratorResolverSecondPass (org.hibernate.cfg.IdGeneratorResolverSecondPass)1 PropertyData (org.hibernate.cfg.PropertyData)1 PropertyInferredData (org.hibernate.cfg.PropertyInferredData)1 SecondPass (org.hibernate.cfg.SecondPass)1 WrappedInferredData (org.hibernate.cfg.WrappedInferredData)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 Table (org.hibernate.mapping.Table)1