Search in sources :

Example 1 with Bag

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());
}
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 2 with Bag

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);
}
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 3 with Bag

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;
}
Also used : Set(org.hibernate.mapping.Set) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty) AssertionFailure(org.hibernate.AssertionFailure) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) IdentifierBag(org.hibernate.mapping.IdentifierBag) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) PluralAttributeSourceArray(org.hibernate.boot.model.source.spi.PluralAttributeSourceArray) Array(org.hibernate.mapping.Array) PluralAttributeSourceArray(org.hibernate.boot.model.source.spi.PluralAttributeSourceArray) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) Collection(org.hibernate.mapping.Collection) IndexedCollection(org.hibernate.mapping.IndexedCollection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Bag

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Bag(org.hibernate.mapping.Bag) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with Bag

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Bag(org.hibernate.mapping.Bag) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

Bag (org.hibernate.mapping.Bag)6 Property (org.hibernate.mapping.Property)5 Test (org.junit.Test)5 PersistentClass (org.hibernate.mapping.PersistentClass)4 MetadataSources (org.hibernate.boot.MetadataSources)3 Column (org.hibernate.mapping.Column)3 SimpleValue (org.hibernate.mapping.SimpleValue)3 Metadata (org.hibernate.boot.Metadata)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 Array (org.hibernate.mapping.Array)2 Component (org.hibernate.mapping.Component)2 IdentifierBag (org.hibernate.mapping.IdentifierBag)2 PrimitiveArray (org.hibernate.mapping.PrimitiveArray)2 Set (org.hibernate.mapping.Set)2 Table (org.hibernate.mapping.Table)2 TestForIssue (org.hibernate.testing.TestForIssue)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1