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 266912 | Differences between
and this patch

Collapse All | Expand All

(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/ArrayProcessor.java (-14 lines)
Lines 15-39 Link Here
15
 ******************************************************************************/  
15
 ******************************************************************************/  
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
17
17
18
import javax.persistence.Column;
19
import javax.persistence.Entity;
18
import javax.persistence.Entity;
20
import javax.persistence.Table;
19
import javax.persistence.Table;
21
import javax.persistence.Version;
22
20
23
@Entity(name="ArrayProcessorMetamodel")
21
@Entity(name="ArrayProcessorMetamodel")
24
@Table(name="CMP3_MM_ARRAYPROC")
22
@Table(name="CMP3_MM_ARRAYPROC")
25
public class ArrayProcessor extends Processor implements java.io.Serializable{
23
public class ArrayProcessor extends Processor implements java.io.Serializable{
26
//    @Version
27
//    @Column(name="ARRAYPROC_VERSION")
28
//    private int version;
29
30
    public ArrayProcessor() {}
24
    public ArrayProcessor() {}
31
32
/*    public int getVersion() { 
33
        return version; 
34
    }
35
    
36
    protected void setVersion(int version) {
37
        this.version = version;
38
    }*/
39
}
25
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Board.java (-1 / +2 lines)
Lines 19-24 Link Here
19
import static javax.persistence.FetchType.EAGER;
19
import static javax.persistence.FetchType.EAGER;
20
import static javax.persistence.GenerationType.TABLE;
20
import static javax.persistence.GenerationType.TABLE;
21
21
22
import java.util.ArrayList;
22
import java.util.Collection;
23
import java.util.Collection;
23
import java.util.HashSet;
24
import java.util.HashSet;
24
25
Lines 55-61 Link Here
55
    
56
    
56
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
57
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
57
    @OneToMany(cascade=ALL, mappedBy="board")
58
    @OneToMany(cascade=ALL, mappedBy="board")
58
    private Collection<Processor> processors = new HashSet<Processor>();
59
    private Collection<Processor> processors = new ArrayList<Processor>();
59
60
60
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
61
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
61
    @OneToMany(cascade=ALL, mappedBy="board")
62
    @OneToMany(cascade=ALL, mappedBy="board")
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Computer.java (+2 lines)
Lines 78-83 Link Here
78
    // Inverse side 
78
    // Inverse side 
79
    @OneToMany(cascade=ALL, mappedBy="computer")
79
    @OneToMany(cascade=ALL, mappedBy="computer")
80
    // A Collection where the Collection type (Map, Set, List) is not defined at design time
80
    // A Collection where the Collection type (Map, Set, List) is not defined at design time
81
    // see design issue #58
82
    // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List
81
    private Collection<Board> circuitBoards;
83
    private Collection<Board> circuitBoards;
82
84
83
    public Computer() {}
85
    public Computer() {}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Corporation.java (+1 lines)
Lines 26-31 Link Here
26
public abstract class Corporation extends Person {
26
public abstract class Corporation extends Person {
27
27
28
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
28
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
29
    // Internally processed as a @ManyToMany because it is on a MappedSuperclass
29
    @OneToMany(cascade=ALL)//, mappedBy="corporation")
30
    @OneToMany(cascade=ALL)//, mappedBy="corporation")
30
    //@JoinColumn(name="CORP_COMPUTERS")
31
    //@JoinColumn(name="CORP_COMPUTERS")
31
    private Collection<Computer> corporateComputers = new HashSet<Computer>();
32
    private Collection<Computer> corporateComputers = new HashSet<Computer>();
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Designer.java (+1 lines)
Lines 34-39 Link Here
34
    // Verify special handling for PK for OneToMany (custom descriptor with fake PK name)
34
    // Verify special handling for PK for OneToMany (custom descriptor with fake PK name)
35
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
35
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
36
    // However, bidirectional relationships are not allowed to MappedSuperclasses - as they have no identity
36
    // However, bidirectional relationships are not allowed to MappedSuperclasses - as they have no identity
37
    // This @OneToMany implements internally as a @ManyToMany
37
    @OneToMany(fetch=EAGER, cascade=ALL)
38
    @OneToMany(fetch=EAGER, cascade=ALL)
38
    @JoinTable(name="CMP3_MM_HIST_EMPLOY", 
39
    @JoinTable(name="CMP3_MM_HIST_EMPLOY", 
39
                joinColumns = @JoinColumn(name="PERSON_ID"))   
40
                joinColumns = @JoinColumn(name="PERSON_ID"))   
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Manufacturer.java (-3 / +5 lines)
Lines 17-25 Link Here
17
17
18
import static javax.persistence.CascadeType.ALL;
18
import static javax.persistence.CascadeType.ALL;
19
19
20
import java.util.ArrayList;
20
import java.util.Collection;
21
import java.util.Collection;
21
import java.util.HashMap;
22
import java.util.HashMap;
22
import java.util.HashSet;
23
import java.util.HashSet;
24
import java.util.List;
23
import java.util.Map;
25
import java.util.Map;
24
import java.util.Set;
26
import java.util.Set;
25
27
Lines 42-48 Link Here
42
44
43
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
45
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
44
    @OneToMany(cascade=ALL, mappedBy="employer")
46
    @OneToMany(cascade=ALL, mappedBy="employer")
45
    private Collection<HardwareDesigner> hardwareDesigners = new HashSet<HardwareDesigner>();
47
    private List<HardwareDesigner> hardwareDesigners = new ArrayList<HardwareDesigner>();
46
    
48
    
47
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
49
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
48
    //@OneToMany(cascade=ALL, mappedBy="manufacturer")
50
    //@OneToMany(cascade=ALL, mappedBy="manufacturer")
Lines 81-91 Link Here
81
        aComputer.setManufacturer(null);
83
        aComputer.setManufacturer(null);
82
    }
84
    }
83
85
84
    public Collection<HardwareDesigner> getHardwareDesigners() {
86
    public List<HardwareDesigner> getHardwareDesigners() {
85
        return hardwareDesigners;
87
        return hardwareDesigners;
86
    }
88
    }
87
89
88
    public void setHardwareDesigners(Collection<HardwareDesigner> designers) {
90
    public void setHardwareDesigners(List<HardwareDesigner> designers) {
89
        this.hardwareDesigners = designers;
91
        this.hardwareDesigners = designers;
90
    }
92
    }
91
93
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/VectorProcessor.java (-15 lines)
Lines 15-40 Link Here
15
 ******************************************************************************/  
15
 ******************************************************************************/  
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
17
17
18
import javax.persistence.Column;
19
import javax.persistence.Entity;
18
import javax.persistence.Entity;
20
import javax.persistence.Table;
19
import javax.persistence.Table;
21
import javax.persistence.Version;
22
20
23
@Entity(name="VectorProcessorMetamodel")
21
@Entity(name="VectorProcessorMetamodel")
24
@Table(name="CMP3_MM_PROC")
22
@Table(name="CMP3_MM_PROC")
25
public class VectorProcessor extends Processor implements java.io.Serializable{
23
public class VectorProcessor extends Processor implements java.io.Serializable{
26
//    @Version
27
//    @Column(name="VECTPROC_VERSION")
28
//    private int version;
29
    
30
    public VectorProcessor() {}
24
    public VectorProcessor() {}
31
32
/*    public int getVersion() { 
33
        return version; 
34
    }
35
    
36
    protected void setVersion(int version) {
37
        this.version = version;
38
    }
39
*/
40
}
25
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-3 / +18 lines)
Lines 182-188 Link Here
182
        Collection<Memory> arrayMemories = new HashSet<Memory>();
182
        Collection<Memory> arrayMemories = new HashSet<Memory>();
183
        Collection<Processor> vectorProcessors = new HashSet<Processor>();
183
        Collection<Processor> vectorProcessors = new HashSet<Processor>();
184
        Collection<Processor> arrayProcessors = new HashSet<Processor>();
184
        Collection<Processor> arrayProcessors = new HashSet<Processor>();
185
        Collection<HardwareDesigner> hardwareDesigners = new HashSet<HardwareDesigner>();
185
        List<HardwareDesigner> hardwareDesigners = new ArrayList<HardwareDesigner>();
186
        Map<String, HardwareDesigner> mappedDesigners = new HashMap<String, HardwareDesigner>();
186
        Map<String, HardwareDesigner> mappedDesigners = new HashMap<String, HardwareDesigner>();
187
        Computer arrayComputer1 = null;
187
        Computer arrayComputer1 = null;
188
        Computer vectorComputer2 = null;
188
        Computer vectorComputer2 = null;
Lines 1118-1125 Link Here
1118
            try {
1118
            try {
1119
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1119
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1120
                // UC4 - the attribute is on the immediate superclass
1120
                // UC4 - the attribute is on the immediate superclass
1121
                ListAttribute<Manufacturer, Computer> anAttribute = 
1121
                CollectionAttribute<Manufacturer, Computer> anAttribute = 
1122
                    entityManufacturer.getDeclaredList("corporateComputers", entityComputer.getJavaType());
1122
                    entityManufacturer.getDeclaredCollection("corporateComputers", entityComputer.getJavaType());
1123
                //System.out.println("entityManufacturer.getDeclaredList(corporateComputers) " + anAttribute);
1123
                //System.out.println("entityManufacturer.getDeclaredList(corporateComputers) " + anAttribute);
1124
            } catch (IllegalArgumentException iae) {
1124
            } catch (IllegalArgumentException iae) {
1125
                // expecting
1125
                // expecting
Lines 1305-1310 Link Here
1305
             *          name is not declared in the managed type
1305
             *          name is not declared in the managed type
1306
             */
1306
             */
1307
            //CollectionAttribute<X, ?> getDeclaredCollection(String name); 
1307
            //CollectionAttribute<X, ?> getDeclaredCollection(String name); 
1308
            
1309
            expectedIAExceptionThrown = false;            
1310
            try {
1311
                //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
1312
                // UC4 - the attribute is on the immediate superclass
1313
                CollectionAttribute<Manufacturer, Computer> anAttribute = 
1314
                    entityManufacturer.getDeclaredCollection("corporateComputers", entityComputer.getJavaType());
1315
                //System.out.println("entityManufacturer.getDeclaredList(corporateComputers) " + anAttribute);
1316
            } catch (IllegalArgumentException iae) {
1317
                // expecting
1318
                // 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.
1319
                //iae.printStackTrace();
1320
                expectedIAExceptionThrown = true;            
1321
            }
1322
            assertTrue(expectedIAExceptionThrown);
1308
1323
1309
            /**
1324
            /**
1310
             *  Return the Set-valued attribute declared by the managed type 
1325
             *  Return the Set-valued attribute declared by the managed type 
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java (-13 / +104 lines)
Lines 28-39 Link Here
28
 *     07/28/2009-2.0  mobrien - 284877: implement recursive functionality for hasDeclaredAttribute()
28
 *     07/28/2009-2.0  mobrien - 284877: implement recursive functionality for hasDeclaredAttribute()
29
 *       - see design issue #52
29
 *       - see design issue #52
30
 *         http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_52:_20090728:_JPA_2:_Implement_recursive_ManagedType.getDeclared.2A_algorithm_to_differentiate_by_IdentifiableType
30
 *         http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_52:_20090728:_JPA_2:_Implement_recursive_ManagedType.getDeclared.2A_algorithm_to_differentiate_by_IdentifiableType
31
 *     08/08/2009-2.0  mobrien - 266912: implement Collection and List separation during attribute initialization
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
31
 ******************************************************************************/
34
 ******************************************************************************/
32
package org.eclipse.persistence.internal.jpa.metamodel;
35
package org.eclipse.persistence.internal.jpa.metamodel;
33
36
37
import java.lang.reflect.Field;
38
import java.lang.reflect.Method;
39
import java.util.Collection;
34
import java.util.HashMap;
40
import java.util.HashMap;
35
import java.util.HashSet;
41
import java.util.HashSet;
36
import java.util.Iterator;
42
import java.util.Iterator;
43
import java.util.List;
37
import java.util.Map;
44
import java.util.Map;
38
import java.util.Set;
45
import java.util.Set;
39
46
Lines 49-56 Link Here
49
56
50
import org.eclipse.persistence.descriptors.RelationalDescriptor;
57
import org.eclipse.persistence.descriptors.RelationalDescriptor;
51
import org.eclipse.persistence.indirection.IndirectSet;
58
import org.eclipse.persistence.indirection.IndirectSet;
59
import org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor;
60
import org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor;
52
import org.eclipse.persistence.internal.helper.ClassConstants;
61
import org.eclipse.persistence.internal.helper.ClassConstants;
53
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
62
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
63
import org.eclipse.persistence.internal.queries.ContainerPolicy;
54
import org.eclipse.persistence.mappings.CollectionMapping;
64
import org.eclipse.persistence.mappings.CollectionMapping;
55
import org.eclipse.persistence.mappings.DatabaseMapping;
65
import org.eclipse.persistence.mappings.DatabaseMapping;
56
66
Lines 959-977 Link Here
959
    
969
    
960
    /**
970
    /**
961
     * INTERNAL:
971
     * INTERNAL:
962
     * Initialize the members of this ManagedType based on the mappings defined on the descriptor.
972
     * Initialise the members of this ManagedType based on the mappings defined on the descriptor.
963
     * We process the appropriate Map, List, Set, Collection or Object/primitive types.<p>
973
     * We process the appropriate Map, List, Set, Collection or Object/primitive types.<p>
964
     * Initialization should occur after all types in the metamodel have been created already.
974
     * Initialisation should occur after all types in the metamodel have been created already.
965
     * 
975
     * 
966
     */
976
     */
967
    protected void initialize() { // TODO: Check all is*Policy() calls
977
    protected void initialize() { // TODO: Check all is*Policy() calls
968
        /*
978
        /*
969
         * Design Issue 37:
979
         * Design Issue 37 and 58:
970
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_37:_20090708:_CollectionAttribute_acts_as_a_peer_of_Map.2C_Set.2C_List_but_should_be_a_super_interface 
980
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_37:_20090708:_CollectionAttribute_acts_as_a_peer_of_Map.2C_Set.2C_List_but_should_be_a_super_interface
981
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List 
982
         * 
971
         *     The hierarchy of the Metamodel API has Collection alongside List, Set and Map.
983
         *     The hierarchy of the Metamodel API has Collection alongside List, Set and Map.
972
         * However, in a normal Java collections framework Collection is an 
984
         * However, in a normal Java collections framework Collection is an 
973
         * abstract superclass of List, Set and Map (with Map not really a Collection).
985
         * abstract superclass of List, Set and Map (with Map not really a Collection).
974
         * We therefore need to treat Collection here as a peer of the other "collections".
986
         * We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass.
975
         */
987
         */
976
        this.members = new HashMap<String, Attribute<X, ?>>();
988
        this.members = new HashMap<String, Attribute<X, ?>>();
977
989
Lines 984-1004 Link Here
984
            if (mapping.isCollectionMapping()) {
996
            if (mapping.isCollectionMapping()) {
985
                // Handle 1:m, n:m collection mappings
997
                // Handle 1:m, n:m collection mappings
986
                CollectionMapping colMapping = (CollectionMapping) mapping;
998
                CollectionMapping colMapping = (CollectionMapping) mapping;
987
                if (colMapping.getContainerPolicy().isMapPolicy()) {
999
                ContainerPolicy collectionContainerPolicy = colMapping.getContainerPolicy();
1000
                if (collectionContainerPolicy.isMapPolicy()) {
988
                    // Handle Map type mappings
1001
                    // Handle Map type mappings
989
                    member = new MapAttributeImpl(this, colMapping, true);
1002
                    member = new MapAttributeImpl(this, colMapping, true);
990
                    // check mapping.attributeAcessor.attributeField.type=Collection
1003
                    // check mapping.attributeAcessor.attributeField.type=Collection
991
                } else if (colMapping.getContainerPolicy().isListPolicy()) { // TODO: isListPolicy() will return true for IndirectList (a lazy Collection)                    
1004
                } else if (collectionContainerPolicy.isListPolicy()) { 
992
                    // Handle List type mappings
1005
                    /**
993
                    member = new ListAttributeImpl(this, colMapping, true);
1006
                     * Handle lazy Collections and Lists and the fact that both return an IndirectList policy.
1007
                     * We check the type on the attributeField of the attributeAccessor on the mapping
1008
                     */
1009
                    Class aType = null;
1010
                    if(colMapping.getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) {
1011
                        Field aField = ((InstanceVariableAttributeAccessor)colMapping.getAttributeAccessor()).getAttributeField();                        
1012
                        // MappedSuperclasses need special handling to get their type from an inheriting subclass
1013
                        if(null == aField) { // MappedSuperclass field will not be set
1014
                            if(this.isMappedSuperclass()) {
1015
                                // get inheriting subtype member (without handling @override annotations)
1016
                                MappedSuperclassTypeImpl aMappedSuperclass = ((MappedSuperclassTypeImpl)this);
1017
                                AttributeImpl inheritingTypeMember = aMappedSuperclass.getMemberFromInheritingType(colMapping.getAttributeName());
1018
                                aField = ((InstanceVariableAttributeAccessor)inheritingTypeMember.getMapping().getAttributeAccessor()).getAttributeField();
1019
                                if(null == aField) {
1020
                                    aType = Collection.class;
1021
                                } else {
1022
                                    aType = aField.getType();
1023
                                }
1024
                            } else {
1025
                                aType = List.class;
1026
                            }                        
1027
                        } else {
1028
                            aType = aField.getType();
1029
                        }
1030
                        // This attribute is declared as List 
1031
                        if(aType == List.class) {                    
1032
                            member = new ListAttributeImpl(this, colMapping, true);
1033
                        } else {
1034
                            if(aType == Collection.class) {
1035
                                // This attribute is therefore declared as Collection
1036
                                member = new CollectionAttributeImpl(this, colMapping, true);
1037
                            } else {
1038
                                // TODO: System.out.println("_Warning: type is null on " + colMapping);
1039
                                member = new CollectionAttributeImpl(this, colMapping, true);
1040
                            }
1041
                        }
1042
                    } else {
1043
                        // handle variations of missing get/set methods - only for Collection vs List
1044
                        if(colMapping.getAttributeAccessor() instanceof MethodAttributeAccessor) {
1045
                            aType = ((MethodAttributeAccessor)colMapping.getAttributeAccessor()).getAttributeClass();
1046
                            if(aType == Collection.class) {
1047
                                member = new CollectionAttributeImpl(this, colMapping, true);
1048
                            } else if(aType == List.class) {
1049
                                member = new ListAttributeImpl(this, colMapping, true);
1050
                            } else {
1051
                                // Type may be null when no getMethod exists for the class such as an embeddable
1052
                                // Here we check the returnType on the declared method on the class directly                                
1053
                                String getMethodName = ((MethodAttributeAccessor)colMapping.getAttributeAccessor()).getGetMethodName();
1054
                                if(null == getMethodName) {
1055
                                    // default to List
1056
                                    member = new ListAttributeImpl(this, colMapping, true);
1057
                                } else {
1058
                                    try {
1059
                                        Method aMethod = this.getJavaType().getDeclaredMethod(getMethodName);
1060
                                        aType = aMethod.getReturnType();
1061
                                        if(aType == Collection.class) {
1062
                                            member = new CollectionAttributeImpl(this, colMapping, true);
1063
                                        } else if(aType == List.class) {
1064
                                            member = new ListAttributeImpl(this, colMapping, true);
1065
                                        } else {
1066
                                            // default to List
1067
                                            // TODO: System.out.println("_Warning: type is null on " + colMapping);                                            
1068
                                            member = new ListAttributeImpl(this, colMapping, true);
1069
                                        }
1070
                                    } catch (Exception e) {
1071
                                        // TODO: System.out.println("_Warning: type is null on " + colMapping);
1072
                                        // default to List
1073
                                        member = new ListAttributeImpl(this, colMapping, true);
1074
                                    }
1075
                                }
1076
                            }
1077
                        }
1078
                    }
994
                } else {
1079
                } else {
995
                    // Handle Set type mappings (IndirectSet.isAssignableFrom(Set.class) == false)
1080
                    // Handle Set type mappings (IndirectSet.isAssignableFrom(Set.class) == false)
996
                    if (colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(Set.class) ||
1081
                    if (collectionContainerPolicy.getContainerClass().isAssignableFrom(Set.class) ||
997
                            colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(IndirectSet.class)) {
1082
                            collectionContainerPolicy.getContainerClass().isAssignableFrom(IndirectSet.class)) {
998
                        member = new SetAttributeImpl(this, colMapping, true);
1083
                        member = new SetAttributeImpl(this, colMapping, true);
999
                    } else {
1084
                    } else {
1000
                        // Handle Collection type mappings as a default
1085
                        // Check for non-lazy Collection policy
1001
                        member = new CollectionAttributeImpl(this, colMapping, true);
1086
                        if(collectionContainerPolicy.isCollectionPolicy()) {
1087
                            member = new CollectionAttributeImpl(this, colMapping, true);
1088
                        } else {
1089
                            // Handle Collection type mappings as a default
1090
                            // TODO: System.out.println("_Warning: defaulting to non-Set specific Collection type on " + colMapping);
1091
                            member = new CollectionAttributeImpl(this, colMapping, true);
1092
                        }
1002
                    }
1093
                    }
1003
                }
1094
                }
1004
            } else {
1095
            } else {
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java (+40 lines)
Lines 20-25 Link Here
20
 ******************************************************************************/
20
 ******************************************************************************/
21
package org.eclipse.persistence.internal.jpa.metamodel;
21
package org.eclipse.persistence.internal.jpa.metamodel;
22
22
23
import java.util.HashMap;
24
import java.util.Iterator;
25
import java.util.Map;
26
23
import javax.persistence.metamodel.MappedSuperclassType;
27
import javax.persistence.metamodel.MappedSuperclassType;
24
28
25
import org.eclipse.persistence.descriptors.RelationalDescriptor;
29
import org.eclipse.persistence.descriptors.RelationalDescriptor;
Lines 41-59 Link Here
41
 */ 
45
 */ 
42
public class MappedSuperclassTypeImpl<X> extends IdentifiableTypeImpl<X> implements MappedSuperclassType<X> {
46
public class MappedSuperclassTypeImpl<X> extends IdentifiableTypeImpl<X> implements MappedSuperclassType<X> {
43
    
47
    
48
    /** The map of types that inherit from this mappedSuperclass */
49
    protected Map<Class, IdentifiableTypeImpl> inheritingTypes;
50
    
44
    protected MappedSuperclassTypeImpl(Class<?> object, MetamodelImpl metamodel, RelationalDescriptor relationalDescriptor) {
51
    protected MappedSuperclassTypeImpl(Class<?> object, MetamodelImpl metamodel, RelationalDescriptor relationalDescriptor) {
45
        this(metamodel, relationalDescriptor);
52
        this(metamodel, relationalDescriptor);
46
    }
53
    }
47
54
48
    protected MappedSuperclassTypeImpl(MetamodelImpl metamodel, RelationalDescriptor relationalDescriptor) {        
55
    protected MappedSuperclassTypeImpl(MetamodelImpl metamodel, RelationalDescriptor relationalDescriptor) {        
49
        super(metamodel, relationalDescriptor);
56
        super(metamodel, relationalDescriptor);
57
        inheritingTypes = new HashMap<Class, IdentifiableTypeImpl>();
50
        // The supertype field will remain uninstantiated until MetamodelImpl.initialize() is complete
58
        // The supertype field will remain uninstantiated until MetamodelImpl.initialize() is complete
51
    }
59
    }
52
    
60
    
61
    /**
62
     * INTERNAL:
63
     * Add an inheriting subclass to the map of types that inherit from this mappedSuperclass.
64
     * @param identifiableType
65
     */
66
    protected void addInheritingType(IdentifiableTypeImpl identifiableType) {
67
        if(null == inheritingTypes) {
68
            inheritingTypes = new HashMap<Class, IdentifiableTypeImpl>();
69
        }
70
        inheritingTypes.put(identifiableType.getJavaType(), identifiableType);
71
    }
72
    
53
    public static MappedSuperclassTypeImpl<?> create(MetamodelImpl metamodel, Class object, RelationalDescriptor relationalDescriptor) {
73
    public static MappedSuperclassTypeImpl<?> create(MetamodelImpl metamodel, Class object, RelationalDescriptor relationalDescriptor) {
54
        MappedSuperclassTypeImpl<?> mappedSuperclassTypeImpl = new MappedSuperclassTypeImpl(object, metamodel, relationalDescriptor);
74
        MappedSuperclassTypeImpl<?> mappedSuperclassTypeImpl = new MappedSuperclassTypeImpl(object, metamodel, relationalDescriptor);
55
        return mappedSuperclassTypeImpl;
75
        return mappedSuperclassTypeImpl;
56
    }
76
    }
77
78
    /**
79
     * INTERNAL:
80
     *    MappedSuperclasses need special handling to get their type from an inheriting subclass.
81
     *    This function determines the type for an attribute by returning the same inherited attribute from a subclass
82
     * @param name
83
     * @return
84
     */
85
    public AttributeImpl getMemberFromInheritingType(String name) {
86
        AttributeImpl inheritedAttribute = null;
87
        // search the inheriting types map for an attribute matching the attribute name
88
        for(Iterator<IdentifiableTypeImpl> anIterator = inheritingTypes.values().iterator(); anIterator.hasNext();) {
89
            IdentifiableTypeImpl inheritingType = anIterator.next();
90
            if(inheritingType.members.containsKey(name)) {
91
                return (AttributeImpl)inheritingType.getAttribute(name);
92
            }
93
        }
94
        // we will return a null attribute in the case that a MappedSuperclass has no implementing entities
95
        return inheritedAttribute;
96
    }    
57
    
97
    
58
    /**
98
    /**
59
     *  Return the persistence type.
99
     *  Return the persistence type.
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (-12 / +26 lines)
Lines 275-291 Link Here
275
            this.types.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
275
            this.types.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
276
        }
276
        }
277
277
278
        /**
279
         * Delayed-Initialization (process all mappings) of all Managed types
280
         *  (This includes all IdentifiableTypes = Entity and MappedSuperclass types).
281
         * To avoid a ConcurrentModificationException on the types map, iterate a list instead of the Map values directly.
282
         * The following code section may add BasicTypes to the types map.
283
         */
284
        List<ManagedTypeImpl<?>> aManagedTypeList = new ArrayList<ManagedTypeImpl<?>>(this.managedTypes.values());
285
        for(Iterator<ManagedTypeImpl<?>> managedTypeImplIterator = aManagedTypeList.iterator(); managedTypeImplIterator.hasNext();) {
286
            ManagedTypeImpl<?> aType = managedTypeImplIterator.next();
287
            aType.initialize();
288
        }
289
        
278
        
290
        // Handle all IdentifiableTypes (after all ManagedTypes have been created)
279
        // Handle all IdentifiableTypes (after all ManagedTypes have been created)
291
        // Assign all superType fields on all IdentifiableTypes (only after all managedType objects have been created)
280
        // Assign all superType fields on all IdentifiableTypes (only after all managedType objects have been created)
Lines 301-309 Link Here
301
                // If there is no superclass (besides Object for a top level identifiable type) then keep the supertype set to null
290
                // If there is no superclass (besides Object for a top level identifiable type) then keep the supertype set to null
302
                // See design issue #42 - we return Object for top-level types (with no superclass) and null if the supertype was not set
291
                // See design issue #42 - we return Object for top-level types (with no superclass) and null if the supertype was not set
303
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_42:_20090709:_IdentifiableType.supertype_-_what_do_top-level_types_set_it_to
292
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_42:_20090709:_IdentifiableType.supertype_-_what_do_top-level_types_set_it_to
304
                ((IdentifiableTypeImpl)potentialIdentifiableType).setSupertype(identifiableTypeSuperclass);                    
293
                ((IdentifiableTypeImpl)potentialIdentifiableType).setSupertype(identifiableTypeSuperclass);
294
                // set back pointer if mappedSuperclass
295
                if(null != identifiableTypeSuperclass && ((IdentifiableTypeImpl)identifiableTypeSuperclass).isMappedSuperclass()) {
296
                    ((MappedSuperclassTypeImpl)identifiableTypeSuperclass).addInheritingType(((IdentifiableTypeImpl)potentialIdentifiableType));
297
                }
305
            }
298
            }
306
        }        
299
        }        
300
        
301
        //1 - process all non-mappedSuperclass types first so we pick up attribute types
302
        //2 - process mappedSuperclass types and lookup collection attribute types on inheriting entity types when field is not set
303
        
304
        /**
305
         * Delayed-Initialization (process all mappings) of all Managed types
306
         *  (This includes all IdentifiableTypes = Entity and MappedSuperclass types).
307
         * To avoid a ConcurrentModificationException on the types map, iterate a list instead of the Map values directly.
308
         * The following code section may add BasicTypes to the types map.
309
         */
310
        for(Iterator<EntityTypeImpl<?>> managedTypeImplIterator = (new ArrayList<EntityTypeImpl<?>>(entities.values())).iterator(); managedTypeImplIterator.hasNext();) {
311
            managedTypeImplIterator.next().initialize();
312
        }
313
        for(Iterator<EmbeddableTypeImpl<?>> managedTypeImplIterator = (new ArrayList<EmbeddableTypeImpl<?>>(embeddables.values())).iterator(); managedTypeImplIterator.hasNext();) {
314
            managedTypeImplIterator.next().initialize();
315
        }
316
        for(Iterator<MappedSuperclassTypeImpl<?>> managedTypeImplIterator = (new ArrayList<MappedSuperclassTypeImpl<?>>(mappedSuperclasses)).iterator(); managedTypeImplIterator.hasNext();) {
317
            managedTypeImplIterator.next().initialize();
318
        }
319
320
    
307
    }
321
    }
308
322
309
    /**
323
    /**

Return to bug 266912