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());
}
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);
}
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;
}
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);
}
}
}
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);
}
}
Aggregations