Search in sources :

Example 26 with Component

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

the class NonReflectiveBinderTest method testNonMutatedInheritance.

@Test
@TestForIssue(jiraKey = "HBX-718")
public void testNonMutatedInheritance() {
    PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
    MetaAttribute metaAttribute = cm.getMetaAttribute("globalmutated");
    assertNotNull(metaAttribute);
    /*assertEquals( metaAttribute.getValues().size(), 2 );		
		assertEquals( "top level", metaAttribute.getValues().get(0) );*/
    assertEquals("wicked level", metaAttribute.getValue());
    Property property = cm.getProperty("component");
    MetaAttribute propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 3 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
    assertEquals("monetaryamount level", propertyAttribute.getValue());
    org.hibernate.mapping.Component component = (Component) property.getValue();
    property = component.getProperty("x");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount x level", propertyAttribute.getValue());
    property = cm.getProperty("sortedEmployee");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 3 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );*/
    assertEquals("sortedemployee level", propertyAttribute.getValue());
    property = cm.getProperty("anotherSet");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 2 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );*/
    assertEquals("wicked level", propertyAttribute.getValue());
    Bag bag = (Bag) property.getValue();
    component = (Component) bag.getElement();
    assertEquals(4, component.getMetaAttributes().size());
    metaAttribute = component.getMetaAttribute("globalmutated");
    /*assertEquals( metaAttribute.getValues().size(), 3 );
		assertEquals( "top level", metaAttribute.getValues().get(0) );
		assertEquals( "wicked level", metaAttribute.getValues().get(1) );*/
    assertEquals("monetaryamount anotherSet composite level", metaAttribute.getValue());
    property = component.getProperty("emp");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount anotherSet composite property emp level", propertyAttribute.getValue());
    property = component.getProperty("empinone");
    propertyAttribute = property.getMetaAttribute("globalmutated");
    assertNotNull(propertyAttribute);
    /*assertEquals( propertyAttribute.getValues().size(), 4 );
		assertEquals( "top level", propertyAttribute.getValues().get(0) );
		assertEquals( "wicked level", propertyAttribute.getValues().get(1) );
		assertEquals( "monetaryamount anotherSet composite level", propertyAttribute.getValues().get(2) );*/
    assertEquals("monetaryamount anotherSet composite property empinone level", propertyAttribute.getValue());
}
Also used : Component(org.hibernate.mapping.Component) Bag(org.hibernate.mapping.Bag) MetaAttribute(org.hibernate.mapping.MetaAttribute) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 27 with Component

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

the class ValueVisitorTest method testProperCallbacks.

@Test
public void testProperCallbacks() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
    final Table tbl = new Table();
    final RootClass rootClass = new RootClass(metadataBuildingContext);
    ValueVisitor vv = new ValueVisitorValidator();
    new Any(metadata, tbl).accept(vv);
    new Array(metadata, rootClass).accept(vv);
    new Bag(metadata, rootClass).accept(vv);
    new Component(metadata, rootClass).accept(vv);
    new DependantValue(metadata, tbl, null).accept(vv);
    new IdentifierBag(metadata, rootClass).accept(vv);
    new List(metadata, rootClass).accept(vv);
    new ManyToOne(metadata, tbl).accept(vv);
    new Map(metadata, rootClass).accept(vv);
    new OneToMany(metadata, rootClass).accept(vv);
    new OneToOne(metadata, tbl, rootClass).accept(vv);
    new PrimitiveArray(metadata, rootClass).accept(vv);
    new Set(metadata, rootClass).accept(vv);
    new SimpleValue(metadata).accept(vv);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Set(org.hibernate.mapping.Set) ValueVisitor(org.hibernate.mapping.ValueVisitor) DependantValue(org.hibernate.mapping.DependantValue) MetadataSources(org.hibernate.boot.MetadataSources) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IdentifierBag(org.hibernate.mapping.IdentifierBag) OneToMany(org.hibernate.mapping.OneToMany) Any(org.hibernate.mapping.Any) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) OneToOne(org.hibernate.mapping.OneToOne) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) List(org.hibernate.mapping.List) Component(org.hibernate.mapping.Component) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 28 with Component

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

the class CollectionMetadataGenerator method searchMappedByKey.

@SuppressWarnings({ "unchecked" })
private String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) {
    final Iterator<Value> assocIdClassProps = referencedClass.getKeyClosureIterator();
    while (assocIdClassProps.hasNext()) {
        final Value value = assocIdClassProps.next();
        // make sure its a 'Component' because IdClass is registered as this type.
        if (value instanceof Component) {
            final Component component = (Component) value;
            final Iterator<Property> componentPropertyIterator = component.getPropertyIterator();
            while (componentPropertyIterator.hasNext()) {
                final Property property = componentPropertyIterator.next();
                final Iterator<Selectable> propertySelectables = property.getValue().getColumnIterator();
                final Iterator<Selectable> collectionSelectables = collectionValue.getKey().getColumnIterator();
                if (Tools.iteratorsContentEqual(propertySelectables, collectionSelectables)) {
                    return property.getName();
                }
            }
        }
    }
    return null;
}
Also used : Selectable(org.hibernate.mapping.Selectable) Value(org.hibernate.mapping.Value) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Example 29 with Component

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

the class ClassesAuditingData method updateCalculatedProperty.

private void updateCalculatedProperty(String entityName, Property property, String propertyName, AuditedPropertiesHolder propertyHolder) {
    final PropertyAuditingData propertyAuditingData = propertyHolder.getPropertyAuditingData(propertyName);
    final boolean isAuditMappedBy = propertyAuditingData.getAuditMappedBy() != null;
    final boolean isRelationMappedBy = propertyAuditingData.getRelationMappedBy() != null;
    // handle updating the property, if applicable.
    if (isAuditMappedBy || isRelationMappedBy) {
        final String referencedEntityName = MappingTools.getReferencedEntityName(property.getValue());
        final ClassAuditingData referencedAuditData = entityNameToAuditingData.get(referencedEntityName);
        if (isAuditMappedBy) {
            // If a property had the @AuditMappedBy annotation, setting the referenced fields to be always insertable.
            setAuditMappedByInsertable(referencedEntityName, entityName, referencedAuditData, propertyAuditingData);
        } else if (isRelationMappedBy && (property.getValue() instanceof List)) {
            // If a property has mappedBy= and @Indexed and isn't @AuditMappedBy, add synthetic support.
            addSyntheticIndexProperty((List) property.getValue(), property.getPropertyAccessorName(), referencedAuditData);
        }
    }
    // This is useful for AuditMappedBy inside an Embeddable that holds a collection of entities.
    if (propertyAuditingData instanceof ComponentAuditingData) {
        final ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;
        final Component component = (Component) property.getValue();
        for (String componentPropertyName : componentAuditingData.getNonSyntheticPropertyNames()) {
            final Property componentProperty = component.getProperty(componentPropertyName);
            updateCalculatedProperty(entityName, componentProperty, componentPropertyName, componentAuditingData);
        }
    }
}
Also used : ClassAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData) ComponentAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ComponentAuditingData) List(org.hibernate.mapping.List) PropertyAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.PropertyAuditingData) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Example 30 with Component

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

the class ModelBinder method bindMapKey.

private void bindMapKey(final MappingDocument mappingDocument, final IndexedPluralAttributeSource pluralAttributeSource, final org.hibernate.mapping.Map collectionBinding) {
    if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic) {
        final PluralAttributeMapKeySourceBasic mapKeySource = (PluralAttributeMapKeySourceBasic) pluralAttributeSource.getIndexSource();
        final SimpleValue value = new SimpleValue(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        bindSimpleValueType(mappingDocument, mapKeySource.getTypeInformation(), value);
        if (!value.isTypeSpecified()) {
            throw new MappingException("map index element must specify a type: " + pluralAttributeSource.getAttributeRole().getFullPath(), mappingDocument.getOrigin());
        }
        relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), value, true, new RelationalObjectBinder.ColumnNamingDelegate() {

            @Override
            public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
                return database.toIdentifier(IndexedCollection.DEFAULT_INDEX_COLUMN_NAME);
            }
        });
        collectionBinding.setIndex(value);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded) {
        final PluralAttributeMapKeySourceEmbedded mapKeySource = (PluralAttributeMapKeySourceEmbedded) pluralAttributeSource.getIndexSource();
        final Component componentBinding = new Component(mappingDocument.getMetadataCollector(), collectionBinding);
        bindComponent(mappingDocument, mapKeySource.getEmbeddableSource(), componentBinding, null, pluralAttributeSource.getName(), mapKeySource.getXmlNodeName(), false);
        collectionBinding.setIndex(componentBinding);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource) {
        final PluralAttributeMapKeyManyToManySource mapKeySource = (PluralAttributeMapKeyManyToManySource) pluralAttributeSource.getIndexSource();
        final ManyToOne mapKeyBinding = new ManyToOne(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        mapKeyBinding.setReferencedEntityName(mapKeySource.getReferencedEntityName());
        relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), mapKeyBinding, true, new RelationalObjectBinder.ColumnNamingDelegate() {

            @Override
            public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
                return implicitNamingStrategy.determineMapKeyColumnName(new ImplicitMapKeyColumnNameSource() {

                    @Override
                    public AttributePath getPluralAttributePath() {
                        return pluralAttributeSource.getAttributePath();
                    }

                    @Override
                    public MetadataBuildingContext getBuildingContext() {
                        return context;
                    }
                });
            }
        });
        collectionBinding.setIndex(mapKeyBinding);
    } else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource) {
        final PluralAttributeMapKeyManyToAnySource mapKeySource = (PluralAttributeMapKeyManyToAnySource) pluralAttributeSource.getIndexSource();
        final Any mapKeyBinding = new Any(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
        bindAny(mappingDocument, mapKeySource, mapKeyBinding, pluralAttributeSource.getAttributeRole().append("key"), pluralAttributeSource.getAttributePath().append("key"));
        collectionBinding.setIndex(mapKeyBinding);
    }
}
Also used : PluralAttributeMapKeyManyToAnySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToAnySource) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException) Identifier(org.hibernate.boot.model.naming.Identifier) PluralAttributeMapKeySourceEmbedded(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceEmbedded) PluralAttributeMapKeyManyToManySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToManySource) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Component(org.hibernate.mapping.Component) ImplicitMapKeyColumnNameSource(org.hibernate.boot.model.naming.ImplicitMapKeyColumnNameSource) PluralAttributeMapKeySourceBasic(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceBasic)

Aggregations

Component (org.hibernate.mapping.Component)42 Property (org.hibernate.mapping.Property)29 PersistentClass (org.hibernate.mapping.PersistentClass)17 Iterator (java.util.Iterator)11 AnnotationException (org.hibernate.AnnotationException)9 SimpleValue (org.hibernate.mapping.SimpleValue)9 XProperty (org.hibernate.annotations.common.reflection.XProperty)8 ManyToOne (org.hibernate.mapping.ManyToOne)8 Value (org.hibernate.mapping.Value)8 HashMap (java.util.HashMap)6 Collection (org.hibernate.mapping.Collection)6 ArrayList (java.util.ArrayList)5 AssertionFailure (org.hibernate.AssertionFailure)5 MappingException (org.hibernate.MappingException)5 Any (org.hibernate.mapping.Any)5 Column (org.hibernate.mapping.Column)5 Join (org.hibernate.mapping.Join)5 XClass (org.hibernate.annotations.common.reflection.XClass)4 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)4 Ejb3Column (org.hibernate.cfg.Ejb3Column)3