use of org.hibernate.mapping.Bag 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.Bag 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.Bag in project hibernate-orm by hibernate.
the class ModelBinder method createPluralAttribute.
private Property createPluralAttribute(MappingDocument sourceDocument, PluralAttributeSource attributeSource, PersistentClass entityDescriptor) {
final Collection collectionBinding;
if (attributeSource instanceof PluralAttributeSourceListImpl) {
collectionBinding = new org.hibernate.mapping.List(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributeListSecondPass(sourceDocument, (IndexedPluralAttributeSource) attributeSource, (org.hibernate.mapping.List) collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourceSetImpl) {
collectionBinding = new Set(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributeSetSecondPass(sourceDocument, attributeSource, collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourceMapImpl) {
collectionBinding = new org.hibernate.mapping.Map(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributeMapSecondPass(sourceDocument, (IndexedPluralAttributeSource) attributeSource, (org.hibernate.mapping.Map) collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourceBagImpl) {
collectionBinding = new Bag(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributeBagSecondPass(sourceDocument, attributeSource, collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourceIdBagImpl) {
collectionBinding = new IdentifierBag(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributeIdBagSecondPass(sourceDocument, attributeSource, collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourceArrayImpl) {
final PluralAttributeSourceArray arraySource = (PluralAttributeSourceArray) attributeSource;
collectionBinding = new Array(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
((Array) collectionBinding).setElementClassName(sourceDocument.qualifyClassName(arraySource.getElementClass()));
registerSecondPass(new PluralAttributeArraySecondPass(sourceDocument, arraySource, (Array) collectionBinding), sourceDocument);
} else if (attributeSource instanceof PluralAttributeSourcePrimitiveArrayImpl) {
collectionBinding = new PrimitiveArray(sourceDocument.getMetadataCollector(), entityDescriptor);
bindCollectionMetadata(sourceDocument, attributeSource, collectionBinding);
registerSecondPass(new PluralAttributePrimitiveArraySecondPass(sourceDocument, (IndexedPluralAttributeSource) attributeSource, (PrimitiveArray) collectionBinding), sourceDocument);
} else {
throw new AssertionFailure("Unexpected PluralAttributeSource type : " + attributeSource.getClass().getName());
}
sourceDocument.getMetadataCollector().addCollectionBinding(collectionBinding);
final Property attribute = new Property();
attribute.setValue(collectionBinding);
bindProperty(sourceDocument, attributeSource, attribute);
return attribute;
}
use of org.hibernate.mapping.Bag in project hibernate-orm by hibernate.
the class ComponentNamingStrategyTest method testComponentSafeNamingStrategy.
@Test
@TestForIssue(jiraKey = "HHH-6005")
public void testComponentSafeNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyComponentPathImpl.INSTANCE).build();
final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
Property p = pc.getProperty("items");
Bag value = assertTyping(Bag.class, p.getValue());
SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
assertEquals(1, elementValue.getColumnSpan());
Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
assertEquals("items_name", column.getName());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.Bag in project hibernate-orm by hibernate.
the class ComponentNamingStrategyTest method testDefaultNamingStrategy.
@Test
public void testDefaultNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
Property p = pc.getProperty("items");
Bag value = assertTyping(Bag.class, p.getValue());
SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
assertEquals(1, elementValue.getColumnSpan());
Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
assertEquals(column.getName(), "name");
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations