This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
View | Details | Raw Unified | Return to bug 284877 | Differences between
and this patch

Collapse All | Expand All

(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-6 / +125 lines)
Lines 71-76 Link Here
71
import org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor;
71
import org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor;
72
import org.eclipse.persistence.testing.models.jpa.metamodel.Board;
72
import org.eclipse.persistence.testing.models.jpa.metamodel.Board;
73
import org.eclipse.persistence.testing.models.jpa.metamodel.Computer;
73
import org.eclipse.persistence.testing.models.jpa.metamodel.Computer;
74
import org.eclipse.persistence.testing.models.jpa.metamodel.Corporation;
74
import org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK;
75
import org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK;
75
import org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition;
76
import org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition;
76
import org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner;
77
import org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner;
Lines 588-593 Link Here
588
            Type<?> personIdType = null;
589
            Type<?> personIdType = null;
589
            MappedSuperclassTypeImpl<Person> msPerson = (MappedSuperclassTypeImpl)metamodel.type(Person.class);
590
            MappedSuperclassTypeImpl<Person> msPerson = (MappedSuperclassTypeImpl)metamodel.type(Person.class);
590
            assertNotNull(msPerson);
591
            assertNotNull(msPerson);
592
            MappedSuperclassTypeImpl<Corporation> msCorporation = (MappedSuperclassTypeImpl)metamodel.type(Corporation.class);
593
            assertNotNull(msCorporation);
591
            
594
            
592
            try {
595
            try {
593
                personIdType = msPerson.getIdType();
596
                personIdType = msPerson.getIdType();
Lines 821-826 Link Here
821
            
824
            
822
            /**
825
            /**
823
             *  Return the attributes declared by the managed type.
826
             *  Return the attributes declared by the managed type.
827
             *  Testing for Design Issue 52:
828
             *  http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI:52_Refactor:_20090817
824
             */
829
             */
825
             //java.util.Set<Attribute<X, ?>> getDeclaredAttributes();
830
             //java.util.Set<Attribute<X, ?>> getDeclaredAttributes();
826
            expectedIAExceptionThrown = false;            
831
            expectedIAExceptionThrown = false;            
Lines 831-858 Link Here
831
                 *     +
836
                 *     +
832
                 *     +- id : Integer
837
                 *     +- id : Integer
833
                 *     +- name : String
838
                 *     +- name : String
839
                 *     +- historicalEmployers : Manufacturer
834
                 *     
840
                 *     
835
                 *     Corporation : MappedSuperclass extends Person
841
                 *     Corporation : MappedSuperclass extends Person
836
                 *       +
842
                 *       +
837
                 *       +- corpComputers : Set 
843
                 *       +- corporateComputers : Collection 
838
                 *       
844
                 *       
839
                 *       Manufacturer : Entity extends Corporation
845
                 *       Manufacturer : Entity extends Corporation
840
                 *         +
846
                 *         +
841
                 *         +- computers : Set
847
                 *         +- computers : Set
842
                 *         +- hardwareDesigners : Set
848
                 *         +- hardwareDesigners : List
843
                 *         +- hardwareDesignersMap : Map
849
                 *         +- hardwareDesignersMap : Map
844
                 *         +- version : int
850
                 *         +- version : int
845
                 */
851
                 */
846
                Set<Attribute<Manufacturer, ?>> declaredAttributesSet = entityManufacturer.getDeclaredAttributes();
852
                Set<Attribute<Manufacturer, ?>> declaredAttributesSet = entityManufacturer.getDeclaredAttributes();
847
                //System.out.println("entityManufacturer.getDeclaredAttributes() " + declaredAttributesSet);
853
                //System.out.println("entityManufacturer.getDeclaredAttributes() " + declaredAttributesSet);
848
                assertNotNull(declaredAttributesSet);
854
                assertNotNull(declaredAttributesSet);
849
                // We should see 4 declared out of 7 attributes for Manufacturer 
855
                // We should see 4 declared out of 8 attributes for Manufacturer 
850
                assertEquals(4, declaredAttributesSet.size());
856
                assertEquals(4, declaredAttributesSet.size());
851
                // Id is declared 2 levels above
857
                // Id is declared 2 levels above
852
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("id"))); //
858
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("id"))); //
853
                // name is declared 2 levels above
859
                // name is declared 2 levels above
854
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("name"))); //
860
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("name"))); //
855
                // corpComputers is declared 1 level above
861
                // corporateComputers is declared 1 level above
856
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("corporateComputers"))); //
862
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("corporateComputers"))); //
857
                // version is declared at this level
863
                // version is declared at this level
858
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("version"))); //
864
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("version"))); //
Lines 861-867 Link Here
861
                // hardwareDesigners is declared at this level
867
                // hardwareDesigners is declared at this level
862
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesigners"))); //
868
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesigners"))); //
863
                // hardwareDesignersMap is declared at this level
869
                // hardwareDesignersMap is declared at this level
864
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesignersMap"))); //                
870
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesignersMap"))); //
871
                // historicalEmployers is declared 2 levels above
872
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("historicalEmployers"))); //
873
                
874
                Set<Attribute<Corporation, ?>> declaredAttributesSetForCorporation = msCorporation.getDeclaredAttributes();
875
                assertNotNull(declaredAttributesSetForCorporation);
876
                // We should see 1 declared out of 4 attributes for Computer 
877
                assertEquals(1, declaredAttributesSetForCorporation.size());
878
                // Id is declared 1 level above
879
                //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("id"))); //
880
                // name is declared 1 level above but is not visible in a ms-->ms hierarchy
881
                //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("name"))); //
882
                // corporateComputers is declared at this level
883
                assertTrue(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("corporateComputers"))); //
884
                // historicalEmployers is declared 1 level above but is not visible in a ms-->ms hierarchy
885
                //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("historicalEmployers"))); //                
886
887
                Set<Attribute<Person, ?>> declaredAttributesSetForPerson = msPerson.getDeclaredAttributes();
888
                assertNotNull(declaredAttributesSetForPerson);
889
                // We should see 3 declared out of 3 attributes for Person 
890
                assertEquals(3, declaredAttributesSetForPerson.size());
891
                // Id is declared at this level
892
                assertTrue(declaredAttributesSetForPerson.contains(msPerson.getAttribute("id"))); //
893
                // name is declared at this level
894
                assertTrue(declaredAttributesSetForPerson.contains(msPerson.getAttribute("name"))); //
895
                // historicalEmployers is declared at this level
896
                assertTrue(declaredAttributesSetForPerson.contains(msPerson.getAttribute("historicalEmployers"))); //
897
865
            } catch (IllegalArgumentException iae) {
898
            } catch (IllegalArgumentException iae) {
866
                iae.printStackTrace();
899
                iae.printStackTrace();
867
                expectedIAExceptionThrown = true;            
900
                expectedIAExceptionThrown = true;            
Lines 1238-1246 Link Here
1238
                expectedIAExceptionThrown = true;            
1271
                expectedIAExceptionThrown = true;            
1239
            }
1272
            }
1240
            assertTrue(expectedIAExceptionThrown);
1273
            assertTrue(expectedIAExceptionThrown);
1274
1275
            expectedIAExceptionThrown = false;            
1276
            Attribute<Manufacturer, ?> aListAttribute = null;
1277
            try {
1278
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1279
                // the attribute is on the class
1280
                aListAttribute = entityManufacturer.getDeclaredAttribute("hardwareDesigners");//, entityComputer.getJavaType());
1281
            } catch (IllegalArgumentException iae) {
1282
                // expecting
1283
                // java.lang.IllegalArgumentException: The declared attribute [corporateComputers] from the managed type [ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)])]] is not present - however, it is declared on a superclass.
1284
                //iae.printStackTrace();
1285
                expectedIAExceptionThrown = true;            
1286
            }
1287
            assertFalse(expectedIAExceptionThrown);
1288
            assertNotNull(aListAttribute);
1289
1290
1291
            // check the root
1292
            expectedIAExceptionThrown = false;            
1293
            Attribute<Person, Manufacturer> aCollectionAttribute = null;
1294
            try {
1295
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1296
                // the attribute is on the class
1297
                IdentifiableType person = entityManufacturer.getSupertype().getSupertype();
1298
                aCollectionAttribute = person.getDeclaredAttribute("historicalEmployers");//, entityComputer.getJavaType());
1299
            } catch (IllegalArgumentException iae) {
1300
                // expecting
1301
                // java.lang.IllegalArgumentException: The declared attribute [corporateComputers] from the managed type [ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)])]] is not present - however, it is declared on a superclass.
1302
                //iae.printStackTrace();
1303
                expectedIAExceptionThrown = true;            
1304
            }
1305
            assertFalse(expectedIAExceptionThrown);
1306
            assertNotNull(aCollectionAttribute);
1307
            // check managed type
1308
            assertEquals(msPerson, aCollectionAttribute.getDeclaringType());            
1309
            // check element type
1310
            //assertEquals(entityManufacturer, aCollectionAttribute.getDeclaringType());
1311
1312
1313
            // positive: check one level down from the root
1314
            expectedIAExceptionThrown = false;            
1315
            Attribute<Corporation,?> aCollectionAttribute2 = null;
1316
            try {
1317
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1318
                // the attribute is on the class
1319
                IdentifiableType corporation = entityManufacturer.getSupertype();                
1320
                aCollectionAttribute2 = corporation.getDeclaredAttribute("corporateComputers");//, entityComputer.getJavaType());
1321
            } catch (IllegalArgumentException iae) {
1322
                // expecting
1323
                // java.lang.IllegalArgumentException: The declared attribute [corporateComputers] from the managed type [ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)])]] is not present - however, it is declared on a superclass.
1324
                //iae.printStackTrace();
1325
                expectedIAExceptionThrown = true;            
1326
            }
1327
            assertFalse(expectedIAExceptionThrown);
1328
            assertNotNull(aCollectionAttribute2);
1329
1330
            // negative: check one level down from the root
1331
            expectedIAExceptionThrown = false;            
1332
            aCollectionAttribute2 = null;
1333
            try {
1334
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1335
                // the attribute is on the class
1336
                IdentifiableType corporation = entityManufacturer.getSupertype();                
1337
                aCollectionAttribute2 = corporation.getDeclaredAttribute("notFound");//, entityComputer.getJavaType());
1338
            } catch (IllegalArgumentException iae) {
1339
                // expecting
1340
                // java.lang.IllegalArgumentException: The declared attribute [corporateComputers] from the managed type [ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)])]] is not present - however, it is declared on a superclass.
1341
                //iae.printStackTrace();
1342
                expectedIAExceptionThrown = true;            
1343
            }
1344
            // we expect an IAE on getAttribute(name) if name does not exist
1345
            assertTrue(expectedIAExceptionThrown);
1241
            
1346
            
1242
            
1347
            
1243
1244
            /**
1348
            /**
1245
             *  Return the single-valued attribute of the managed type that
1349
             *  Return the single-valued attribute of the managed type that
1246
             *  corresponds to the specified name in the represented type.
1350
             *  corresponds to the specified name in the represented type.
Lines 1437-1443 Link Here
1437
             *           type has a single id attribute
1541
             *           type has a single id attribute
1438
             */
1542
             */
1439
            //public boolean hasSingleIdAttribute() {
1543
            //public boolean hasSingleIdAttribute() {
1544
            // verify false for "no" type of Id attribute
1545
            // test normal path
1546
            expectedIAExceptionThrown = false;
1547
            boolean hasSingleIdAttribute = false;
1548
            try {
1549
                EntityType<Manufacturer> aType = metamodel.entity(Manufacturer.class);
1550
                hasSingleIdAttribute = aType.hasSingleIdAttribute();
1551
            } catch (IllegalArgumentException iae) {
1552
                //iae.printStackTrace();
1553
                expectedIAExceptionThrown = true;            
1554
            }
1555
            assertFalse(expectedIAExceptionThrown);            
1556
            assertTrue(hasSingleIdAttribute);
1440
            
1557
            
1558
            
1559
            
1441
            /**
1560
            /**
1442
             *  Whether or not the identifiable type has a version attribute.
1561
             *  Whether or not the identifiable type has a version attribute.
1443
             *  @return boolean indicating whether or not the identifiable
1562
             *  @return boolean indicating whether or not the identifiable
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java (-26 / +40 lines)
Lines 31-36 Link Here
31
 *     08/08/2009-2.0  mobrien - 266912: implement Collection and List separation during attribute initialization
31
 *     08/08/2009-2.0  mobrien - 266912: implement Collection and List separation during attribute initialization
32
 *       - see design issue #58
32
 *       - see design issue #58
33
 *       http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List
33
 *       http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List
34
 *     08/17/2009-2.0  mobrien - 284877: The base case for the recursive function 
35
 *         managedTypeImpl.hasDeclaredAttribute() does not handle use case 1.4 (root-level managedType) 
36
 *         when the caller of the function does not do it's own inheritedType check. 
37
 *       - see design issue #52
38
 *         http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI:52_Refactor:_20090817
34
 ******************************************************************************/
39
 ******************************************************************************/
35
package org.eclipse.persistence.internal.jpa.metamodel;
40
package org.eclipse.persistence.internal.jpa.metamodel;
36
41
Lines 220-233 Link Here
220
        // get the attribute parameterized by <Owning type, return Type> - throw an IAE if not found (no need to check hierarchy)
225
        // get the attribute parameterized by <Owning type, return Type> - throw an IAE if not found (no need to check hierarchy)
221
        // Handles UC1 and UC2
226
        // Handles UC1 and UC2
222
        Attribute<X, ?> anAttribute = getAttribute(name);
227
        Attribute<X, ?> anAttribute = getAttribute(name);
223
        // Check the hierarchy for a declaration in the superclass(s) - keep moving up only when the attribute is not found
228
        // If an Attribute is found then check the hierarchy for a declaration in the superclass(s)
224
        ManagedTypeImpl aManagedSuperType = getManagedSuperType();
229
        // Keep moving up only when the attribute is not found
230
        ManagedTypeImpl aManagedSuperType = getManagedSuperType();        
225
        if(null == aManagedSuperType) {
231
        if(null == aManagedSuperType) {
226
            return anAttribute;
232
            return anAttribute;
227
        } else {
233
        } else {
228
            // keep checking the hierarchy but skip this level
234
            // keep checking the hierarchy but skip this level
229
            if(aManagedSuperType.hasDeclaredAttribute(name)) {
235
            if(aManagedSuperType.hasNoDeclaredAttributeInSuperType(name)) {
230
                // Handles UC4 and UC5 
236
                // Handles UC4 and UC5 - throw an IAE if the class is declared above
231
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
237
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
232
                        "metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass",
238
                        "metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass",
233
                        new Object[] { name, this }));
239
                        new Object[] { name, this }));
Lines 277-286 Link Here
277
        Set<Attribute<X, ?>> allAttributes = new HashSet<Attribute<X, ?>>(this.members.values());;
283
        Set<Attribute<X, ?>> allAttributes = new HashSet<Attribute<X, ?>>(this.members.values());;
278
        // Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException
284
        // Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException
279
        Set<Attribute<X, ?>> declaredAttributes = new HashSet<Attribute<X, ?>>();
285
        Set<Attribute<X, ?>> declaredAttributes = new HashSet<Attribute<X, ?>>();
280
        for(Iterator<Attribute<X, ?>> anIterator = allAttributes.iterator(); anIterator.hasNext();) {
286
        for(Attribute<X, ?> anAttribute : allAttributes) {
281
            Attribute<? super X, ?> anAttribute = anIterator.next();
282
            // Check the inheritance hierarchy for higher declarations
287
            // Check the inheritance hierarchy for higher declarations
283
            if(this.hasDeclaredAttribute(anAttribute.getName())) {
288
            if(this.hasNoDeclaredAttributeInSuperType(anAttribute.getName())) {
284
                declaredAttributes.add((Attribute<X, ?>)anAttribute);
289
                declaredAttributes.add((Attribute<X, ?>)anAttribute);
285
            }
290
            }
286
        }
291
        }
Lines 342-349 Link Here
342
        // Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException
347
        // Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException
343
        Set<PluralAttribute<X, ?, ?>> declaredAttributes = new HashSet<PluralAttribute<X, ?, ?>>();
348
        Set<PluralAttribute<X, ?, ?>> declaredAttributes = new HashSet<PluralAttribute<X, ?, ?>>();
344
        // The set is a copy of the underlying metamodel attribute set - we will remove all SingularAttribute(s)
349
        // The set is a copy of the underlying metamodel attribute set - we will remove all SingularAttribute(s)
345
        for(Iterator<PluralAttribute<? super X, ?, ?>> anIterator = pluralAttributes.iterator(); anIterator.hasNext();) {
350
        for(PluralAttribute<? super X, ?, ?>  anAttribute :pluralAttributes) {
346
            PluralAttribute<? super X, ?, ?> anAttribute = anIterator.next();
347
            if(((TypeImpl)anAttribute.getElementType()).isManagedType()) {
351
            if(((TypeImpl)anAttribute.getElementType()).isManagedType()) {
348
                // check for declarations in the hierarchy and don't add if declared above
352
                // check for declarations in the hierarchy and don't add if declared above
349
                //if(!((ManagedTypeImpl)anAttribute.getElementType()).hasDeclaredAttribute(anAttribute.getName())) {
353
                //if(!((ManagedTypeImpl)anAttribute.getElementType()).hasDeclaredAttribute(anAttribute.getName())) {
Lines 353-359 Link Here
353
                    declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute);
357
                    declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute);
354
                } else {
358
                } else {
355
                    // add only if we reach the root without finding another declaration
359
                    // add only if we reach the root without finding another declaration
356
                    if(!potentialSuperType.hasDeclaredAttribute(anAttribute.getName())) {
360
                    if(!potentialSuperType.hasNoDeclaredAttributeInSuperType(anAttribute.getName())) {
357
                        declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute);
361
                        declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute);
358
                    }
362
                    }
359
                }
363
                }
Lines 362-367 Link Here
362
        return declaredAttributes;
366
        return declaredAttributes;
363
    }
367
    }
364
368
369
    
365
    /**
370
    /**
366
     * INTERNAL:
371
     * INTERNAL:
367
     * Return an instance of a ManagedType based on the RelationalDescriptor parameter
372
     * Return an instance of a ManagedType based on the RelationalDescriptor parameter
Lines 372-388 Link Here
372
    public static ManagedTypeImpl<?> create(MetamodelImpl metamodel, RelationalDescriptor descriptor) {
377
    public static ManagedTypeImpl<?> create(MetamodelImpl metamodel, RelationalDescriptor descriptor) {
373
        // Get the ManagedType property on the descriptor if it exists
378
        // Get the ManagedType property on the descriptor if it exists
374
        ManagedTypeImpl<?> managedType = (ManagedTypeImpl<?>) descriptor.getProperty(ManagedTypeImpl.class.getName());
379
        ManagedTypeImpl<?> managedType = (ManagedTypeImpl<?>) descriptor.getProperty(ManagedTypeImpl.class.getName());
375
376
        // Create an Entity, Embeddable or MappedSuperclass
380
        // Create an Entity, Embeddable or MappedSuperclass
377
        if (null == managedType) {
381
        if (null == managedType) {
378
            // The descriptor can be one of NORMAL, INTERFACE (not supported), AGGREGATE or AGGREGATE_COLLECTION
382
            // The descriptor can be one of NORMAL, INTERFACE (not supported), AGGREGATE or AGGREGATE_COLLECTION
379
            // TODO: handle MappedSuperclass
380
            if (descriptor.isAggregateDescriptor()) {
383
            if (descriptor.isAggregateDescriptor()) {
384
                // EMBEDDABLE
381
                managedType = new EmbeddableTypeImpl(metamodel, descriptor);                
385
                managedType = new EmbeddableTypeImpl(metamodel, descriptor);                
382
            //} else if (descriptor.isAggregateCollectionDescriptor()) {
386
            //} else if (descriptor.isAggregateCollectionDescriptor()) {
383
            //    managedType = new EntityTypeImpl(metamodel, descriptor);
387
            //    managedType = new EntityTypeImpl(metamodel, descriptor);
384
            } else {
388
            } else {
385
                managedType = new EntityTypeImpl(metamodel, descriptor);
389
                // Determine if the descriptor is a mappedSuperclass
390
                // 20090817: comment out work for DI 39
391
/*                if(metamodel.hasMappedSuperclassDescriptorKeyedByClassName(descriptor.getJavaClassName())) {
392
                    // MAPPEDSUPERCLASS
393
                    // defer to subclass                    
394
                    managedType = MappedSuperclassTypeImpl.create(metamodel, descriptor);
395
                } else {*/
396
                    // ENTITY
397
                    managedType = new EntityTypeImpl(metamodel, descriptor);
398
//                }
386
            }
399
            }
387
        }
400
        }
388
401
Lines 852-862 Link Here
852
     */
865
     */
853
    public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
866
    public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
854
        // Iterate the members set for attributes of type SingularAttribute
867
        // Iterate the members set for attributes of type SingularAttribute
855
        //Set<SingularAttribute<? super X, ?>> singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>();
856
        Set singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>();
868
        Set singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>();
857
        for(Iterator<Attribute<X, ?>> anIterator = this.members.values().iterator(); anIterator.hasNext();) {
869
        for(Attribute<X, ?> anAttribute : this.members.values()) {            
858
            AttributeImpl<? super X, ?> anAttribute = (AttributeImpl<? super X, ?>)anIterator.next();
870
            if(!((AttributeImpl<? super X, ?>)anAttribute).isPlural()) {
859
            if(!anAttribute.isPlural()) {
860
                singularAttributeSet.add(anAttribute);
871
                singularAttributeSet.add(anAttribute);
861
            }
872
            }
862
        }
873
        }
Lines 874-881 Link Here
874
     *             false if no attribute is found in the superTree, or
885
     *             false if no attribute is found in the superTree, or
875
     *             false if the attribute is found declared higher up in the inheritance superTree
886
     *             false if the attribute is found declared higher up in the inheritance superTree
876
     */
887
     */
877
    private boolean hasDeclaredAttribute(String attributeName) {
888
    private boolean hasNoDeclaredAttributeInSuperType(String attributeName) {
878
        return hasDeclaredAttribute(attributeName, this.getMembers().get(attributeName));
889
        return hasNoDeclaredAttributeInSuperType(attributeName, this.getMembers().get(attributeName));
879
    }
890
    }
880
    
891
    
881
    /**
892
    /**
Lines 889-895 Link Here
889
     *             false if no attribute is found in the superTree, or
900
     *             false if no attribute is found in the superTree, or
890
     *             false if the attribute is found declared higher up in the inheritance superTree
901
     *             false if the attribute is found declared higher up in the inheritance superTree
891
     */
902
     */
892
    private boolean hasDeclaredAttribute(String attributeName, Attribute firstLevelAttribute) {
903
    private boolean hasNoDeclaredAttributeInSuperType(String attributeName, Attribute firstLevelAttribute) {
893
        /*
904
        /*
894
         * Issues: We need to take into account whether the superType is an Entity or MappedSuperclass
905
         * Issues: We need to take into account whether the superType is an Entity or MappedSuperclass
895
         * - If superType is entity then inheriting entities will not have copies of the inherited mappings
906
         * - If superType is entity then inheriting entities will not have copies of the inherited mappings
Lines 935-941 Link Here
935
                return true; 
946
                return true; 
936
            } else {
947
            } else {
937
                // UC 1.3 (part of the else condition (anAttribute != null)) is handled by the return false in null != aSuperTypeAttribute
948
                // UC 1.3 (part of the else condition (anAttribute != null)) is handled by the return false in null != aSuperTypeAttribute
938
                return false;
949
                // UC 1.4 (when caller is firstLevel) superType does not contain the attribute - check that the current attribute and the first differ
950
                if(null != anAttribute && anAttribute == firstLevelAttribute) {
951
                    return true;
952
                } else {
953
                    return false;
954
                }
939
            }
955
            }
940
        } else {            
956
        } else {            
941
           // Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType
957
           // Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType
Lines 946-955 Link Here
946
                   // return false immediately if a superType exists above the first level
962
                   // return false immediately if a superType exists above the first level
947
                   return false;
963
                   return false;
948
               } else {
964
               } else {
949
                   // UC1.4 The immediate mappedSuperclass may not have the attribute if another one up the chain of rmappedSuperclasses declares it
965
                   // UC1.4 (when caller is firstLevel.supertype) - the immediate mappedSuperclass may not have the attribute if another one up the chain of rmappedSuperclasses declares it
950
                   if(null == aSuperTypeAttribute) {
966
                   if(null == aSuperTypeAttribute) {
951
                       // UC 1.5: keep searching a possible chain of mappedSuperclasses
967
                       // UC 1.5: keep searching a possible chain of mappedSuperclasses
952
                       return aSuperType.hasDeclaredAttribute(attributeName, firstLevelAttribute);
968
                       return aSuperType.hasNoDeclaredAttributeInSuperType(attributeName, firstLevelAttribute);
953
                   } else {
969
                   } else {
954
                       // superType does not contain the attribute - check that the current attribute and the first differ
970
                       // superType does not contain the attribute - check that the current attribute and the first differ
955
                       if(anAttribute != firstLevelAttribute) {
971
                       if(anAttribute != firstLevelAttribute) {
Lines 1006-1015 Link Here
1006
         * We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass.
1022
         * We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass.
1007
         */
1023
         */
1008
        this.members = new HashMap<String, Attribute<X, ?>>();
1024
        this.members = new HashMap<String, Attribute<X, ?>>();
1009
1010
        // Get and process all mappings on the relationalDescriptor
1025
        // Get and process all mappings on the relationalDescriptor
1011
        for (Iterator<DatabaseMapping> i = getDescriptor().getMappings().iterator(); i.hasNext();) {
1026
        for (DatabaseMapping mapping : getDescriptor().getMappings()) {
1012
            DatabaseMapping mapping = (DatabaseMapping) i.next();
1013
            AttributeImpl<X, ?> member = null;
1027
            AttributeImpl<X, ?> member = null;
1014
1028
1015
            /**
1029
            /**

Return to bug 284877