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

Collapse All | Expand All

(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-3 / +17 lines)
Lines 2372-2378 Link Here
2372
             *  @return the metamodel managed type
2372
             *  @return the metamodel managed type
2373
             *  @throws IllegalArgumentException if not a managed class
2373
             *  @throws IllegalArgumentException if not a managed class
2374
             */
2374
             */
2375
            //<X> ManagedType<X> type(Class<X> cls);
2375
            //<X> ManagedType<X> managedType(Class<X> cls);
2376
            // test normal path (subtype = Basic)
2376
            // test normal path (subtype = Basic)
2377
/*            expectedIAExceptionThrown = false;            
2377
/*            expectedIAExceptionThrown = false;            
2378
            try {
2378
            try {
Lines 2387-2392 Link Here
2387
            expectedIAExceptionThrown = false;            
2387
            expectedIAExceptionThrown = false;            
2388
            try {
2388
            try {
2389
                Type<EmbeddedPK> aType = metamodel.managedType(EmbeddedPK.class);
2389
                Type<EmbeddedPK> aType = metamodel.managedType(EmbeddedPK.class);
2390
                assertFalse(((TypeImpl)aType).isEntity());
2391
                assertFalse(((TypeImpl)aType).isMappedSuperclass());
2390
            } catch (IllegalArgumentException iae) {
2392
            } catch (IllegalArgumentException iae) {
2391
                iae.printStackTrace();
2393
                iae.printStackTrace();
2392
                expectedIAExceptionThrown = true;            
2394
                expectedIAExceptionThrown = true;            
Lines 2397-2402 Link Here
2397
            expectedIAExceptionThrown = false;            
2399
            expectedIAExceptionThrown = false;            
2398
            try {
2400
            try {
2399
                Type<Manufacturer> aType = metamodel.managedType(Manufacturer.class);
2401
                Type<Manufacturer> aType = metamodel.managedType(Manufacturer.class);
2402
                assertTrue(((TypeImpl)aType).isEntity());
2403
                assertFalse(((TypeImpl)aType).isMappedSuperclass());                
2400
            } catch (IllegalArgumentException iae) {
2404
            } catch (IllegalArgumentException iae) {
2401
                iae.printStackTrace();
2405
                iae.printStackTrace();
2402
                expectedIAExceptionThrown = true;            
2406
                expectedIAExceptionThrown = true;            
Lines 2423-2431 Link Here
2423
                //iae.printStackTrace();
2427
                //iae.printStackTrace();
2424
                expectedIAExceptionThrown = true;            
2428
                expectedIAExceptionThrown = true;            
2425
            }
2429
            }
2426
            assertNull(aTypeFromNullClass);
2430
            //assertNull(aTypeFromNullClass);
2427
            assertFalse(expectedIAExceptionThrown);            
2431
            assertTrue("IllegalArgumentException expected on Metamodel.managedType(null)",expectedIAExceptionThrown);            
2428
2432
2433
            // Type is basic - throw IAE
2434
            expectedIAExceptionThrown = false;            
2435
            try {
2436
                Type<Integer> aType = metamodel.managedType(Integer.class);                
2437
            } catch (IllegalArgumentException iae) {
2438
                //iae.printStackTrace();
2439
                expectedIAExceptionThrown = true;            
2440
            }
2441
            assertTrue("IllegalArgumentException expected on Metamodel.managedType(Integer.class)",expectedIAExceptionThrown);
2442
            
2429
            // test variant path: wrong type (java simple type)
2443
            // test variant path: wrong type (java simple type)
2430
            expectedIAExceptionThrown = false;            
2444
            expectedIAExceptionThrown = false;            
2431
            try {
2445
            try {
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (-12 / +10 lines)
Lines 23-28 Link Here
23
 *       all other 6 remaining methods for Id and Version support.
23
 *       all other 6 remaining methods for Id and Version support.
24
 *       DI 70 - 77 and 56
24
 *       DI 70 - 77 and 56
25
 *       http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_74:_20090909:_Implement_IdentifiableType.hasSingleIdAttribute.28.29 
25
 *       http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_74:_20090909:_Implement_IdentifiableType.hasSingleIdAttribute.28.29 
26
 *     10/14/2009-2.0  mobrien - 285512: managedType(clazz) now throws IAE again for 
27
 *        any clazz that resolves to a BasicType - use getType(clazz) in implementations instead
28
 *        when you are expecting a BasicType
26
 ******************************************************************************/
29
 ******************************************************************************/
27
package org.eclipse.persistence.internal.jpa.metamodel;
30
package org.eclipse.persistence.internal.jpa.metamodel;
28
31
Lines 395-412 Link Here
395
    public <X> ManagedType<X> managedType(Class<X> clazz) {
398
    public <X> ManagedType<X> managedType(Class<X> clazz) {
396
        Object aType = this.managedTypes.get(clazz);
399
        Object aType = this.managedTypes.get(clazz);
397
        // Throw an IAE exception if the returned type is not a ManagedType
400
        // Throw an IAE exception if the returned type is not a ManagedType
398
        // However in this case the type will usually be null - as no Basic types are in the managedTypes Map
401
        // For any clazz that resolves to a BasicType - use getType(clazz) in implementations when you are expecting a BasicType
399
        if(null == aType) {
402
        if(null != aType && aType instanceof ManagedType) {
400
            // return null as there is no way to check the return type for isManagedType
403
            return (ManagedType<X>) aType;
401
            return null;
404
        } else {
402
        } else {        
405
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
403
            if(aType instanceof ManagedType) {
406
                    "metamodel_class_incorrect_type_instance", 
404
                return (ManagedType<X>) aType;
407
                    new Object[] { clazz, "ManagedType", aType}));
405
            } else {
406
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
407
                        "metamodel_class_incorrect_type_instance", 
408
                        new Object[] { clazz, "ManagedType", aType}));
409
            }
410
        }
408
        }
411
    }
409
    }
412
    
410
    
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/querydef/CriteriaBuilderImpl.java (-1 / +3 lines)
Lines 33-38 Link Here
33
import org.eclipse.persistence.internal.expressions.SubSelectExpression;
33
import org.eclipse.persistence.internal.expressions.SubSelectExpression;
34
import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl;
34
import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl;
35
import org.eclipse.persistence.internal.helper.ClassConstants;
35
import org.eclipse.persistence.internal.helper.ClassConstants;
36
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
37
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
36
import org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.ResultType;
38
import org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.ResultType;
37
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
39
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
38
import org.eclipse.persistence.queries.ReportQuery;
40
import org.eclipse.persistence.queries.ReportQuery;
Lines 74-80 Link Here
74
                if (resultClass.isPrimitive() || resultClass.equals(ClassConstants.STRING)|| BasicTypeHelperImpl.getInstance().isWrapperClass(resultClass) || BasicTypeHelperImpl.getInstance().isDateClass(resultClass)) {
76
                if (resultClass.isPrimitive() || resultClass.equals(ClassConstants.STRING)|| BasicTypeHelperImpl.getInstance().isWrapperClass(resultClass) || BasicTypeHelperImpl.getInstance().isDateClass(resultClass)) {
75
                    return new CriteriaQueryImpl<T>(metamodel, ResultType.OTHER, resultClass, this);
77
                    return new CriteriaQueryImpl<T>(metamodel, ResultType.OTHER, resultClass, this);
76
                } else {
78
                } else {
77
                    ManagedType type = this.metamodel.managedType(resultClass);
79
                    TypeImpl type = ((MetamodelImpl)this.metamodel).getType(resultClass);
78
                    if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
80
                    if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
79
                        return new CriteriaQueryImpl(this.metamodel, ResultType.ENTITY, resultClass, this);
81
                        return new CriteriaQueryImpl(this.metamodel, ResultType.ENTITY, resultClass, this);
80
                    } else {
82
                    } else {
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/querydef/CriteriaQueryImpl.java (-2 / +4 lines)
Lines 38-43 Link Here
38
import org.eclipse.persistence.internal.expressions.ConstantExpression;
38
import org.eclipse.persistence.internal.expressions.ConstantExpression;
39
import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl;
39
import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl;
40
import org.eclipse.persistence.internal.helper.ClassConstants;
40
import org.eclipse.persistence.internal.helper.ClassConstants;
41
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
42
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
41
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
43
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
42
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
44
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
43
import org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor;
45
import org.eclipse.persistence.internal.security.PrivilegedGetConstructorFor;
Lines 113-119 Link Here
113
            }
115
            }
114
        } else {
116
        } else {
115
            this.queryType = selection.getJavaType();
117
            this.queryType = selection.getJavaType();
116
            ManagedType type = this.metamodel.managedType(this.queryType);
118
            TypeImpl type = ((MetamodelImpl)this.metamodel).getType(this.queryType);
117
            if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
119
            if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
118
                this.queryResult = ResultType.ENTITY;
120
                this.queryResult = ResultType.ENTITY;
119
                ((FromImpl) selection).isLeaf = false; // this will be a
121
                ((FromImpl) selection).isLeaf = false; // this will be a
Lines 581-587 Link Here
581
583
582
            } else {
584
            } else {
583
                // Selection is not null set type to selection
585
                // Selection is not null set type to selection
584
                ManagedType type = this.metamodel.managedType(selection.getJavaType());
586
                TypeImpl type = ((MetamodelImpl)this.metamodel).getType(selection.getJavaType());
585
                if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
587
                if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
586
                    query = new ReadAllQuery(type.getJavaType());
588
                    query = new ReadAllQuery(type.getJavaType());
587
                    List<org.eclipse.persistence.expressions.Expression> list = ((FromImpl) this.roots.iterator().next()).findJoinFetches();
589
                    List<org.eclipse.persistence.expressions.Expression> list = ((FromImpl) this.roots.iterator().next()).findJoinFetches();
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/querydef/SubQueryImpl.java (-2 / +4 lines)
Lines 41-46 Link Here
41
import org.eclipse.persistence.internal.expressions.ConstantExpression;
41
import org.eclipse.persistence.internal.expressions.ConstantExpression;
42
import org.eclipse.persistence.internal.expressions.SubSelectExpression;
42
import org.eclipse.persistence.internal.expressions.SubSelectExpression;
43
import org.eclipse.persistence.internal.helper.ClassConstants;
43
import org.eclipse.persistence.internal.helper.ClassConstants;
44
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
45
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
44
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
46
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
45
import org.eclipse.persistence.queries.ReportQuery;
47
import org.eclipse.persistence.queries.ReportQuery;
46
48
Lines 110-116 Link Here
110
                this.subQuery.addItem(String.valueOf(count), ((InternalSelection) select).getCurrentNode());
112
                this.subQuery.addItem(String.valueOf(count), ((InternalSelection) select).getCurrentNode());
111
            }
113
            }
112
        } else {
114
        } else {
113
            ManagedType type = this.metamodel.managedType(selection.getJavaType());
115
            TypeImpl type = ((MetamodelImpl)this.metamodel).getType(selection.getJavaType());
114
            if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
116
            if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
115
                this.subQuery.addAttribute("", new ConstantExpression(1, ((InternalSelection)selection).getCurrentNode().getBuilder()));
117
                this.subQuery.addAttribute("", new ConstantExpression(1, ((InternalSelection)selection).getCurrentNode().getBuilder()));
116
                this.subQuery.addNonFetchJoinedAttribute(((InternalSelection)selection).getCurrentNode());
118
                this.subQuery.addNonFetchJoinedAttribute(((InternalSelection)selection).getCurrentNode());
Lines 523-529 Link Here
523
525
524
    protected void integrateRoot(RootImpl root) {
526
    protected void integrateRoot(RootImpl root) {
525
        if (this.roots.isEmpty()) {
527
        if (this.roots.isEmpty()) {
526
            ManagedType type = this.metamodel.managedType(this.queryType);
528
            TypeImpl type = ((MetamodelImpl)this.metamodel).getType(this.queryType);
527
            if ((type != null && type.getPersistenceType() == PersistenceType.ENTITY) || queryType.equals(ClassConstants.OBJECT)) {
529
            if ((type != null && type.getPersistenceType() == PersistenceType.ENTITY) || queryType.equals(ClassConstants.OBJECT)) {
528
                // this is the first root, set return type and selection and
530
                // this is the first root, set return type and selection and
529
                // query
531
                // query

Return to bug 285512