Search in sources :

Example 1 with SingularAttributeSourceEmbedded

use of org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded in project hibernate-orm by hibernate.

the class AttributesHelper method processPropertiesGroup.

private static void processPropertiesGroup(final MappingDocument mappingDocument, final Callback callback, final JaxbHbmPropertiesType propertiesGroupJaxbMapping, String logicalTableName, NaturalIdMutability naturalIdMutability) {
    final String name = propertiesGroupJaxbMapping.getName();
    final AttributeRole attributeRole = callback.getAttributeSourceContainer().getAttributeRoleBase().append(name);
    final AttributePath attributePath = callback.getAttributeSourceContainer().getAttributePathBase().append(name);
    final EmbeddableSourceVirtualImpl embeddable = new EmbeddableSourceVirtualImpl(mappingDocument, callback, new EmbeddableSourceContainer() {

        @Override
        public AttributeRole getAttributeRoleBase() {
            return attributeRole;
        }

        @Override
        public AttributePath getAttributePathBase() {
            return attributePath;
        }

        @Override
        public ToolingHintContext getToolingHintContextBaselineForEmbeddable() {
            return callback.getAttributeSourceContainer().getToolingHintContext();
        }
    }, propertiesGroupJaxbMapping.getAttributes(), logicalTableName, naturalIdMutability, propertiesGroupJaxbMapping);
    // fake the JAXB mapping...
    final EmbeddableMapping embeddableMapping = new EmbeddableMapping() {

        @Override
        public String getClazz() {
            return null;
        }

        @Override
        public List<JaxbHbmTuplizerType> getTuplizer() {
            return Collections.emptyList();
        }

        @Override
        public String getParent() {
            return null;
        }
    };
    final EmbeddedAttributeMapping attributeMapping = new EmbeddedAttributeMapping() {

        @Override
        public boolean isUnique() {
            return propertiesGroupJaxbMapping.isUnique();
        }

        @Override
        public EmbeddableMapping getEmbeddableMapping() {
            return embeddableMapping;
        }

        @Override
        public String getName() {
            return propertiesGroupJaxbMapping.getName();
        }

        @Override
        public String getAccess() {
            return null;
        }

        @Override
        public List<JaxbHbmToolingHintType> getToolingHints() {
            return Collections.emptyList();
        }
    };
    // todo : make the virtual embedded attribute
    final SingularAttributeSourceEmbedded virtualAttribute = new AbstractSingularAttributeSourceEmbeddedImpl(mappingDocument, attributeMapping, embeddable, naturalIdMutability) {

        @Override
        public boolean isVirtualAttribute() {
            return true;
        }

        @Override
        public Boolean isInsertable() {
            return propertiesGroupJaxbMapping.isInsert();
        }

        @Override
        public Boolean isUpdatable() {
            return propertiesGroupJaxbMapping.isUpdate();
        }

        @Override
        public boolean isBytecodeLazy() {
            return false;
        }

        @Override
        public XmlElementMetadata getSourceType() {
            return XmlElementMetadata.PROPERTIES;
        }

        @Override
        public String getXmlNodeName() {
            return null;
        }

        @Override
        public AttributePath getAttributePath() {
            return attributePath;
        }

        @Override
        public AttributeRole getAttributeRole() {
            return attributeRole;
        }

        @Override
        public boolean isIncludedInOptimisticLocking() {
            return false;
        }

        @Override
        public ToolingHintContext getToolingHintContext() {
            return mappingDocument.getToolingHintContext();
        }
    };
    callback.addAttributeSource(virtualAttribute);
}
Also used : AttributeRole(org.hibernate.boot.model.source.spi.AttributeRole) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) EmbeddedAttributeMapping(org.hibernate.boot.model.source.spi.EmbeddedAttributeMapping) JaxbHbmToolingHintType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmToolingHintType) JaxbHbmTuplizerType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTuplizerType) ToolingHintContext(org.hibernate.boot.model.source.spi.ToolingHintContext) EmbeddableMapping(org.hibernate.boot.model.source.spi.EmbeddableMapping) AttributePath(org.hibernate.boot.model.source.spi.AttributePath)

Example 2 with SingularAttributeSourceEmbedded

use of org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded in project hibernate-orm by hibernate.

the class ModelBinder method bindAllEntityAttributes.

private void bindAllEntityAttributes(MappingDocument mappingDocument, EntitySource entitySource, PersistentClass entityDescriptor) {
    final EntityTableXref entityTableXref = mappingDocument.getMetadataCollector().getEntityTableXref(entityDescriptor.getEntityName());
    if (entityTableXref == null) {
        throw new AssertionFailure(String.format(Locale.ENGLISH, "Unable to locate EntityTableXref for entity [%s] : %s", entityDescriptor.getEntityName(), mappingDocument.getOrigin()));
    }
    // make sure we bind secondary tables first!
    for (SecondaryTableSource secondaryTableSource : entitySource.getSecondaryTableMap().values()) {
        final Join secondaryTableJoin = new Join();
        secondaryTableJoin.setPersistentClass(entityDescriptor);
        bindSecondaryTable(mappingDocument, secondaryTableSource, secondaryTableJoin, entityTableXref);
        entityDescriptor.addJoin(secondaryTableJoin);
    }
    for (AttributeSource attributeSource : entitySource.attributeSources()) {
        if (PluralAttributeSource.class.isInstance(attributeSource)) {
            // plural attribute
            final Property attribute = createPluralAttribute(mappingDocument, (PluralAttributeSource) attributeSource, entityDescriptor);
            entityDescriptor.addProperty(attribute);
        } else {
            // singular attribute
            if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
                final SingularAttributeSourceBasic basicAttributeSource = (SingularAttributeSourceBasic) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, basicAttributeSource.getName(), basicAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createBasicAttribute(mappingDocument, basicAttributeSource, new SimpleValue(mappingDocument, table), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, basicAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
                final SingularAttributeSourceEmbedded embeddedAttributeSource = (SingularAttributeSourceEmbedded) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, embeddedAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createEmbeddedAttribute(mappingDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, embeddedAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
                final SingularAttributeSourceManyToOne manyToOneAttributeSource = (SingularAttributeSourceManyToOne) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, manyToOneAttributeSource.getName(), manyToOneAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createManyToOneAttribute(mappingDocument, manyToOneAttributeSource, new ManyToOne(mappingDocument, table), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, manyToOneAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
                final SingularAttributeSourceOneToOne oneToOneAttributeSource = (SingularAttributeSourceOneToOne) attributeSource;
                final Table table = entityDescriptor.getTable();
                final Property attribute = createOneToOneAttribute(mappingDocument, oneToOneAttributeSource, new OneToOne(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
                entityDescriptor.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, oneToOneAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
                final SingularAttributeSourceAny anyAttributeSource = (SingularAttributeSourceAny) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, anyAttributeSource.getName(), anyAttributeSource.getKeySource().getRelationalValueSources());
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createAnyAssociationAttribute(mappingDocument, anyAttributeSource, new Any(mappingDocument, table), entityDescriptor.getEntityName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, anyAttributeSource.getNaturalIdMutability());
            }
        }
    }
}
Also used : SingularAttributeSourceBasic(org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic) AssertionFailure(org.hibernate.AssertionFailure) VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) AttributeSource(org.hibernate.boot.model.source.spi.AttributeSource) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) SingularAttributeSource(org.hibernate.boot.model.source.spi.SingularAttributeSource) Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) Join(org.hibernate.mapping.Join) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) AttributeContainer(org.hibernate.mapping.AttributeContainer) SecondaryTableSource(org.hibernate.boot.model.source.spi.SecondaryTableSource) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) OneToOne(org.hibernate.mapping.OneToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) Identifier(org.hibernate.boot.model.naming.Identifier) EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Example 3 with SingularAttributeSourceEmbedded

use of org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded in project hibernate-orm by hibernate.

the class ModelBinder method determineTable.

private Identifier determineTable(MappingDocument mappingDocument, SingularAttributeSourceEmbedded embeddedAttributeSource) {
    Identifier tableName = null;
    for (AttributeSource attributeSource : embeddedAttributeSource.getEmbeddableSource().attributeSources()) {
        final Identifier determinedName;
        if (RelationalValueSourceContainer.class.isInstance(attributeSource)) {
            determinedName = determineTable(mappingDocument, embeddedAttributeSource.getAttributeRole().getFullPath(), (RelationalValueSourceContainer) attributeSource);
        } else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
            determinedName = determineTable(mappingDocument, (SingularAttributeSourceEmbedded) attributeSource);
        } else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
            determinedName = determineTable(mappingDocument, attributeSource.getAttributeRole().getFullPath(), ((SingularAttributeSourceAny) attributeSource).getKeySource().getRelationalValueSources());
        } else {
            continue;
        }
        if (EqualsHelper.equals(tableName, determinedName)) {
            continue;
        }
        if (tableName != null) {
            throw new MappingException(String.format(Locale.ENGLISH, "Attribute [%s] referenced columns from multiple tables: %s, %s", embeddedAttributeSource.getAttributeRole().getFullPath(), tableName, determinedName), mappingDocument.getOrigin());
        }
        tableName = determinedName;
    }
    return tableName;
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) AttributeSource(org.hibernate.boot.model.source.spi.AttributeSource) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) SingularAttributeSource(org.hibernate.boot.model.source.spi.SingularAttributeSource) RelationalValueSourceContainer(org.hibernate.boot.model.source.spi.RelationalValueSourceContainer) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) MappingException(org.hibernate.boot.MappingException)

Example 4 with SingularAttributeSourceEmbedded

use of org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded in project hibernate-orm by hibernate.

the class ModelBinder method bindAllCompositeAttributes.

private void bindAllCompositeAttributes(MappingDocument sourceDocument, EmbeddableSource embeddableSource, Component component) {
    for (AttributeSource attributeSource : embeddableSource.attributeSources()) {
        Property attribute = null;
        if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
            attribute = createBasicAttribute(sourceDocument, (SingularAttributeSourceBasic) attributeSource, new SimpleValue(sourceDocument, component.getTable()), component.getComponentClassName());
        } else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
            attribute = createEmbeddedAttribute(sourceDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(sourceDocument, component), component.getComponentClassName());
        } else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
            attribute = createManyToOneAttribute(sourceDocument, (SingularAttributeSourceManyToOne) attributeSource, new ManyToOne(sourceDocument, component.getTable()), component.getComponentClassName());
        } else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
            attribute = createOneToOneAttribute(sourceDocument, (SingularAttributeSourceOneToOne) attributeSource, new OneToOne(sourceDocument, component.getTable(), component.getOwner()), component.getComponentClassName());
        } else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
            attribute = createAnyAssociationAttribute(sourceDocument, (SingularAttributeSourceAny) attributeSource, new Any(sourceDocument, component.getTable()), component.getComponentClassName());
        } else if (PluralAttributeSource.class.isInstance(attributeSource)) {
            attribute = createPluralAttribute(sourceDocument, (PluralAttributeSource) attributeSource, component.getOwner());
        } else {
            throw new AssertionFailure(String.format(Locale.ENGLISH, "Unexpected AttributeSource sub-type [%s] as part of composite [%s]", attributeSource.getClass().getName(), attributeSource.getAttributeRole().getFullPath()));
        }
        component.addProperty(attribute);
    }
}
Also used : SingularAttributeSourceBasic(org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic) VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) AttributeSource(org.hibernate.boot.model.source.spi.AttributeSource) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) SingularAttributeSource(org.hibernate.boot.model.source.spi.SingularAttributeSource) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) AssertionFailure(org.hibernate.AssertionFailure) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) OneToOne(org.hibernate.mapping.OneToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Aggregations

SingularAttributeSourceEmbedded (org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded)4 AttributeSource (org.hibernate.boot.model.source.spi.AttributeSource)3 PluralAttributeSource (org.hibernate.boot.model.source.spi.PluralAttributeSource)3 SingularAttributeSource (org.hibernate.boot.model.source.spi.SingularAttributeSource)3 VersionAttributeSource (org.hibernate.boot.model.source.spi.VersionAttributeSource)3 AssertionFailure (org.hibernate.AssertionFailure)2 Identifier (org.hibernate.boot.model.naming.Identifier)2 PluralAttributeElementSourceManyToAny (org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny)2 SingularAttributeSourceAny (org.hibernate.boot.model.source.spi.SingularAttributeSourceAny)2 SingularAttributeSourceBasic (org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic)2 SingularAttributeSourceManyToOne (org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne)2 SingularAttributeSourceOneToOne (org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne)2 Any (org.hibernate.mapping.Any)2 Component (org.hibernate.mapping.Component)2 ManyToOne (org.hibernate.mapping.ManyToOne)2 OneToOne (org.hibernate.mapping.OneToOne)2 Property (org.hibernate.mapping.Property)2 SimpleValue (org.hibernate.mapping.SimpleValue)2 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)2 MappingException (org.hibernate.boot.MappingException)1