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

(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/descriptors/RelationalDescriptor.java (-31 lines)
Lines 10-19 Link Here
10
 * Contributors:
10
 * Contributors:
11
 *     Oracle - initial API and implementation from Oracle TopLink
11
 *     Oracle - initial API and implementation from Oracle TopLink
12
 *     
12
 *     
13
 *     04/30/2009-2.0 Michael O'Brien 
14
 *       - 266912: JPA 2.0 Metamodel API (part of Criteria API)
15
 *         override equals and hashcode for use in a Set. 
16
 *
17
 ******************************************************************************/  
13
 ******************************************************************************/  
18
package org.eclipse.persistence.descriptors;
14
package org.eclipse.persistence.descriptors;
19
15
Lines 123-153 Link Here
123
        super.setTableQualifier(tableQualifier);
119
        super.setTableQualifier(tableQualifier);
124
    }
120
    }
125
    
121
    
126
    // 266912: This class is used in a Set - we therefore need to override equals() and hashCode() so we can maintain no-duplicates functionality
127
    // See Item 8 p.37 of Effective Java - J.Bloch 
128
    public boolean equals(Object o) {
129
        // we defer to the superclass except during inequality
130
        boolean equal = super.equals(o);        
131
        if(equal) {
132
            return true;
133
        }
134
        if(o == this) {
135
            return true;
136
        }
137
        if(!(o instanceof RelationalDescriptor)) {
138
            return false;
139
        }
140
        RelationalDescriptor descriptor = (RelationalDescriptor) o;
141
        // TODO: for now if the implementing className is the same then we have equality
142
        // TODO: we need a strategy to check classes that are different classLoaders but with the same name
143
        return descriptor.getJavaClassName().equals(getJavaClassName());
144
    }
145
146
    public int hashCode() {
147
        int result = 17;
148
        result = 37 * result + this.getJavaClassName().hashCode();
149
        return result;
150
    }
151
    
152
    
153
}
122
}
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/sessions/Project.java (-28 / +30 lines)
Lines 14-19 Link Here
14
 *       - 266912: JPA 2.0 Metamodel API (part of Criteria API)
14
 *       - 266912: JPA 2.0 Metamodel API (part of Criteria API)
15
 *         Add Set<RelationalDescriptor> mappedSuperclassDescriptors 
15
 *         Add Set<RelationalDescriptor> mappedSuperclassDescriptors 
16
 *         to support the Metamodel API 
16
 *         to support the Metamodel API 
17
 *     06/17/2009-2.0 Michael O'Brien 
18
 *       - 266912: change mappedSuperclassDescriptors Set to a Map
19
 *          keyed on MetadataClass - avoiding the use of a hashCode/equals
20
 *          override on RelationalDescriptor, but requiring a contains check prior to a put
17
 *     
21
 *     
18
 ******************************************************************************/  
22
 ******************************************************************************/  
19
package org.eclipse.persistence.sessions;
23
package org.eclipse.persistence.sessions;
Lines 89-97 Link Here
89
    protected transient List<DatabaseQuery> queries = null;
93
    protected transient List<DatabaseQuery> queries = null;
90
    
94
    
91
    /**
95
    /**
92
     * Mapped Superclasses (JPA 2) collection of parent non-relational descriptors
96
     * Mapped Superclasses (JPA 2) collection of parent non-relational descriptors keyed on MetadataClass
97
     * without creating a compile time dependency onJPA
93
     */
98
     */
94
    protected Set<RelationalDescriptor> mappedSuperclassDescriptors;
99
    protected Map<Object, RelationalDescriptor> mappedSuperclassDescriptors;
95
    
100
    
96
    /**
101
    /**
97
     * PUBLIC:
102
     * PUBLIC:
Lines 107-113 Link Here
107
        this.hasProxyIndirection = false;
112
        this.hasProxyIndirection = false;
108
        this.jpqlParseCache = new ConcurrentFixedCache(200);
113
        this.jpqlParseCache = new ConcurrentFixedCache(200);
109
        this.queries = new ArrayList<DatabaseQuery>();
114
        this.queries = new ArrayList<DatabaseQuery>();
110
        this.mappedSuperclassDescriptors = new HashSet<RelationalDescriptor>(2);
115
        this.mappedSuperclassDescriptors = new HashMap<Object, RelationalDescriptor>(2);
111
    }
116
    }
112
117
113
    /**
118
    /**
Lines 968-1021 Link Here
968
    
973
    
969
    /**
974
    /**
970
     * INTERNAL:
975
     * INTERNAL:
971
     * 266912: Add a descriptor to the Set of mappedSuperclass descriptors
976
     * 266912: Add a descriptor to the Map of mappedSuperclass descriptors
977
     * @param key (Metadata class) 
972
     * @param value (RelationalDescriptor)
978
     * @param value (RelationalDescriptor)
973
     */
979
     */
974
    public void addMappedSuperclass(RelationalDescriptor value) {
980
    public void addMappedSuperclass(Object key, RelationalDescriptor value) {
975
        // Lazy initialization of the mappedSuperclassDescriptors field.
981
        // Lazy initialization of the mappedSuperclassDescriptors field.
976
        if(null == this.mappedSuperclassDescriptors) {
982
        if(null == this.mappedSuperclassDescriptors) {
977
            this.mappedSuperclassDescriptors = new HashSet<RelationalDescriptor>(2);
983
            this.mappedSuperclassDescriptors = new HashMap<Object, RelationalDescriptor>(2);
978
        }
984
        }
979
        // duplicates are avoided with use of a Set and overriding equals()/hashCode()
985
        // Avoid replacing the current RelationalDescriptor that may have mappings set
980
        this.mappedSuperclassDescriptors.add(value);
986
        if(!this.mappedSuperclassDescriptors.containsKey(key)) {
987
            this.mappedSuperclassDescriptors.put(key, value);
988
        }
981
    }
989
    }
982
990
983
    /**
991
    /**
984
     * INTERNAL:
992
     * INTERNAL:
985
     * Use the javaClassName from the Class key parameter to lookup the 
993
     * Use the Metadata key parameter to lookup the 
986
     * Descriptor from the Set of mappedSuperclass descriptors
994
     * Descriptor from the Map of mappedSuperclass descriptors
987
     * @param key - the String name of the metadata class
995
     * @param key - theMetadata class
988
     * @return
996
     * @return
989
     */
997
     */
990
    public RelationalDescriptor getMappedSuperclass(String key) {
998
    public RelationalDescriptor getMappedSuperclass(Object key) {
991
        // TODO: this implementation may have side effects when we have the same class in different class loaders. 
999
        // TODO: this implementation may have side effects when we have the same class 
992
        RelationalDescriptor descriptor = null;
1000
        // in different class loaders - however currently there is only one classLoader per project
993
        // Lazy initialization of the mappedSuperclassDescriptors field.
1001
        // Lazy initialization of the mappedSuperclassDescriptors field.
994
        if(null == this.mappedSuperclassDescriptors) {
1002
        if(null == this.mappedSuperclassDescriptors) {
995
            this.mappedSuperclassDescriptors = new HashSet<RelationalDescriptor>(2);
1003
            this.mappedSuperclassDescriptors = new HashMap<Object, RelationalDescriptor>(2);
1004
            return null;
996
        }
1005
        }
997
        // iterate the set of mappedSuperclasses and return the value that has a matching javaClass key
1006
        // iterate the set of mappedSuperclasses and return the value that has a matching javaClass key
998
        for(Iterator<RelationalDescriptor> anIterator = 
1007
        return this.mappedSuperclassDescriptors.get(key);
999
            this.mappedSuperclassDescriptors.iterator(); anIterator.hasNext();) {
1000
            descriptor = anIterator.next();
1001
            // return descriptor that matches the name set in  EntityAccessor
1002
            if(descriptor.getJavaClassName().equals(key)) {
1003
                return descriptor;
1004
            }
1005
        }
1006
        return null;
1007
    }
1008
    }
1008
1009
1009
1010
1010
    /**
1011
    /**
1011
     * INTERNAL:
1012
     * INTERNAL:
1012
     * Return the Set of RelationalDescriptor objects representing mapped superclass parents
1013
     * Return the Map of RelationalDescriptor objects representing mapped superclass parents
1013
     * @return Set
1014
     * keyed by className of the metadata class
1015
     * @return Map
1014
     */
1016
     */
1015
    public Set<RelationalDescriptor> getMappedSuperclassDescriptors() {        
1017
    public Map<Object, RelationalDescriptor> getMappedSuperclassDescriptors() {        
1016
        // Lazy initialization of the mappedSuperclassDescriptors field.
1018
        // Lazy initialization of the mappedSuperclassDescriptors field.
1017
        if(null == this.mappedSuperclassDescriptors) {
1019
        if(null == this.mappedSuperclassDescriptors) {
1018
            this.mappedSuperclassDescriptors = new HashSet<RelationalDescriptor>(2);
1020
            this.mappedSuperclassDescriptors = new HashMap<Object, RelationalDescriptor>(2);
1019
        }
1021
        }
1020
        return this.mappedSuperclassDescriptors;
1022
        return this.mappedSuperclassDescriptors;
1021
    }
1023
    }
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-3 / +3 lines)
Lines 232-242 Link Here
232
            // The managedType is the owner of the attribute
232
            // The managedType is the owner of the attribute
233
            //hardwareDesigners=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[hardwareDesigners]], 
233
            //hardwareDesigners=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[hardwareDesigners]], 
234
            //computers=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[computers]], 
234
            //computers=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[computers]], 
235
            javax.persistence.metamodel.CollectionAttribute<? super Manufacturer, Computer> computersAttribute = 
235
            //javax.persistence.metamodel.CollectionAttribute<? super Manufacturer, Computer> computersAttribute = 
236
                entityManufacturer.getCollection("computers", Computer.class);
236
            //    entityManufacturer.getCollection("computers", Computer.class);
237
            //javax.persistence.metamodel.Set<Manufacturer, Computer> computersAttribute2 = 
237
            //javax.persistence.metamodel.Set<Manufacturer, Computer> computersAttribute2 = 
238
            //    entityManufacturer.getSet("computers", Computer.class);
238
            //    entityManufacturer.getSet("computers", Computer.class);
239
            System.out.println("_Manufacturer.computers: " + computersAttribute);
239
            //System.out.println("_Manufacturer.computers: " + computersAttribute);
240
            
240
            
241
            //version=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[version-->CMP3_MM_MANUF.MANUF_VERSION]], 
241
            //version=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[version-->CMP3_MM_MANUF.MANUF_VERSION]], 
242
            //name=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[name-->CMP3_MM_MANUF.NAME]], 
242
            //name=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[name-->CMP3_MM_MANUF.NAME]], 
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataProject.java (-3 / +7 lines)
Lines 27-32 Link Here
27
 *       - 266912: JPA 2.0 Metamodel API (part of Criteria API)
27
 *       - 266912: JPA 2.0 Metamodel API (part of Criteria API)
28
 *     06/16/2009-2.0 Guy Pelletier 
28
 *     06/16/2009-2.0 Guy Pelletier 
29
 *       - 277039: JPA 2.0 Cache Usage Settings
29
 *       - 277039: JPA 2.0 Cache Usage Settings
30
 *     06/17/2009-2.0 Michael O'Brien 
31
 *       - 266912: change mappedSuperclassDescriptors Set to a Map
32
 *          keyed on MetadataClass - avoiding the use of a hashCode/equals
33
 *          override on RelationalDescriptor, but requiring a contains check prior to a put
30
 ******************************************************************************/  
34
 ******************************************************************************/  
31
package org.eclipse.persistence.internal.jpa.metadata;
35
package org.eclipse.persistence.internal.jpa.metadata;
32
36
Lines 1220-1227 Link Here
1220
        // when the descriptor is part of a set
1224
        // when the descriptor is part of a set
1221
        // The javaClass itself will be set on the descriptor later when we have the correct classLoader
1225
        // The javaClass itself will be set on the descriptor later when we have the correct classLoader
1222
        msDescriptor.setJavaClassName(metadataClass.getName());
1226
        msDescriptor.setJavaClassName(metadataClass.getName());
1223
        // Add the mapped superclass to the native project
1227
        // Add the mapped superclass to the native project keyed by MetadataClass
1224
        m_session.getProject().addMappedSuperclass(msDescriptor);
1228
        m_session.getProject().addMappedSuperclass(metadataClass, msDescriptor);
1225
    }    
1229
    }    
1226
1230
1227
    /**
1231
    /**
Lines 1236-1242 Link Here
1236
        // we only handle classes, return null for Methods, Fields and URLs 
1240
        // we only handle classes, return null for Methods, Fields and URLs 
1237
        if(null != metadataClass && metadataClass instanceof MetadataClass) {
1241
        if(null != metadataClass && metadataClass instanceof MetadataClass) {
1238
            relationalDescriptor = m_session.getProject()
1242
            relationalDescriptor = m_session.getProject()
1239
                .getMappedSuperclass(((MetadataClass)metadataClass).getName());
1243
                .getMappedSuperclass(((MetadataClass)metadataClass));
1240
        }
1244
        }
1241
        return relationalDescriptor;
1245
        return relationalDescriptor;
1242
    }    
1246
    }    
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/EntityTypeImpl.java (-2 / +2 lines)
Lines 179-188 Link Here
179
                        return (CollectionAttribute<X,E>) member; 
179
                        return (CollectionAttribute<X,E>) member; 
180
                    }
180
                    }
181
                } else {
181
                } else {
182
                    throw new IllegalArgumentException("The attributed named [" + name + "] is not of the java type [" + elementType + "].");                    
182
                    throw new IllegalArgumentException("The attribute named [" + name + "] is not of the java type [" + elementType + "].");                    
183
                }
183
                }
184
        } else {            
184
        } else {            
185
            throw new IllegalArgumentException("The attributed named [" + name + "] is not present in the managedType [" + this + "].");
185
            throw new IllegalArgumentException("The attribute named [" + name + "] is not present in the managedType [" + this + "].");
186
        }
186
        }
187
    }
187
    }
188
    
188
    
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java (-1 / +1 lines)
Lines 341-347 Link Here
341
        StringBuffer aBuffer = new StringBuffer();
341
        StringBuffer aBuffer = new StringBuffer();
342
        aBuffer.append(this.getClass().getSimpleName());
342
        aBuffer.append(this.getClass().getSimpleName());
343
        aBuffer.append("@");
343
        aBuffer.append("@");
344
        aBuffer.append(getClass().hashCode());
344
        aBuffer.append(hashCode());
345
        aBuffer.append(" [descriptor: ");
345
        aBuffer.append(" [descriptor: ");
346
        aBuffer.append(this.getDescriptor());
346
        aBuffer.append(this.getDescriptor());
347
        if(null != this.getDescriptor()) {
347
        if(null != this.getDescriptor()) {
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (-4 / +2 lines)
Lines 140-149 Link Here
140
        // Get mapped superclass types from the project (not a regular descriptor)
140
        // Get mapped superclass types from the project (not a regular descriptor)
141
        try {
141
        try {
142
            Project project = session.getProject();
142
            Project project = session.getProject();
143
            //Map<Class, RelationalDescriptor> descriptors = project.getMappedSuperclasses();
143
            Map<Object, RelationalDescriptor> descriptors = project.getMappedSuperclassDescriptors();
144
            Set<RelationalDescriptor> descriptors = project.getMappedSuperclassDescriptors();
144
            for(Iterator<RelationalDescriptor> anIterator = descriptors.values().iterator(); anIterator.hasNext();) {
145
            //for(Iterator<RelationalDescriptor> anIterator = descriptors.values().iterator(); anIterator.hasNext();) {            
146
            for(Iterator<RelationalDescriptor> anIterator = descriptors.iterator(); anIterator.hasNext();) {
147
                //Class key = anIterator.next();
145
                //Class key = anIterator.next();
148
                RelationalDescriptor descriptor = anIterator.next();//mappedSuperclassesSet.get(key);
146
                RelationalDescriptor descriptor = anIterator.next();//mappedSuperclassesSet.get(key);
149
                //MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(key, descriptor);
147
                //MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(key, descriptor);

Return to bug 266912