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/mappings/DirectCollectionMapping.java (-1 / +103 lines)
Lines 55-60 Link Here
55
 *
55
 *
56
 * @author Sati
56
 * @author Sati
57
 * @since TOPLink/Java 1.0
57
 * @since TOPLink/Java 1.0
58
 * 
59
 *     09/18/2009-2.0 Michael O'Brien  
60
 *       - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API) 
61
 *         add support for passing BasicMap value type to MapAttributeImpl via new attributeClassification field  
58
 */
62
 */
59
public class DirectCollectionMapping extends CollectionMapping implements RelationalMapping {
63
public class DirectCollectionMapping extends CollectionMapping implements RelationalMapping {
60
64
Lines 92-97 Link Here
92
    protected transient ModifyQuery updateAtIndexQuery;
96
    protected transient ModifyQuery updateAtIndexQuery;
93
    protected transient boolean hasCustomDeleteAtIndexQuery;
97
    protected transient boolean hasCustomDeleteAtIndexQuery;
94
    protected transient boolean hasCustomUpdateAtIndexQuery;
98
    protected transient boolean hasCustomUpdateAtIndexQuery;
99
    
100
    /**
101
     * @since Java Persistence API 2.0
102
     * Referenced by MapAttributeImpl to pick up the BasicMap value parameter type 
103
     * To specify the conversion type 
104
     * */
105
    protected transient Class attributeClassification;
106
    protected transient String attributeClassificationName;    
107
    /** 
108
     * @since Java Persistence API 2.0
109
     * Referenced by MapAttributeImpl to pick up the BasicMap value parameter type 
110
     * PERF: Also store object class of attribute in case of primitive. 
111
     * */
112
    protected transient Class attributeObjectClassification;
95
113
96
    /**
114
    /**
97
     * PUBLIC:
115
     * PUBLIC:
Lines 753-761 Link Here
753
     * This method is implemented by subclasses as necessary.
771
     * This method is implemented by subclasses as necessary.
754
     * @param classLoader 
772
     * @param classLoader 
755
     */
773
     */
756
    public void convertClassNamesToClasses(ClassLoader classLoader){
774
    public void convertClassNamesToClasses(ClassLoader classLoader) {
757
        super.convertClassNamesToClasses(classLoader);
775
        super.convertClassNamesToClasses(classLoader);
758
        
776
        
777
        /**
778
         * 266912 DI 83: This code block sets the value parameter type so that it
779
         * can be picked up by the Metamodel PluralAttributeImpl constructor.
780
         * The typeName String is used instead of the type Class because of the
781
         * way that converters shadow the type/typeName in bug# 289487
782
         *  @since Java Persistence API 2.0 for the Metamodel API
783
         */
784
        if(null == this.attributeClassification) {
785
            String typeName = this.directField.getTypeName();
786
            if(null != typeName) {
787
                // Create the Class based on the class name - no need to use the ConversionManager as we have the correct ClassLoader
788
                try {
789
                    if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
790
                        try {
791
                            this.attributeClassification = (Class) AccessController.doPrivileged(new PrivilegedClassForName(typeName, true, classLoader));
792
                        } catch (PrivilegedActionException pae) {
793
                            throw ValidationException.classNotFoundWhileConvertingClassNames(typeName, pae.getException());
794
                        }
795
                    } else {
796
                        this.attributeClassification = org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(typeName, true, classLoader);
797
                    }
798
                } catch (ClassNotFoundException cnfe) {
799
                    throw ValidationException.classNotFoundWhileConvertingClassNames(typeName, cnfe);
800
                } catch (Exception iae_or_ie) {
801
                    // Catches IllegalAccessException and InstantiationException
802
                    throw ValidationException.classNotFoundWhileConvertingClassNames(typeName, iae_or_ie);
803
                }
804
                this.attributeClassificationName = typeName;
805
            }
806
        }
807
        if(null != this.attributeClassification) {
808
            this.attributeObjectClassification = Helper.getObjectClass(this.attributeClassification);
809
        }
810
        
811
759
        if (valueConverter != null) {
812
        if (valueConverter != null) {
760
            if (valueConverter instanceof TypeConversionConverter){
813
            if (valueConverter instanceof TypeConversionConverter){
761
                ((TypeConversionConverter)valueConverter).convertClassNamesToClasses(classLoader);
814
                ((TypeConversionConverter)valueConverter).convertClassNamesToClasses(classLoader);
Lines 944-949 Link Here
944
        // do nothing
997
        // do nothing
945
    }
998
    }
946
999
1000
    
1001
    /**
1002
     * PUBLIC:
1003
     * Some databases do not properly support all of the base data types. For these databases,
1004
     * the base data type must be explicitly specified in the mapping to tell EclipseLink to force
1005
     * the instance variable value to that data type.
1006
     * @since Java Persistence API 2.0
1007
     */
1008
    public Class getAttributeClassification() {
1009
        return attributeClassification;
1010
    }
1011
1012
    /**
1013
     * INTERNAL:
1014
     * Return the class name of the attribute type.
1015
     * This is only used by the MW.
1016
     * @since Java Persistence API 2.0
1017
     */
1018
    public String getAttributeClassificationName() {
1019
        if ((null == attributeClassificationName) && (attributeClassification != null)) {
1020
            attributeClassificationName = attributeClassification.getName();
1021
        }
1022
        return attributeClassificationName;
1023
    }
1024
    
947
    protected ModifyQuery getDeleteQuery() {
1025
    protected ModifyQuery getDeleteQuery() {
948
        if (changeSetDeleteQuery == null) {
1026
        if (changeSetDeleteQuery == null) {
949
            changeSetDeleteQuery = new DataModifyQuery();
1027
            changeSetDeleteQuery = new DataModifyQuery();
Lines 2205-2210 Link Here
2205
    @Override
2283
    @Override
2206
    public void recordPrivateOwnedRemovals(Object object, UnitOfWorkImpl uow) {
2284
    public void recordPrivateOwnedRemovals(Object object, UnitOfWorkImpl uow) {
2207
    }
2285
    }
2286
    
2208
    /**
2287
    /**
2209
     * INTERNAL:
2288
     * INTERNAL:
2210
     * Once descriptors are serialized to the remote session. All its mappings and reference descriptors are traversed. Usually
2289
     * Once descriptors are serialized to the remote session. All its mappings and reference descriptors are traversed. Usually
Lines 2220-2225 Link Here
2220
        }
2299
        }
2221
    }
2300
    }
2222
2301
2302
  
2223
    /**
2303
    /**
2224
     * INTERNAL:
2304
     * INTERNAL:
2225
     * replace the value holders in the specified reference object(s)
2305
     * replace the value holders in the specified reference object(s)
Lines 2229-2234 Link Here
2229
        return null;
2309
        return null;
2230
    }
2310
    }
2231
2311
2312
    /**
2313
     * PUBLIC:
2314
     * Some databases do not properly support all of the base data types. For these databases,
2315
     * the base data type must be explicitly specified in the mapping to tell EclipseLink to force
2316
     * the instance variable value to that data type.
2317
     * @since Java Persistence API 2.0
2318
     * Migrated from AbstractDirectMapping 
2319
     */
2320
    public void setAttributeClassification(Class attributeClassification) {
2321
        this.attributeClassification = attributeClassification;
2322
    }
2323
2324
    /**
2325
     * INTERNAL:
2326
     * Set the name of the class for MW usage.
2327
     * @since Java Persistence API 2.0
2328
     * Migrated from AbstractDirectMapping 
2329
     */
2330
    public void setAttributeClassificationName(String attributeClassificationName) {
2331
        this.attributeClassificationName = attributeClassificationName;
2332
    }
2333
    
2232
    protected void setDeleteQuery(ModifyQuery query) {
2334
    protected void setDeleteQuery(ModifyQuery query) {
2233
        this.changeSetDeleteQuery = query;
2335
        this.changeSetDeleteQuery = query;
2234
    }
2336
    }
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/advanced/AdvancedJPAJunitTest.java (-17 / +17 lines)
Lines 21-54 Link Here
21
import java.util.Set;
21
import java.util.Set;
22
import java.util.Vector;
22
import java.util.Vector;
23
23
24
import javax.persistence.EntityManager;
24
import javax.persistence.Query;
25
import javax.persistence.Query;
25
import javax.persistence.EntityManager;
26
import javax.persistence.metamodel.Attribute;
26
import javax.persistence.metamodel.Attribute;
27
import javax.persistence.metamodel.EntityType;
27
import javax.persistence.metamodel.EntityType;
28
import javax.persistence.metamodel.MapAttribute;
28
import javax.persistence.metamodel.Metamodel;
29
import javax.persistence.metamodel.Metamodel;
29
import javax.persistence.metamodel.SingularAttribute;
30
import javax.persistence.metamodel.SingularAttribute;
30
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
31
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
31
import javax.persistence.metamodel.Bindable.BindableType;
32
import javax.persistence.metamodel.Bindable.BindableType;
32
import javax.persistence.metamodel.Type.PersistenceType;
33
import javax.persistence.metamodel.Type.PersistenceType;
33
34
34
import junit.framework.*;
35
import junit.framework.Test;
36
import junit.framework.TestSuite;
35
37
36
import org.eclipse.persistence.descriptors.ClassDescriptor;
38
import org.eclipse.persistence.descriptors.ClassDescriptor;
39
import org.eclipse.persistence.descriptors.invalidation.CacheInvalidationPolicy;
37
import org.eclipse.persistence.descriptors.invalidation.TimeToLiveCacheInvalidationPolicy;
40
import org.eclipse.persistence.descriptors.invalidation.TimeToLiveCacheInvalidationPolicy;
38
import org.eclipse.persistence.descriptors.invalidation.CacheInvalidationPolicy;
41
import org.eclipse.persistence.internal.helper.ClassConstants;
39
import org.eclipse.persistence.queries.DoesExistQuery;
42
import org.eclipse.persistence.internal.helper.Helper;
40
import org.eclipse.persistence.sessions.server.ServerSession;
41
import org.eclipse.persistence.mappings.DatabaseMapping;
42
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
43
import org.eclipse.persistence.internal.jpa.EJBQueryImpl;
43
import org.eclipse.persistence.internal.jpa.EJBQueryImpl;
44
import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl;
44
import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl;
45
import org.eclipse.persistence.internal.jpa.EntityManagerImpl;
45
import org.eclipse.persistence.internal.jpa.EntityManagerImpl;
46
import org.eclipse.persistence.internal.jpa.metamodel.MapAttributeImpl;
46
import org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl;
47
import org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl;
47
import org.eclipse.persistence.internal.helper.ClassConstants;
48
import org.eclipse.persistence.mappings.DatabaseMapping;
48
import org.eclipse.persistence.internal.helper.Helper;
49
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
49
50
import org.eclipse.persistence.queries.DoesExistQuery;
51
import org.eclipse.persistence.sessions.server.ServerSession;
50
import org.eclipse.persistence.testing.framework.JoinedAttributeTestHelper;
52
import org.eclipse.persistence.testing.framework.JoinedAttributeTestHelper;
51
52
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
53
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
53
import org.eclipse.persistence.testing.models.jpa.advanced.Address;
54
import org.eclipse.persistence.testing.models.jpa.advanced.Address;
54
import org.eclipse.persistence.testing.models.jpa.advanced.AdvancedTableCreator;
55
import org.eclipse.persistence.testing.models.jpa.advanced.AdvancedTableCreator;
Lines 57-74 Link Here
57
import org.eclipse.persistence.testing.models.jpa.advanced.Dealer;
58
import org.eclipse.persistence.testing.models.jpa.advanced.Dealer;
58
import org.eclipse.persistence.testing.models.jpa.advanced.Department;
59
import org.eclipse.persistence.testing.models.jpa.advanced.Department;
59
import org.eclipse.persistence.testing.models.jpa.advanced.Employee;
60
import org.eclipse.persistence.testing.models.jpa.advanced.Employee;
61
import org.eclipse.persistence.testing.models.jpa.advanced.EmployeePopulator;
60
import org.eclipse.persistence.testing.models.jpa.advanced.EmploymentPeriod;
62
import org.eclipse.persistence.testing.models.jpa.advanced.EmploymentPeriod;
61
import org.eclipse.persistence.testing.models.jpa.advanced.EmployeePopulator;
62
import org.eclipse.persistence.testing.models.jpa.advanced.Equipment;
63
import org.eclipse.persistence.testing.models.jpa.advanced.Equipment;
63
import org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode;
64
import org.eclipse.persistence.testing.models.jpa.advanced.EquipmentCode;
64
import org.eclipse.persistence.testing.models.jpa.advanced.GoldBuyer;
65
import org.eclipse.persistence.testing.models.jpa.advanced.GoldBuyer;
66
import org.eclipse.persistence.testing.models.jpa.advanced.LargeProject;
65
import org.eclipse.persistence.testing.models.jpa.advanced.PhoneNumber;
67
import org.eclipse.persistence.testing.models.jpa.advanced.PhoneNumber;
66
import org.eclipse.persistence.testing.models.jpa.advanced.LargeProject;
67
import org.eclipse.persistence.testing.models.jpa.advanced.Project;
68
import org.eclipse.persistence.testing.models.jpa.advanced.Project;
68
import org.eclipse.persistence.testing.models.jpa.advanced.SmallProject;
69
import org.eclipse.persistence.testing.models.jpa.advanced.SmallProject;
69
70
70
/**
71
/**
71
 * This test suite tests TopLink JPA annotations extensions.
72
 * This test suite tests EclipseLink JPA annotations extensions.
72
 */
73
 */
73
public class AdvancedJPAJunitTest extends JUnitTestCase {
74
public class AdvancedJPAJunitTest extends JUnitTestCase {
74
    private static int empId;
75
    private static int empId;
Lines 251-258 Link Here
251
            assertFalse(expectedIAExceptionThrown);            
252
            assertFalse(expectedIAExceptionThrown);            
252
            assertTrue(hasSingleIdAttribute);
253
            assertTrue(hasSingleIdAttribute);
253
*/
254
*/
254
            // In mid implementation in Design Issue 83
255
            // Verify that the BasicMap Buyer.creditCards is picked up properly
255
/*          // Verify that the BasicMap Buyer.creditCards is picked up properly
256
            //* @param <X> The type the represented Map belongs to
256
            //* @param <X> The type the represented Map belongs to
257
            //* @param <K> The type of the key of the represented Map
257
            //* @param <K> The type of the key of the represented Map
258
            //* @param <V> The type of the value of the represented Map
258
            //* @param <V> The type of the value of the represented Map
Lines 272-278 Link Here
272
        
272
        
273
            // Verify Map Value
273
            // Verify Map Value
274
            assertEquals(Long.class, buyerCreditCardsMap.getElementType().getJavaType());
274
            assertEquals(Long.class, buyerCreditCardsMap.getElementType().getJavaType());
275
*/        
275
        
276
        }
276
        }
277
    }
277
    }
278
    
278
    
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-15 / +148 lines)
Lines 59-64 Link Here
59
import org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTypeImpl;
59
import org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTypeImpl;
60
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl;
60
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl;
61
import org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl;
61
import org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl;
62
import org.eclipse.persistence.internal.jpa.metamodel.MapAttributeImpl;
62
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl;
63
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl;
63
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
64
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
64
import org.eclipse.persistence.internal.jpa.metamodel.PluralAttributeImpl;
65
import org.eclipse.persistence.internal.jpa.metamodel.PluralAttributeImpl;
Lines 164-182 Link Here
164
    
165
    
165
    public static Test suite() {
166
    public static Test suite() {
166
        TestSuite suite = new TestSuite("MetamodelMetamodelTest");
167
        TestSuite suite = new TestSuite("MetamodelMetamodelTest");
167
168
        suite.addTest(new MetamodelMetamodelTest("testMetamodelLazyInitialization"));
168
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelStringBasedQuery"));
169
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelTypeSafeBasedQuery"));
170
        suite.addTest(new MetamodelMetamodelTest("testMetamodelFullImplementation"));
169
        suite.addTest(new MetamodelMetamodelTest("testMetamodelFullImplementation"));
170
        suite.addTest(new MetamodelMetamodelTest("testMapAtributeElementTypeWhenMapKeySetButNameAttributeIsDefaulted"));
171
        suite.addTest(new MetamodelMetamodelTest("testMapAtributeElementTypeWhenMapKeySetAndNameAttributeSet"));        
171
        return suite;
172
        return suite;
172
    }
173
    }
173
174
175
    private EntityManager privateTestSetup() {
176
        EntityManagerFactory emf = null;
177
        EntityManager em = null;
178
        boolean exceptionThrown = false;
179
        Metamodel metamodel = null;
180
        try {
181
            emf = initialize();
182
            em = emf.createEntityManager();
183
            // Unset the metamodel - for repeated runs through this test
184
            if(!isOnServer()) { 
185
                ((EntityManagerFactoryImpl)emf).setMetamodel(null);
186
            }
187
            metamodel = em.getMetamodel();
188
            assertNotNull(metamodel);
189
        } catch (Exception e) {
190
            e.printStackTrace();
191
            if(null != em) {
192
                cleanup(em);
193
            }
194
        }
195
        return em;
196
    }
197
    
198
    private void privateTestTeardown() {        
199
    }
200
    
201
    public void testMetamodelLazyInitialization() {
202
        if(!this.isJPA10()) {
203
            boolean exceptionThrown = false;
204
            EntityManager em = null;            
205
            try {
206
                em = privateTestSetup();
207
                assertNotNull(em);
208
                Metamodel metamodel = em.getMetamodel();
209
                assertNotNull(metamodel);
210
            } catch (Exception e) {
211
                e.printStackTrace();
212
                exceptionThrown = true;
213
            } finally {
214
                assertFalse(exceptionThrown);
215
                if(null != em) {
216
                    cleanup(em);
217
                }
218
            }
219
        }
220
    }    
221
174
    /**
222
    /**
223
     * This test will verify that MapAttribute instance have their elementType set correctly.
224
     * The elementType corresponds to the 3rd V parameter on the class definition - which is the Map value.
225
     * MapAttributeImpl<X, K, V> 
226
     */
227
    public void testMapAtributeElementTypeWhenMapKeySetButNameAttributeIsDefaulted() {
228
        if(!this.isJPA10()) {
229
            boolean exceptionThrown = false;
230
            EntityManager em = null;            
231
            try {
232
                em = privateTestSetup();
233
                assertNotNull(em);
234
                Metamodel metamodel = em.getMetamodel();
235
                assertNotNull(metamodel);
236
                
237
                EntityType<Manufacturer> entityManufacturer = metamodel.entity(Manufacturer.class);
238
                assertNotNull(entityManufacturer);                
239
                Attribute hardwareDesignersMap = entityManufacturer.getAttribute("hardwareDesignersMapUC8");
240
                assertNotNull(hardwareDesignersMap);
241
                assertTrue(hardwareDesignersMap.isCollection());
242
                assertTrue(hardwareDesignersMap instanceof MapAttributeImpl);
243
                MapAttribute<? super Manufacturer, ?, ?> manufactuerHardwareDesignersMap = entityManufacturer.getMap("hardwareDesignersMapUC8");            
244
                // Verify owning type
245
                assertNotNull(manufactuerHardwareDesignersMap);
246
                assertEquals(entityManufacturer, manufactuerHardwareDesignersMap.getDeclaringType());            
247
                // Verify Map Key - should be PK of owning type
248
                assertEquals(Integer.class, manufactuerHardwareDesignersMap.getKeyJavaType());            
249
                // Verify Map Value
250
                assertEquals(HardwareDesigner.class, manufactuerHardwareDesignersMap.getElementType().getJavaType());
251
                
252
            } catch (Exception e) {
253
                // we enter here on a failed commit() - for example if the table schema is incorrectly defined
254
                e.printStackTrace();
255
                exceptionThrown = true;
256
            } finally {
257
                assertFalse(exceptionThrown);
258
                try {
259
                } catch (Exception e) {
260
                    e.printStackTrace();
261
                } finally {
262
                    if(null != em) {
263
                        cleanup(em);
264
                    }
265
                }
266
            }
267
        }
268
    }
269
270
    public void testMapAtributeElementTypeWhenMapKeySetAndNameAttributeSet() {
271
        if(!this.isJPA10()) {
272
            EntityManager em = null;
273
            boolean exceptionThrown = false;
274
            try {
275
                em = privateTestSetup();
276
                assertNotNull(em);
277
                Metamodel metamodel = em.getMetamodel();
278
                assertNotNull(metamodel);
279
                
280
                EntityType<Manufacturer> entityManufacturer = metamodel.entity(Manufacturer.class);
281
                assertNotNull(entityManufacturer);                
282
                Attribute hardwareDesignersMap = entityManufacturer.getAttribute("hardwareDesignersMapUC4");
283
                assertNotNull(hardwareDesignersMap);
284
                assertTrue(hardwareDesignersMap.isCollection());
285
                assertTrue(hardwareDesignersMap instanceof MapAttributeImpl);
286
                MapAttribute<? super Manufacturer, ?, ?> manufactuerHardwareDesignersMap = entityManufacturer.getMap("hardwareDesignersMapUC4");            
287
                // Verify owning type
288
                assertNotNull(manufactuerHardwareDesignersMap);
289
                assertEquals(entityManufacturer, manufactuerHardwareDesignersMap.getDeclaringType());            
290
                // Verify Map Key - should be PK of owning type
291
                assertEquals(String.class, manufactuerHardwareDesignersMap.getKeyJavaType());            
292
                // Verify Map Value
293
                assertEquals(HardwareDesigner.class, manufactuerHardwareDesignersMap.getElementType().getJavaType());
294
                
295
            } catch (Exception e) {
296
                // we enter here on a failed commit() - for example if the table schema is incorrectly defined
297
                e.printStackTrace();
298
                exceptionThrown = true;
299
            } finally {
300
                assertFalse(exceptionThrown);
301
                try {
302
                } catch (Exception e) {
303
                    e.printStackTrace();
304
                } finally {
305
                    if(null != em) {
306
                        cleanup(em);
307
                    }
308
                }
309
            }
310
        }
311
    }
312
    
313
    /**
175
     * The following large single test case contains signatures of all the spec functions.
314
     * The following large single test case contains signatures of all the spec functions.
176
     * Those that have a test are implemented, the missing ones may still be in development.
315
     * Those that have a test are implemented, the missing ones may still be in development.
177
     */
316
     */
178
    public void testMetamodelFullImplementation() {
317
    public void testMetamodelFullImplementation() {
179
        EntityManagerFactory emf = null;
318
        if(!this.isJPA10()) {
180
        EntityManager em = null;
319
        EntityManager em = null;
181
        Collection<Board> boardCollection = new HashSet<Board>();        
320
        Collection<Board> boardCollection = new HashSet<Board>();        
182
        Set<Computer> computersList = new HashSet<Computer>();
321
        Set<Computer> computersList = new HashSet<Computer>();
Lines 206-225 Link Here
206
        EmbeddedPK embeddedPKforLocation2 = new EmbeddedPK();
345
        EmbeddedPK embeddedPKforLocation2 = new EmbeddedPK();
207
        
346
        
208
        boolean exceptionThrown = false;
347
        boolean exceptionThrown = false;
209
        Metamodel metamodel = null;
210
211
        try {
348
        try {
212
            emf = initialize();
349
            em = privateTestSetup();
213
            em = emf.createEntityManager();
350
            assertNotNull(em);
214
351
            Metamodel metamodel = em.getMetamodel();
215
            // Unset the metamodel - for repeated runs through this test
216
            ((EntityManagerFactoryImpl)emf).setMetamodel(null);
217
            // Pre-Persist: get Metamodel representation of the entity schema
218
            metamodel = em.getMetamodel();
219
            assertNotNull(metamodel);
352
            assertNotNull(metamodel);
220
            // Test toString() override
221
            //System.out.println("_Metamodel just after initialization - toString() testing: " + metamodel);
222
353
354
            // SE only            
223
            em.getTransaction().begin();
355
            em.getTransaction().begin();
224
356
225
            // setup entity relationships
357
            // setup entity relationships
Lines 2426-2431 Link Here
2426
                }
2558
                }
2427
            }
2559
            }
2428
        }
2560
        }
2561
        }
2429
    }
2562
    }
2430
    
2563
    
2431
    
2564
    
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java (-1 lines)
Lines 402-408 Link Here
402
                } else if (descriptor.isAggregateCollectionDescriptor()) {
402
                } else if (descriptor.isAggregateCollectionDescriptor()) {
403
                    // TODO: Embeddable Collection handling is in progress
403
                    // TODO: Embeddable Collection handling is in progress
404
                    // AGGREGATE_COLLECTION:3 can be an embeddable or entity type depending on ?
404
                    // AGGREGATE_COLLECTION:3 can be an embeddable or entity type depending on ?
405
                    //managedType = new EntityTypeImpl(metamodel, descriptor);
406
                    managedType = new EmbeddableTypeImpl(metamodel, descriptor);
405
                    managedType = new EmbeddableTypeImpl(metamodel, descriptor);
407
                }
406
                }
408
            } else if(descriptor.isDescriptorTypeNormal()) {
407
            } else if(descriptor.isDescriptorTypeNormal()) {
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MapAttributeImpl.java (-40 / +34 lines)
Lines 67-124 Link Here
67
     * @param validationEnabled
67
     * @param validationEnabled
68
     */
68
     */
69
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
69
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
70
        // Set the managedType (X or owning Type)
70
        super(managedType, mapping, validationEnabled);
71
        super(managedType, mapping, validationEnabled);
72
        // Override the elementType (V or Map value)
71
        // We need to set the keyType Type that represents the type of the Map key for this mapping
73
        // We need to set the keyType Type that represents the type of the Map key for this mapping
72
        ContainerPolicy policy = mapping.getContainerPolicy();
74
        ContainerPolicy policy = mapping.getContainerPolicy();
73
        Object policyKeyType = policy.getKeyType(); // returns a Class<?> or descriptor (via AggregateObjectMapping)        
75
        Object policyKeyType = policy.getKeyType(); // returns a Class<?> or descriptor (via AggregateObjectMapping)        
74
        Type<?> aKeyType = null;
76
        Type<?> aKeyType = null;
75
        // Default to Object class for any variant cases that are not handled
77
        // Default to Object class for any variant cases that are not handled
76
        Class<?> javaClass = Object.class;
78
        Class<?> javaClass = null;
77
        if(null == policyKeyType) {
79
        if(null == policyKeyType) {
78
            // No policy key type = IdClass (use CMP3Policy.pkClass)
80
            // No policy key type = IdClass (use CMP3Policy.pkClass)
79
            if(managedType.isIdentifiableType()) {
81
            if(managedType.isIdentifiableType()) {
80
                // Use the CMPPolicy on the element not the one on the managedType
82
                // Use the CMPPolicy on the element not the one on the managedType
81
                if(policy.getElementDescriptor() != null && policy.getElementDescriptor().getCMPPolicy() != null) {
83
                if(policy.getElementDescriptor() != null && policy.getElementDescriptor().getCMPPolicy() != null) {
82
                    javaClass = policy.getElementDescriptor().getCMPPolicy().getPKClass();
84
                    javaClass = policy.getElementDescriptor().getCMPPolicy().getPKClass();
83
                    if(null == javaClass) {
85
                }
84
                        // check for a @MapKeyClass annotation
86
                if(null == javaClass) {
85
                        if(policy.isMappedKeyMapPolicy()) {                            
87
                    // check for a @MapKeyClass annotation
86
                            MapKeyMapping mapKeyMapping = ((MappedKeyMapContainerPolicy)policy).getKeyMapping();
88
                    if(policy.isMappedKeyMapPolicy()) {                            
87
                            RelationalDescriptor descriptor = (RelationalDescriptor)((DatabaseMapping)mapKeyMapping).getDescriptor();
89
                        javaClass = getOwningPrimaryKeyTypeWhenMapKeyAnnotationMissingOrDefaulted((MappedKeyMapContainerPolicy)policy);
88
                            // If the reference descriptor is null then we are on a direct mapping
89
                            if(null != descriptor) { 
90
                                javaClass = ((DatabaseMapping)mapKeyMapping).getAttributeClassification();
91
                                if(null == javaClass) {
92
                                    // Default to the PK of the owning descriptor when no MapKey is specified
93
                                    if (null != descriptor.getCMPPolicy()) {
94
                                        javaClass = descriptor.getCMPPolicy().getPKClass();
95
                                    }                                        
96
                                }
97
                            }
98
                        }
99
                    }
90
                    }
100
                } else {
101
                    if(null == policy.getElementDescriptor()) {
102
                        // check for a keyMapping on the mapping
103
                        if(policy.isMappedKeyMapPolicy()) {                            
104
                            MapKeyMapping mapKeyMapping = ((MappedKeyMapContainerPolicy)policy).getKeyMapping();
105
                            RelationalDescriptor descriptor = (RelationalDescriptor)((DatabaseMapping)mapKeyMapping).getDescriptor();
106
                            // If the reference descriptor is null then we are on a direct mapping
107
                            if(null == descriptor) {
108
                                javaClass = Object.class;
109
                            } else {
110
                                if(null == descriptor.getCMPPolicy()) { // for __PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME
111
                                    javaClass = ((DatabaseMapping)mapKeyMapping).getAttributeClassification();
112
                                    if(null == javaClass) {
113
                                        javaClass = Object.class;
114
                                    }
115
                                } else {
116
                                    // Default to the PK of the owning descriptor when no MapKey is specified
117
                                    javaClass = descriptor.getCMPPolicy().getPKClass();        
118
                                }
119
                            }
120
                        }
121
                    }
122
                }
91
                }
123
            } else {
92
            } else {
124
                // TODO: Handle EmbeddableType
93
                // TODO: Handle EmbeddableType
Lines 128-134 Link Here
128
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
97
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
129
                javaClass = (Class<?>)((ClassDescriptor)policyKeyType).getJavaClass();
98
                javaClass = (Class<?>)((ClassDescriptor)policyKeyType).getJavaClass();
130
            } else {
99
            } else {
131
                javaClass = (Class<?>)policyKeyType;
100
                if(policy.isMappedKeyMapPolicy()) {                            
101
                    javaClass = getOwningPrimaryKeyTypeWhenMapKeyAnnotationMissingOrDefaulted((MappedKeyMapContainerPolicy)policy);
102
                } else {                                        
103
                    javaClass = (Class<?>)policyKeyType;
104
                }
132
            }            
105
            }            
133
        }
106
        }
134
        if(null == javaClass) {
107
        if(null == javaClass) {
Lines 140-145 Link Here
140
    }
113
    }
141
114
142
    /**
115
    /**
116
     * INTERNAL:
117
     * Default to the PK of the owning descriptor when no MapKey or MapKey:name attribute is specified.
118
     * Prerequisites: policy on the mapping is of type MappedKeyMapPolicy
119
     * @return
120
     */
121
    private Class getOwningPrimaryKeyTypeWhenMapKeyAnnotationMissingOrDefaulted(MappedKeyMapContainerPolicy policy) {
122
        Class<?> javaClass = null;;
123
        MapKeyMapping mapKeyMapping = policy.getKeyMapping();
124
        RelationalDescriptor descriptor = (RelationalDescriptor)((DatabaseMapping)mapKeyMapping).getDescriptor();
125
        // If the reference descriptor is null then we are on a direct mapping
126
        if(null != descriptor) {
127
            javaClass = ((DatabaseMapping)mapKeyMapping).getAttributeClassification();
128
            if(null == javaClass) {
129
                // Default to the PK of the owning descriptor when no MapKey or MapKey:name attribute is specified
130
                javaClass = descriptor.getCMPPolicy().getPKClass();        
131
            }
132
        }
133
        return javaClass;
134
    }
135
    
136
    /**
143
     * Return the collection type.
137
     * Return the collection type.
144
     * @return collection type
138
     * @return collection type
145
     */
139
     */
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/PluralAttributeImpl.java (-13 / +22 lines)
Lines 23-34 Link Here
23
import javax.persistence.metamodel.Type;
23
import javax.persistence.metamodel.Type;
24
24
25
import org.eclipse.persistence.descriptors.ClassDescriptor;
25
import org.eclipse.persistence.descriptors.ClassDescriptor;
26
import org.eclipse.persistence.internal.queries.ContainerPolicy;
26
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
27
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
27
import org.eclipse.persistence.logging.AbstractSessionLog;
28
import org.eclipse.persistence.logging.AbstractSessionLog;
28
import org.eclipse.persistence.logging.SessionLog;
29
import org.eclipse.persistence.logging.SessionLog;
29
import org.eclipse.persistence.mappings.AggregateCollectionMapping;
30
import org.eclipse.persistence.mappings.AggregateCollectionMapping;
30
import org.eclipse.persistence.mappings.CollectionMapping;
31
import org.eclipse.persistence.mappings.CollectionMapping;
31
import org.eclipse.persistence.mappings.DirectCollectionMapping;
32
32
33
/**
33
/**
34
 * <p>
34
 * <p>
Lines 67-87 Link Here
67
        // 2) Get the type set on the policy        
67
        // 2) Get the type set on the policy        
68
        ClassDescriptor elementDesc = mapping.getContainerPolicy().getElementDescriptor();
68
        ClassDescriptor elementDesc = mapping.getContainerPolicy().getElementDescriptor();
69
69
70
        // Set the element type on this attribute
70
        // Set the element type on this attribute (the value parameter for a MapAttribute)
71
        if (elementDesc != null) {
71
        if (elementDesc != null && !(mapping.isMapKeyMapping() || mapping.isDirectMapMapping())) {
72
            // Mappings: OneToMany, UnidirectionalOneToMany, ManyToMany
72
            // Mappings: OneToMany, UnidirectionalOneToMany, ManyToMany
73
            this.elementType = (Type<V>)getMetamodel().getType(elementDesc.getJavaClass());
73
            this.elementType = (Type<V>)getMetamodel().getType(elementDesc.getJavaClass());
74
        } else {
74
        } else {
75
            // See CollectionContainerPolicy
75
            // See CollectionContainerPolicy
76
            Class attributeClass = null;
76
            Class attributeClass = null;
77
            // TODO: handle AggregateCollectionMapping
77
            // TODO: handle AggregateCollectionMapping
78
            if(mapping.isDirectCollectionMapping() || mapping.isAbstractCompositeDirectCollectionMapping()) {// || mapping.isAbstractDirectMapping() ) {
78
            if(mapping.isDirectCollectionMapping() || mapping.isAbstractCompositeDirectCollectionMapping() 
79
                //CollectionContainerPolicy policy = (CollectionContainerPolicy) mapping.getContainerPolicy();
79
                    || mapping.isDirectCollectionMapping()) {// || mapping.isAbstractDirectMapping() ) {
80
                //this.elementType = getMetamodel().getType(policy.getElementDescriptor().getJavaClass());                
81
                if(mapping.isDirectCollectionMapping()) {
82
                    attributeClass = ((DirectCollectionMapping)mapping).getDirectField().getType();                    
83
                }
84
                /**
80
                /**
81
                 * The Map Value parameter was set during metadata processing in DirectCollectionMapping.convertClassNamesToClasses() for example.
82
                 * The attributeClassification is set from the valueField.typeName String instead of the type Class because of the
83
                 * way that converters shadow the type/typeName in bug# 289487
84
                 */
85
                attributeClass = mapping.getAttributeClassification();
86
                /**
85
                 * TODO: REFACTOR
87
                 * TODO: REFACTOR
86
                 * We were unable to get the type because it is not declared as a generic parameter on the method level attribute.
88
                 * We were unable to get the type because it is not declared as a generic parameter on the method level attribute.
87
                 * It may be declared on the field.
89
                 * It may be declared on the field.
Lines 98-107 Link Here
98
                    //attributeClass = managedType.getTypeClassFromAttributeOrMethodLevelAccessor(mapping);
100
                    //attributeClass = managedType.getTypeClassFromAttributeOrMethodLevelAccessor(mapping);
99
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_unable_to_determine_element_type_in_absence_of_generic_parameters", this);
101
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_unable_to_determine_element_type_in_absence_of_generic_parameters", this);
100
                }
102
                }
101
            } else if(mapping.isMapKeyMapping()) {
103
            } else if(mapping.isMapKeyMapping()) {                   
102
                    // TODO: Handle DirectMapContainerPolicy                    
104
                ContainerPolicy policy = mapping.getContainerPolicy();
103
                    MapContainerPolicy policy = (MapContainerPolicy) mapping.getContainerPolicy();
105
                if(policy.isMapPolicy()) {
104
                    attributeClass = policy.getElementClass();
106
                    MapContainerPolicy mapPolicy = (MapContainerPolicy) mapping.getContainerPolicy();
107
                    attributeClass = mapPolicy.getElementClass();
108
                } else if(policy.isDirectMapPolicy()) {
109
                    attributeClass = mapping.getAttributeClassification();
110
                } else {
111
                    // TODO: refactor: default to the managedType
112
                    attributeClass = managedType.getJavaType();
113
                }
105
            } else if(mapping.isManyToManyMapping() || mapping.isOneToManyMapping()) {
114
            } else if(mapping.isManyToManyMapping() || mapping.isOneToManyMapping()) {
106
                // Example: Collection with an instantiated Set/List
115
                // Example: Collection with an instantiated Set/List
107
                attributeClass = ((CollectionMapping)mapping).getReferenceClass();
116
                attributeClass = ((CollectionMapping)mapping).getReferenceClass();

Return to bug 266912