From: <hib...@li...> - 2006-08-02 15:06:01
|
Author: max...@jb... Date: 2006-08-02 11:05:52 -0400 (Wed, 02 Aug 2006) New Revision: 10192 Modified: trunk/Hibernate3/src/org/hibernate/cfg/CollectionSecondPass.java trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java trunk/Hibernate3/test/org/hibernate/test/legacy/NonReflectiveBinderTest.java trunk/Hibernate3/test/org/hibernate/test/legacy/Wicked.hbm.xml Log: HHH-1963 meta inheritance is broken HBX-719 Modified: trunk/Hibernate3/src/org/hibernate/cfg/CollectionSecondPass.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/CollectionSecondPass.java 2006-08-02 15:05:40 UTC (rev 10191) +++ trunk/Hibernate3/src/org/hibernate/cfg/CollectionSecondPass.java 2006-08-02 15:05:52 UTC (rev 10192) @@ -1,7 +1,9 @@ //$Id$ package org.hibernate.cfg; +import java.util.Collections; import java.util.Iterator; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -21,18 +23,24 @@ private static Log log = LogFactory.getLog( CollectionSecondPass.class ); Mappings mappings; Collection collection; + private Map localInheritedMetas; - public CollectionSecondPass(Mappings mappings, Collection collection) { + public CollectionSecondPass(Mappings mappings, Collection collection, java.util.Map inheritedMetas) { this.collection = collection; this.mappings = mappings; + this.localInheritedMetas = inheritedMetas; } + public CollectionSecondPass(Mappings mappings, Collection collection) { + this(mappings, collection, Collections.EMPTY_MAP); + } + public void doSecondPass(java.util.Map persistentClasses, java.util.Map inheritedMetas) throws MappingException { if ( log.isDebugEnabled() ) log.debug( "Second pass for collection: " + collection.getRole() ); - secondPass( persistentClasses, inheritedMetas ); + secondPass( persistentClasses, localInheritedMetas ); // using local since the inheritedMetas at this point is not the correct map since it is always the empty map collection.createAllKeys(); if ( log.isDebugEnabled() ) { Modified: trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-08-02 15:05:40 UTC (rev 10191) +++ trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-08-02 15:05:52 UTC (rev 10192) @@ -1051,7 +1051,7 @@ while ( iter.hasNext() ) { SecondPass sp = (SecondPass) iter.next(); if ( ! (sp instanceof QuerySecondPass) ) { - sp.doSecondPass( classes, CollectionHelper.EMPTY_MAP ); // TODO: align meta-attributes with normal bind... + sp.doSecondPass( classes, CollectionHelper.EMPTY_MAP ); iter.remove(); } } @@ -1060,7 +1060,7 @@ iter = secondPasses.iterator(); while ( iter.hasNext() ) { SecondPass sp = (SecondPass) iter.next(); - sp.doSecondPass( classes, CollectionHelper.EMPTY_MAP ); // TODO: align meta-attributes with normal bind... + sp.doSecondPass( classes, CollectionHelper.EMPTY_MAP ); iter.remove(); } Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-08-02 15:05:40 UTC (rev 10191) +++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-08-02 15:05:52 UTC (rev 10192) @@ -2,6 +2,7 @@ package org.hibernate.cfg; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -1287,7 +1288,7 @@ * Called for all collections */ public static void bindCollection(Element node, Collection collection, String className, - String path, Mappings mappings) throws MappingException { + String path, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { // ROLENAME collection.setRole(path); @@ -1438,20 +1439,21 @@ handleCustomSQL( node, collection ); // set up second pass if ( collection instanceof List ) { - mappings.addSecondPass( new ListSecondPass( node, mappings, (List) collection ) ); + mappings.addSecondPass( new ListSecondPass( node, mappings, (List) collection, inheritedMetas ) ); } else if ( collection instanceof Map ) { - mappings.addSecondPass( new MapSecondPass( node, mappings, (Map) collection ) ); + mappings.addSecondPass( new MapSecondPass( node, mappings, (Map) collection, inheritedMetas ) ); } else if ( collection instanceof IdentifierCollection ) { mappings.addSecondPass( new IdentifierCollectionSecondPass( node, mappings, - collection + collection, + inheritedMetas ) ); } else { - mappings.addSecondPass( new CollectionSecondPass( node, mappings, collection ) ); + mappings.addSecondPass( new CollectionSecondPass( node, mappings, collection, inheritedMetas ) ); } Iterator iter = node.elementIterator( "filter" ); @@ -1669,9 +1671,9 @@ * Called for arrays and primitive arrays */ public static void bindArray(Element node, Array array, String prefix, String path, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { - bindCollection( node, array, prefix, path, mappings ); + bindCollection( node, array, prefix, path, mappings, inheritedMetas ); Attribute att = node.attribute( "element-class" ); if ( att != null ) array.setElementClassName( getClassName( att, mappings ) ); @@ -1770,7 +1772,8 @@ component.setEmbedded( isEmbedded ); component.setRoleName( path ); - component.setMetaAttributes( getMetas( node, inheritedMetas ) ); + inheritedMetas = getMetas( node, inheritedMetas ); + component.setMetaAttributes( inheritedMetas ); Attribute classNode = isIdentifierMapper ? null : node.attribute( "class" ); if ( classNode != null ) { @@ -1823,7 +1826,7 @@ subnode, subpath, component.getOwner(), - mappings + mappings, inheritedMetas ); mappings.addCollection( collection ); value = collection; @@ -2048,7 +2051,7 @@ subnode, StringHelper.qualify( entityName, propertyName ), persistentClass, - mappings + mappings, inheritedMetas ); mappings.addCollection( collection ); value = collection; @@ -2639,8 +2642,8 @@ static class CollectionSecondPass extends org.hibernate.cfg.CollectionSecondPass { Element node; - CollectionSecondPass(Element node, Mappings mappings, Collection collection) { - super(mappings, collection); + CollectionSecondPass(Element node, Mappings mappings, Collection collection, java.util.Map inheritedMetas) { + super(mappings, collection, inheritedMetas); this.node = node; } @@ -2657,8 +2660,8 @@ } static class IdentifierCollectionSecondPass extends CollectionSecondPass { - IdentifierCollectionSecondPass(Element node, Mappings mappings, Collection collection) { - super( node, mappings, collection ); + IdentifierCollectionSecondPass(Element node, Mappings mappings, Collection collection, java.util.Map inheritedMetas) { + super( node, mappings, collection, inheritedMetas ); } public void secondPass(java.util.Map persistentClasses, java.util.Map inheritedMetas) @@ -2675,8 +2678,8 @@ } static class MapSecondPass extends CollectionSecondPass { - MapSecondPass(Element node, Mappings mappings, Map collection) { - super( node, mappings, collection ); + MapSecondPass(Element node, Mappings mappings, Map collection, java.util.Map inheritedMetas) { + super( node, mappings, collection, inheritedMetas ); } public void secondPass(java.util.Map persistentClasses, java.util.Map inheritedMetas) @@ -2707,8 +2710,8 @@ } static class ListSecondPass extends CollectionSecondPass { - ListSecondPass(Element node, Mappings mappings, List collection) { - super( node, mappings, collection ); + ListSecondPass(Element node, Mappings mappings, List collection, java.util.Map inheritedMetas) { + super( node, mappings, collection, inheritedMetas ); } public void secondPass(java.util.Map persistentClasses, java.util.Map inheritedMetas) @@ -2729,7 +2732,7 @@ private String xmlTag; public abstract Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException; + Mappings mappings, java.util.Map inheritedMetas) throws MappingException; CollectionType(String xmlTag) { this.xmlTag = xmlTag; @@ -2741,57 +2744,57 @@ private static final CollectionType MAP = new CollectionType( "map" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { Map map = new Map( owner ); - bindCollection( node, map, owner.getEntityName(), path, mappings ); + bindCollection( node, map, owner.getEntityName(), path, mappings, inheritedMetas ); return map; } }; private static final CollectionType SET = new CollectionType( "set" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { Set set = new Set( owner ); - bindCollection( node, set, owner.getEntityName(), path, mappings ); + bindCollection( node, set, owner.getEntityName(), path, mappings, inheritedMetas ); return set; } }; private static final CollectionType LIST = new CollectionType( "list" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { List list = new List( owner ); - bindCollection( node, list, owner.getEntityName(), path, mappings ); + bindCollection( node, list, owner.getEntityName(), path, mappings, inheritedMetas ); return list; } }; private static final CollectionType BAG = new CollectionType( "bag" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { Bag bag = new Bag( owner ); - bindCollection( node, bag, owner.getEntityName(), path, mappings ); + bindCollection( node, bag, owner.getEntityName(), path, mappings, inheritedMetas ); return bag; } }; private static final CollectionType IDBAG = new CollectionType( "idbag" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { IdentifierBag bag = new IdentifierBag( owner ); - bindCollection( node, bag, owner.getEntityName(), path, mappings ); + bindCollection( node, bag, owner.getEntityName(), path, mappings, inheritedMetas ); return bag; } }; private static final CollectionType ARRAY = new CollectionType( "array" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { Array array = new Array( owner ); - bindArray( node, array, owner.getEntityName(), path, mappings ); + bindArray( node, array, owner.getEntityName(), path, mappings, inheritedMetas ); return array; } }; private static final CollectionType PRIMITIVE_ARRAY = new CollectionType( "primitive-array" ) { public Collection create(Element node, String path, PersistentClass owner, - Mappings mappings) throws MappingException { + Mappings mappings, java.util.Map inheritedMetas) throws MappingException { PrimitiveArray array = new PrimitiveArray( owner ); - bindArray( node, array, owner.getEntityName(), path, mappings ); + bindArray( node, array, owner.getEntityName(), path, mappings, inheritedMetas ); return array; } }; @@ -2854,10 +2857,18 @@ String name = metaNode.attributeValue( "attribute" ); MetaAttribute meta = (MetaAttribute) map.get( name ); - if ( meta == null ) { + MetaAttribute inheritedAttribute = (MetaAttribute) inheritedMeta.get( name ); + if ( meta == null ) { meta = new MetaAttribute( name ); map.put( name, meta ); - } + } else if (meta == inheritedAttribute) { // to prevent mutation of the inherited meta attribute. + meta = new MetaAttribute( name ); + map.put( name, meta ); + java.util.List values = inheritedAttribute.getValues(); + for (Iterator iterator = values.iterator(); iterator.hasNext();) { + meta.addValue( (String) iterator.next() ); + } + } meta.addValue( metaNode.getText() ); } return map; Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/NonReflectiveBinderTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/legacy/NonReflectiveBinderTest.java 2006-08-02 15:05:40 UTC (rev 10191) +++ trunk/Hibernate3/test/org/hibernate/test/legacy/NonReflectiveBinderTest.java 2006-08-02 15:05:52 UTC (rev 10192) @@ -10,7 +10,9 @@ import org.hibernate.MappingException; import org.hibernate.cfg.Configuration; +import org.hibernate.mapping.Bag; import org.hibernate.mapping.Collection; +import org.hibernate.mapping.Component; import org.hibernate.mapping.MetaAttribute; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -30,7 +32,7 @@ } public String[] getMappings() { - return new String[] { "legacy/Wicked.hbm.xml" }; + return new String[] { "legacy/Wicked.hbm.xml"}; } void buildConfiguration(String[] files) throws MappingException { @@ -46,7 +48,6 @@ throw e; } - } protected void setUp() throws Exception { @@ -108,6 +109,91 @@ } + // HBX-718 + public void testNonMutatedInheritance() { + Configuration cfg = getCfg(); + cfg.buildMappings(); + + PersistentClass cm = cfg.getClassMapping("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.getValues().get(1) ); + + 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.getValues().get(2) ); + + 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.getValues().get(3) ); + + 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.getValues().get(2) ); + + 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.getValues().get(1) ); + + 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.getValues().get(2) ); + + 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.getValues().get(3) ); + + + 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.getValues().get(3) ); + + + } + public void testComparator() { Configuration cfg = getCfg(); cfg.buildMappings(); Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/Wicked.hbm.xml =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/legacy/Wicked.hbm.xml 2006-08-02 15:05:40 UTC (rev 10191) +++ trunk/Hibernate3/test/org/hibernate/test/legacy/Wicked.hbm.xml 2006-08-02 15:05:52 UTC (rev 10192) @@ -7,6 +7,8 @@ <hibernate-mapping default-lazy="false"> <meta attribute="global">global value</meta> <meta attribute="globalnoinherit" inherit="false">only visible at top level</meta> + <meta attribute="globalmutated">top level</meta> + <class name="org.hibernate.test.legacy.Wicked" table="WICKED" schema="HR"> @@ -14,7 +16,7 @@ <meta attribute="implements">java.lang.Observer</meta> <meta attribute="implements" inherit="false">org.foo.BogusVisitor</meta> <meta attribute="extends">AuditInfo</meta> - + <meta attribute="globalmutated">wicked level</meta> <id name="id" type="long" column="EMPLOYEE_ID"> @@ -31,14 +33,30 @@ <component name="component" class="net.sf.hibern8ide.test.MonetaryAmount"> <meta attribute="componentonly" inherit="true"/> <meta attribute="allcomponent"/> - <property name="x" type="string"/> + <meta attribute="globalmutated">monetaryamount level</meta> + <property name="x" type="string"> + <meta attribute="globalmutated">monetaryamount x level</meta> + </property> </component> <set name="sortedEmployee" sort="org.hibernate.test.legacy.NonExistingComparator"> + <meta attribute="globalmutated">sortedemployee level</meta> <key column="attrb_id"/> <many-to-many class="org.hibernate.test.legacy.Employee" column="id"/> </set> + <bag name="anotherSet"> + <key column="attrb2_id"/> + <composite-element class="org.hibernate.test.legacy.Employee"> + <meta attribute="globalmutated">monetaryamount anotherSet composite level</meta> + <property name="emp" type="string"> + <meta attribute="globalmutated">monetaryamount anotherSet composite property emp level</meta> + </property> + <many-to-one name="empinone" class="org.hibernate.test.legacy.Employee"> + <meta attribute="globalmutated">monetaryamount anotherSet composite property empinone level</meta> + </many-to-one> + </composite-element> + </bag> </class> |