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/ManyToManyMapping.java (-1 / +29 lines)
Lines 28-34 Link Here
28
/**
28
/**
29
 * <p><b>Purpose</b>: Many to many mappings are used to represent the relationships
29
 * <p><b>Purpose</b>: Many to many mappings are used to represent the relationships
30
 * between a collection of source objects and a collection of target objects.
30
 * between a collection of source objects and a collection of target objects.
31
 * The mapping require the creation of an intermediate table for managing the
31
 * The mapping requires the creation of an intermediate table for managing the
32
 * associations between the source and target records.
32
 * associations between the source and target records.
33
 *
33
 *
34
 * @author Sati
34
 * @author Sati
Lines 46-51 Link Here
46
    protected HistoryPolicy historyPolicy;
46
    protected HistoryPolicy historyPolicy;
47
47
48
    /**
48
    /**
49
     * 266912: Since: EclipseLink 2.0 for the Metamodel API
50
     * For 1:1 and m:m mappings - track the original externally defined mapping if different 
51
     * Note: This field will provide differentiation for the following 
52
     *   external to internal representations for mapping types<br>
53
     *   - A OneToManyMapping will be represented by a ManyToManyMapping if unidirectional<br>
54
     *   - A ManyToOneMapping will be represented by a OneToOneMapping (without a FK constraint)<br>      
55
     */
56
    protected boolean isDefinedAsOneToManyMapping = false;
57
    
58
    /**
49
     * PUBLIC:
59
     * PUBLIC:
50
     * Default constructor.
60
     * Default constructor.
51
     */
61
     */
Lines 696-701 Link Here
696
706
697
    /**
707
    /**
698
     * INTERNAL:
708
     * INTERNAL:
709
     * Return whether this mapping was originally defined as a OneToMany
710
     * @return
711
     */
712
    public boolean isDefinedAsOneToManyMapping() {
713
        return isDefinedAsOneToManyMapping;
714
    }
715
    
716
    /**
717
     * INTERNAL:
699
     * Return if this mapping support joining.
718
     * Return if this mapping support joining.
700
     */
719
     */
701
    public boolean isJoiningSupported() {
720
    public boolean isJoiningSupported() {
Lines 942-947 Link Here
942
    public void setDeleteSQLString(String sqlString) {
961
    public void setDeleteSQLString(String sqlString) {
943
        this.mechanism.setDeleteSQLString(sqlString);
962
        this.mechanism.setDeleteSQLString(sqlString);
944
    }
963
    }
964
965
    /**
966
     * INTERNAL:
967
     * Set whether this mapping was originally defined as a OneToMany
968
     * @param isDefinedAsOneToManyMapping
969
     */
970
    public void setDefinedAsOneToManyMapping(boolean isDefinedAsOneToManyMapping) {
971
        this.isDefinedAsOneToManyMapping = isDefinedAsOneToManyMapping;
972
    }
945
    
973
    
946
    /**
974
    /**
947
     * PUBLIC:
975
     * PUBLIC:
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/mappings/OneToOneMapping.java (+27 lines)
Lines 63-68 Link Here
63
    /** Mechanism holds relationTable and all fields and queries associated with it. */
63
    /** Mechanism holds relationTable and all fields and queries associated with it. */
64
    protected transient RelationTableMechanism mechanism;
64
    protected transient RelationTableMechanism mechanism;
65
65
66
    /**
67
     * 266912: Since: EclipseLink 2.0 for the Metamodel API
68
     * For 1:1 and m:m mappings - track the original externally defined mapping if different 
69
     * Note: This field will provide differentiation for the following 
70
     *   external to internal representations for mapping types<br>
71
     *   - A OneToManyMapping will be represented by a ManyToManyMapping if unidirectional<br>
72
     *   - A ManyToOneMapping will be represented by a OneToOneMapping (without a FK constraint)<br>      
73
     */
74
    protected boolean isDefinedAsManyToOneMapping = false;
66
    
75
    
67
    /**
76
    /**
68
     * PUBLIC:
77
     * PUBLIC:
Lines 1245-1250 Link Here
1245
    }
1254
    }
1246
1255
1247
    /**
1256
    /**
1257
     * INTERNAL:
1258
     * Set whether this mapping was originally defined as a ManyToOne
1259
     * @param isDefinedAsManyToOneMapping
1260
     */
1261
    public void setDefinedAsManyToOneMapping(boolean isDefinedAsManyToOneMapping) {
1262
        this.isDefinedAsManyToOneMapping = isDefinedAsManyToOneMapping;
1263
    }
1264
1265
    /**
1248
     * PUBLIC:
1266
     * PUBLIC:
1249
     * Define the foreign key relationship in the 1-1 mapping.
1267
     * Define the foreign key relationship in the 1-1 mapping.
1250
     * This method is used for singleton foreign key relationships only,
1268
     * This method is used for singleton foreign key relationships only,
Lines 1369-1374 Link Here
1369
    
1387
    
1370
    /**
1388
    /**
1371
     * INTERNAL:
1389
     * INTERNAL:
1390
     * Return whether this mapping was originally defined as a ManyToOne
1391
     * @return
1392
     */
1393
     public boolean isDefinedAsManyToOneMapping() {
1394
         return isDefinedAsManyToOneMapping;
1395
     }
1396
     
1397
    /**
1398
     * INTERNAL:
1372
     * Return if this mapping support joining.
1399
     * Return if this mapping support joining.
1373
     */
1400
     */
1374
    public boolean isJoiningSupported() {
1401
    public boolean isJoiningSupported() {
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Board.java (-2 / +4 lines)
Lines 27-32 Link Here
27
import javax.persistence.Entity;
27
import javax.persistence.Entity;
28
import javax.persistence.GeneratedValue;
28
import javax.persistence.GeneratedValue;
29
import javax.persistence.Id;
29
import javax.persistence.Id;
30
import javax.persistence.JoinColumn;
31
import javax.persistence.JoinTable;
30
import javax.persistence.ManyToOne;
32
import javax.persistence.ManyToOne;
31
import javax.persistence.OneToMany;
33
import javax.persistence.OneToMany;
32
import javax.persistence.Table;
34
import javax.persistence.Table;
Lines 65-73 Link Here
65
67
66
    // The M:1 side is the owning side for "circuitBoards"
68
    // The M:1 side is the owning side for "circuitBoards"
67
    @ManyToOne(fetch=EAGER)
69
    @ManyToOne(fetch=EAGER)
68
/*    @JoinTable(name="CMP3_MM_COMPUTER_MM_BOARD", 
70
    @JoinTable(name="CMP3_MM_COMPUTER_MM_BOARD", 
69
            joinColumns = @JoinColumn(name="BOARD_ID"), 
71
            joinColumns = @JoinColumn(name="BOARD_ID"), 
70
            inverseJoinColumns = @JoinColumn(name="COMPUTER_ID"))*/   
72
            inverseJoinColumns = @JoinColumn(name="COMPUTER_ID"))   
71
    private Computer computer;
73
    private Computer computer;
72
    
74
    
73
    public Board() {}
75
    public Board() {}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Manufacturer.java (-1 / +5 lines)
Lines 37-42 Link Here
37
@Entity(name="ManufacturerMetamodel")
37
@Entity(name="ManufacturerMetamodel")
38
@Table(name="CMP3_MM_MANUF")
38
@Table(name="CMP3_MM_MANUF")
39
public class Manufacturer extends Corporation implements java.io.Serializable{
39
public class Manufacturer extends Corporation implements java.io.Serializable{
40
    private static final long serialVersionUID = 5796354087505114955L;
41
40
    @Version
42
    @Version
41
    @Column(name="MANUF_VERSION")
43
    @Column(name="MANUF_VERSION")
42
    private int version;
44
    private int version;
Lines 114-120 Link Here
114
    
116
    
115
    // Define static types
117
    // Define static types
116
    
118
    
117
    public Manufacturer() {}
119
    public Manufacturer() {
120
        //this.hardwareDesignersMap = new HashMap<String, HardwareDesigner>();
121
    }
118
122
119
    public int getVersion() { 
123
    public int getVersion() { 
120
        return version; 
124
        return version; 
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-949 / +380 lines)
Lines 20-40 Link Here
20
import java.lang.reflect.Field;
20
import java.lang.reflect.Field;
21
import java.lang.reflect.Member;
21
import java.lang.reflect.Member;
22
import java.math.BigInteger;
22
import java.math.BigInteger;
23
import java.util.ArrayList;
24
import java.util.Collection;
23
import java.util.Collection;
25
import java.util.HashMap;
26
import java.util.HashSet;
27
import java.util.LinkedHashSet;
28
import java.util.List;
24
import java.util.List;
29
import java.util.Map;
25
import java.util.Map;
30
import java.util.Set;
26
import java.util.Set;
31
27
32
import javax.persistence.EntityManager;
28
import javax.persistence.EntityManager;
33
import javax.persistence.EntityManagerFactory;
29
import javax.persistence.EntityManagerFactory;
34
import javax.persistence.criteria.CriteriaQuery;
35
import javax.persistence.criteria.Path;
36
import javax.persistence.criteria.CriteriaBuilder;
37
import javax.persistence.criteria.Root;
38
import javax.persistence.metamodel.Attribute;
30
import javax.persistence.metamodel.Attribute;
39
import javax.persistence.metamodel.Bindable;
31
import javax.persistence.metamodel.Bindable;
40
import javax.persistence.metamodel.CollectionAttribute;
32
import javax.persistence.metamodel.CollectionAttribute;
Lines 46-54 Link Here
46
import javax.persistence.metamodel.MapAttribute;
38
import javax.persistence.metamodel.MapAttribute;
47
import javax.persistence.metamodel.Metamodel;
39
import javax.persistence.metamodel.Metamodel;
48
import javax.persistence.metamodel.PluralAttribute;
40
import javax.persistence.metamodel.PluralAttribute;
41
import javax.persistence.metamodel.SetAttribute;
49
import javax.persistence.metamodel.SingularAttribute;
42
import javax.persistence.metamodel.SingularAttribute;
50
import javax.persistence.metamodel.Type;
43
import javax.persistence.metamodel.Type;
51
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
44
import javax.persistence.metamodel.Attribute.PersistentAttributeType;
45
import javax.persistence.metamodel.PluralAttribute.CollectionType;
52
import javax.persistence.metamodel.Type.PersistenceType;
46
import javax.persistence.metamodel.Type.PersistenceType;
53
47
54
import junit.framework.Test;
48
import junit.framework.Test;
Lines 79-87 Link Here
79
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory;
73
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory;
80
import org.eclipse.persistence.testing.models.jpa.metamodel.Person;
74
import org.eclipse.persistence.testing.models.jpa.metamodel.Person;
81
import org.eclipse.persistence.testing.models.jpa.metamodel.Processor;
75
import org.eclipse.persistence.testing.models.jpa.metamodel.Processor;
82
import org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner;
83
import org.eclipse.persistence.testing.models.jpa.metamodel.User;
84
import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor;
85
76
86
/**
77
/**
87
 * Disclaimer:
78
 * Disclaimer:
Lines 133-147 Link Here
133
124
134
    public static Test suite() {
125
    public static Test suite() {
135
        TestSuite suite = new TestSuite("MetamodelMetamodelTest");
126
        TestSuite suite = new TestSuite("MetamodelMetamodelTest");
136
        // Test has been expanded by interface function below
137
        //suite.addTest(new MetamodelMetamodelTest("test_MetamodelFullImplementation"));
138
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_BASIC_Method"));
127
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_BASIC_Method"));
139
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_EMBEDDED_Method"));
128
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_EMBEDDED_Method"));
140
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ONE_TO_ONE_Method"));
129
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ONE_TO_ONE_Method"));
141
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ONE_TO_MANY_Method"));
130
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ONE_TO_MANY_Method"));
142
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_MANY_TO_MANY_Method"));
131
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_MANY_TO_MANY_Method"));
143
        // TODO: currently our MANY_TO_ONE is treated as a ONE_TO_ONE - we need an alternate way of getting m:1 state        
132
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_MANY_TO_ONE_Method"));
144
        //suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_MANY_TO_ONE_Method"));
145
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ELEMENT_COLLECTION_Method"));        
133
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getPersistentAttributeType_ELEMENT_COLLECTION_Method"));        
146
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getName_Method"));
134
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getName_Method"));
147
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getDeclaringType_Method"));
135
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_getDeclaringType_Method"));
Lines 154-159 Link Here
154
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isAssociation_on_Singular_Method"));
142
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isAssociation_on_Singular_Method"));
155
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isCollection_false_Method"));
143
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isCollection_false_Method"));
156
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isCollection_true_Method"));
144
        suite.addTest(new MetamodelMetamodelTest("testAttribute_Interface_isCollection_true_Method"));
145
        
157
        suite.addTest(new MetamodelMetamodelTest("testBasicType_Interface"));
146
        suite.addTest(new MetamodelMetamodelTest("testBasicType_Interface"));
158
        suite.addTest(new MetamodelMetamodelTest("testBindable_Interface_getBindableType_Method"));
147
        suite.addTest(new MetamodelMetamodelTest("testBindable_Interface_getBindableType_Method"));
159
        suite.addTest(new MetamodelMetamodelTest("testBindable_Interface_getBindableJavaType_Method"));
148
        suite.addTest(new MetamodelMetamodelTest("testBindable_Interface_getBindableJavaType_Method"));
Lines 173-179 Link Here
173
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getDeclaredId_variant_execution_attribute_is_not_declared_at_all"));
162
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getDeclaredId_variant_execution_attribute_is_not_declared_at_all"));
174
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getDeclaredId_normal_execution_attribute_is_declared"));
163
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getDeclaredId_normal_execution_attribute_is_declared"));
175
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getIdType_handles_possible_null_cmppolicy"));
164
        suite.addTest(new MetamodelMetamodelTest("testIdentifiableType_getIdType_handles_possible_null_cmppolicy"));
165
        
176
        suite.addTest(new MetamodelMetamodelTest("testListAttribute_Interface"));
166
        suite.addTest(new MetamodelMetamodelTest("testListAttribute_Interface"));
167
        
177
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttributes_Method"));
168
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttributes_Method"));
178
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttributes_Method"));
169
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttributes_Method"));
179
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSingularAttribute_Type_param_Method"));
170
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSingularAttribute_Type_param_Method"));
Lines 191-202 Link Here
191
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getPluralAttributes_Method"));
182
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getPluralAttributes_Method"));
192
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_internal_entity_Method"));
183
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_internal_entity_Method"));
193
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_root_entity_Method"));
184
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_root_entity_Method"));
194
        // Require test model expansion
185
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_root_mappedSuperclass_Method"));
195
        //suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredPluralAttributes_root_mappedSuperclass_Method"));        
186
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttribute_on_Entity_Method"));
196
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttribute_Method"));
187
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttribute_on_MappedSuperclass_Method"));
188
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttribute_doesNotExist_on_Entity_Method"));
189
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getAttribute_doesNotExist_on_MappedSuperclass_Method"));
197
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttribute_Method"));
190
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttribute_Method"));
198
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSingularAttribute_Method"));
191
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttribute_above_throws_iae_Method"));
199
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredSingularAttribute_Method"));
192
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredAttribute_doesNotExist_Method"));
193
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSingularAttribute_BASIC_Method"));
194
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSingularAttribute_EMBEDDED_Method"));        
195
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredSingularAttribute_on_Entity_Method"));
196
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredSingularAttribute_on_MappedSuperclass_Method"));
200
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getCollection_Method"));
197
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getCollection_Method"));
201
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredCollection_Method"));
198
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getDeclaredCollection_Method"));
202
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSet_Method"));
199
        suite.addTest(new MetamodelMetamodelTest("testManagedType_Interface_getSet_Method"));
Lines 240-275 Link Here
240
    
237
    
241
    public void setUp() {
238
    public void setUp() {
242
        super.setUp();
239
        super.setUp();
243
        // Drop all tables : Thank you Chris
244
        /*java.util.Vector v = JUnitTestCase.getServerSession("metamodel1").executeSQL("select tablename from sys.systables where tabletype='T'");
245
        for (int i=0; i<v.size(); i++){
246
            try{
247
                DatabaseRecord dr = (DatabaseRecord)v.get(i);
248
                JUnitTestCase.getServerSession().executeNonSelectingSQL("Drop table "+dr.getValues().get(0));
249
            } catch (Exception e){
250
                System.out.println(e);
251
            }
252
        }*/        
253
        /*JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_HIST_EMPLOY");
254
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_HWDES_MAP");
255
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_CORPCOMPUTER");
256
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_COMPUTER");
257
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_HWDESIGNER");
258
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_MM_MEMORY");
259
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_MM_PRO");
260
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_COMPUTER_MM_USER");
261
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_SEQ");
262
263
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_COMPUTER");
264
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_USER");
265
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_HWDESIGNER");
266
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MEMORY");
267
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_PROC");
268
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_LOCATION");
269
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD");
270
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_SWDESIGNER");
271
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF");
272
        */        
273
    }
240
    }
274
    
241
    
275
    /**
242
    /**
Lines 286-303 Link Here
286
        try {
253
        try {
287
            emf = initialize(overrideEMFCachingForTesting);
254
            emf = initialize(overrideEMFCachingForTesting);
288
            em = emf.createEntityManager();
255
            em = emf.createEntityManager();
289
            // Unset the metamodel - for repeated runs through this test
290
            // 20091016 - turn this off for production - as it is a performance hit - reenable if you wish to debug metamodel pre-processing
291
//            if(!isOnServer()) { 
292
//                ((EntityManagerFactoryImpl)emf).setMetamodel(null);
293
//            }
294
            metamodel = em.getMetamodel();
256
            metamodel = em.getMetamodel();
295
            assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
257
            assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
296
        } catch (Exception e) {
258
        } catch (Exception e) {
297
            e.printStackTrace();
259
            e.printStackTrace();
298
            if(null != em) {
260
            cleanup(em);
299
                cleanup(em);
300
            }
301
        }
261
        }
302
        return em;
262
        return em;
303
    }
263
    }
Lines 341-350 Link Here
341
                e.printStackTrace();
301
                e.printStackTrace();
342
                exceptionThrown = true;
302
                exceptionThrown = true;
343
            } finally {
303
            } finally {
304
                cleanup(em);
344
                assertFalse("An IAE exception should not occur on getIdType() here.", exceptionThrown);
305
                assertFalse("An IAE exception should not occur on getIdType() here.", exceptionThrown);
345
                if(null != em) {
346
                    cleanup(em);
347
                }
348
            }
306
            }
349
        }
307
        }
350
    }
308
    }
Lines 369-378 Link Here
369
                e.printStackTrace();
327
                e.printStackTrace();
370
                exceptionThrown = true;
328
                exceptionThrown = true;
371
            } finally {
329
            } finally {
330
                cleanup(em);
372
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
331
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
373
                if(null != em) {
374
                    cleanup(em);
375
                }
376
            }
332
            }
377
        }
333
        }
378
    }
334
    }
Lines 412-421 Link Here
412
                e.printStackTrace();
368
                e.printStackTrace();
413
                exceptionThrown = true;
369
                exceptionThrown = true;
414
            } finally {
370
            } finally {
371
                cleanup(em);
415
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
372
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
416
                if(null != em) {
417
                    cleanup(em);
418
                }
419
            }
373
            }
420
        }
374
        }
421
    }
375
    }
Lines 450-459 Link Here
450
                e.printStackTrace();
404
                e.printStackTrace();
451
                exceptionThrown = true;
405
                exceptionThrown = true;
452
            } finally {
406
            } finally {
407
                cleanup(em);
453
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
408
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
454
                if(null != em) {
455
                    cleanup(em);
456
                }
457
            }
409
            }
458
        }
410
        }
459
    }
411
    }
Lines 488-497 Link Here
488
                //e.printStackTrace();
440
                //e.printStackTrace();
489
                exceptionThrown = true;
441
                exceptionThrown = true;
490
            } finally {
442
            } finally {
443
                cleanup(em);
491
                assertTrue("non-declared attribute should throw an IAE", exceptionThrown);
444
                assertTrue("non-declared attribute should throw an IAE", exceptionThrown);
492
                if(null != em) {
493
                    cleanup(em);
494
                }
495
            }
445
            }
496
        }
446
        }
497
    }
447
    }
Lines 537-546 Link Here
537
                //e.printStackTrace();
487
                //e.printStackTrace();
538
                exceptionThrown = true;
488
                exceptionThrown = true;
539
            } finally {
489
            } finally {
490
                cleanup(em);
540
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
491
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
541
                if(null != em) {
542
                    cleanup(em);
543
                }
544
            }
492
            }
545
        }
493
        }
546
    }
494
    }
Lines 578-587 Link Here
578
                //e.printStackTrace();
526
                //e.printStackTrace();
579
                exceptionThrown = true;
527
                exceptionThrown = true;
580
            } finally {
528
            } finally {
529
                cleanup(em);
581
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
530
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
582
                if(null != em) {
583
                    cleanup(em);
584
                }
585
            }
531
            }
586
        }
532
        }
587
    }
533
    }
Lines 618-627 Link Here
618
                //e.printStackTrace();
564
                //e.printStackTrace();
619
                exceptionThrown = true;
565
                exceptionThrown = true;
620
            } finally {
566
            } finally {
567
                cleanup(em);
621
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
568
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
622
                if(null != em) {
623
                    cleanup(em);
624
                }
625
            }
569
            }
626
        }
570
        }
627
    }
571
    }
Lines 659-668 Link Here
659
                //e.printStackTrace();
603
                //e.printStackTrace();
660
                exceptionThrown = true;
604
                exceptionThrown = true;
661
            } finally {
605
            } finally {
606
                cleanup(em);
662
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
607
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
663
                if(null != em) {
664
                    cleanup(em);
665
                }
666
            }
608
            }
667
        }
609
        }
668
    }
610
    }
Lines 694-703 Link Here
694
                //e.printStackTrace();
636
                //e.printStackTrace();
695
                exceptionThrown = true;
637
                exceptionThrown = true;
696
            } finally {
638
            } finally {
639
                cleanup(em);
697
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
640
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
698
                if(null != em) {
699
                    cleanup(em);
700
                }
701
            }
641
            }
702
        }
642
        }
703
    }
643
    }
Lines 730-745 Link Here
730
                Attribute anAttribute = entityBoard_.getAttribute("computer");                
670
                Attribute anAttribute = entityBoard_.getAttribute("computer");                
731
                assertNotNull(anAttribute);
671
                assertNotNull(anAttribute);
732
                assertEquals(Computer.class, anAttribute.getJavaType());
672
                assertEquals(Computer.class, anAttribute.getJavaType());
733
                // TODO: currently our MANY_TO_ONE is treated as a ONE_TO_ONE - we need an alternate way of getting m:1 state 
673
                // Note: internally our MANY_TO_ONE is treated as a ONE_TO_ONE - although with a DB constraint 
734
                assertEquals(PersistentAttributeType.MANY_TO_ONE, anAttribute.getPersistentAttributeType());
674
                assertEquals(PersistentAttributeType.MANY_TO_ONE, anAttribute.getPersistentAttributeType());
735
            } catch (Exception e) {
675
            } catch (Exception e) {
736
                //e.printStackTrace();
676
                //e.printStackTrace();
737
                exceptionThrown = true;
677
                exceptionThrown = true;
738
            } finally {
678
            } finally {
679
                cleanup(em);
739
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
680
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
740
                if(null != em) {
741
                    cleanup(em);
742
                }
743
            }
681
            }
744
        }
682
        }
745
    }
683
    }
Lines 778-787 Link Here
778
                //e.printStackTrace();
716
                //e.printStackTrace();
779
                exceptionThrown = true;
717
                exceptionThrown = true;
780
            } finally {
718
            } finally {
719
                cleanup(em);
781
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
720
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
782
                if(null != em) {
783
                    cleanup(em);
784
                }
785
            }
721
            }
786
        }
722
        }
787
    }
723
    }
Lines 819-828 Link Here
819
                //e.printStackTrace();
755
                //e.printStackTrace();
820
                exceptionThrown = true;
756
                exceptionThrown = true;
821
            } finally {
757
            } finally {
758
                cleanup(em);
822
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
759
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
823
                if(null != em) {
824
                    cleanup(em);
825
                }
826
            }
760
            }
827
        }
761
        }
828
    }
762
    }
Lines 847-856 Link Here
847
                //e.printStackTrace();
781
                //e.printStackTrace();
848
                exceptionThrown = true;
782
                exceptionThrown = true;
849
            } finally {
783
            } finally {
784
                cleanup(em);
850
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
785
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
851
                if(null != em) {
852
                    cleanup(em);
853
                }
854
            }
786
            }
855
        }
787
        }
856
    }
788
    }
Lines 864-884 Link Here
864
                assertNotNull(em);
796
                assertNotNull(em);
865
                Metamodel metamodel = em.getMetamodel();
797
                Metamodel metamodel = em.getMetamodel();
866
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
798
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
867
799
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
800
                assertNotNull(entityManufacturer_);
801
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
802
                assertNotNull(entityHardwareDesigner_);
803
                
868
                /**
804
                /**
869
                 *  Return the managed type representing the type in which 
805
                 *  Return the managed type representing the type in which 
870
                 *  the attribute was declared.
806
                 *  the attribute was declared.
871
                 *  @return declaring type
807
                 *  @return declaring type
872
                 */
808
                 */
873
                //ManagedType<X> getDeclaringType();
809
                //ManagedType<X> getDeclaringType();
810
                
811
                // Test case
812
                Attribute anAttribute = entityManufacturer_.getDeclaredAttribute("hardwareDesignersMapUC4");
813
                ManagedType aManagedType = anAttribute.getDeclaringType();
814
                assertEquals(entityManufacturer_, aManagedType);
815
                
816
                assertNotNull(anAttribute);
817
                assertEquals(PersistentAttributeType.ONE_TO_MANY, anAttribute.getPersistentAttributeType());
874
            } catch (Exception e) {
818
            } catch (Exception e) {
875
                //e.printStackTrace();
819
                //e.printStackTrace();
876
                exceptionThrown = true;
820
                exceptionThrown = true;
877
            } finally {
821
            } finally {
822
                cleanup(em);
878
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
823
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
879
                if(null != em) {
880
                    cleanup(em);
881
                }
882
            }
824
            }
883
        }
825
        }
884
    }
826
    }
Lines 908-917 Link Here
908
                //e.printStackTrace();
850
                //e.printStackTrace();
909
                exceptionThrown = true;
851
                exceptionThrown = true;
910
            } finally {
852
            } finally {
853
                cleanup(em);
911
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
854
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
912
                if(null != em) {
913
                    cleanup(em);
914
                }
915
            }
855
            }
916
        }
856
        }
917
    }
857
    }
Lines 941-950 Link Here
941
                //e.printStackTrace();
881
                //e.printStackTrace();
942
                exceptionThrown = true;
882
                exceptionThrown = true;
943
            } finally {
883
            } finally {
884
                cleanup(em);
944
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
885
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
945
                if(null != em) {
946
                    cleanup(em);
947
                }
948
            }
886
            }
949
        }
887
        }
950
    }
888
    }
Lines 983-992 Link Here
983
                //e.printStackTrace();
921
                //e.printStackTrace();
984
                exceptionThrown = true;
922
                exceptionThrown = true;
985
            } finally {
923
            } finally {
924
                cleanup(em);
986
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
925
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
987
                if(null != em) {
988
                    cleanup(em);
989
                }
990
            }
926
            }
991
        }
927
        }
992
    }
928
    }
Lines 1025-1034 Link Here
1025
                //e.printStackTrace();
961
                //e.printStackTrace();
1026
                exceptionThrown = true;
962
                exceptionThrown = true;
1027
            } finally {
963
            } finally {
964
                cleanup(em);
1028
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
965
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1029
                if(null != em) {
1030
                    cleanup(em);
1031
                }
1032
            }
966
            }
1033
        }
967
        }
1034
    }
968
    }
Lines 1065-1074 Link Here
1065
                //e.printStackTrace();
999
                //e.printStackTrace();
1066
                exceptionThrown = true;
1000
                exceptionThrown = true;
1067
            } finally {
1001
            } finally {
1002
                cleanup(em);
1068
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1003
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1069
                if(null != em) {
1070
                    cleanup(em);
1071
                }
1072
            }
1004
            }
1073
        }
1005
        }
1074
    }
1006
    }
Lines 1101-1110 Link Here
1101
                //e.printStackTrace();
1033
                //e.printStackTrace();
1102
                exceptionThrown = true;
1034
                exceptionThrown = true;
1103
            } finally {
1035
            } finally {
1036
                cleanup(em);
1104
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1037
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1105
                if(null != em) {
1106
                    cleanup(em);
1107
                }
1108
            }
1038
            }
1109
        }
1039
        }
1110
    }
1040
    }
Lines 1139-1148 Link Here
1139
                //e.printStackTrace();
1069
                //e.printStackTrace();
1140
                exceptionThrown = true;
1070
                exceptionThrown = true;
1141
            } finally {
1071
            } finally {
1072
                cleanup(em);
1142
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1073
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1143
                if(null != em) {
1144
                    cleanup(em);
1145
                }
1146
            }
1074
            }
1147
        }
1075
        }
1148
    }
1076
    }
Lines 1187-1196 Link Here
1187
                //e.printStackTrace();
1115
                //e.printStackTrace();
1188
                exceptionThrown = true;
1116
                exceptionThrown = true;
1189
            } finally {
1117
            } finally {
1118
                cleanup(em);
1190
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1119
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1191
                if(null != em) {
1192
                    cleanup(em);
1193
                }
1194
            }
1120
            }
1195
        }
1121
        }
1196
    }
1122
    }
Lines 1223-1232 Link Here
1223
                //e.printStackTrace();
1149
                //e.printStackTrace();
1224
                exceptionThrown = true;
1150
                exceptionThrown = true;
1225
            } finally {
1151
            } finally {
1152
                cleanup(em);
1226
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1153
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1227
                if(null != em) {
1228
                    cleanup(em);
1229
                }
1230
            }
1154
            }
1231
        }
1155
        }
1232
    }
1156
    }
Lines 1252-1261 Link Here
1252
                //e.printStackTrace();
1176
                //e.printStackTrace();
1253
                exceptionThrown = true;
1177
                exceptionThrown = true;
1254
            } finally {
1178
            } finally {
1179
                cleanup(em);
1255
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1180
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1256
                if(null != em) {
1257
                    cleanup(em);
1258
                }
1259
            }
1181
            }
1260
        }
1182
        }
1261
    }
1183
    }
Lines 1297-1306 Link Here
1297
                //e.printStackTrace();
1219
                //e.printStackTrace();
1298
                exceptionThrown = true;
1220
                exceptionThrown = true;
1299
            } finally {
1221
            } finally {
1222
                cleanup(em);
1300
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1223
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1301
                if(null != em) {
1302
                    cleanup(em);
1303
                }
1304
            }
1224
            }
1305
        }
1225
        }
1306
    }
1226
    }
Lines 1351-1360 Link Here
1351
                //e.printStackTrace();
1271
                //e.printStackTrace();
1352
                exceptionThrown = true;
1272
                exceptionThrown = true;
1353
            } finally {
1273
            } finally {
1274
                cleanup(em);
1354
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1275
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1355
                if(null != em) {
1356
                    cleanup(em);
1357
                }
1358
            }
1276
            }
1359
        }
1277
        }
1360
    }    
1278
    }    
Lines 1381-1390 Link Here
1381
                //e.printStackTrace();
1299
                //e.printStackTrace();
1382
                exceptionThrown = true;
1300
                exceptionThrown = true;
1383
            } finally {
1301
            } finally {
1302
                cleanup(em);
1384
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1303
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1385
                if(null != em) {
1386
                    cleanup(em);
1387
                }
1388
            }
1304
            }
1389
        }
1305
        }
1390
    }
1306
    }
Lines 1404-1423 Link Here
1404
                assertNotNull(entityHardwareDesigner_);
1320
                assertNotNull(entityHardwareDesigner_);
1405
                
1321
                
1406
                // Actual Test Case
1322
                // Actual Test Case
1407
                // exercise EntityTypeImpl
1408
                //System.out.println("_entityManufacturer.getBindableType(): " + entityManufacturer.getBindableType());
1409
                //System.out.println("_entityManufacturer.getCollections(): " + entityManufacturer.getCollections());
1410
                //System.out.println("_entityManufacturer.getDeclaredCollection(type): " + entityManufacturer.getDeclaredCollection("computers", Computer.class));
1411
                //System.out.println("_entityManufacturer.getDeclaredAttribute(type): " + entityManufacturer.getDeclaredSingularAttribute("name", String.class));            
1412
                //System.out.println("_entityManufacturer.getDeclaredAttribute(): " + entityManufacturer.getDeclaredAttribute("name"));
1413
                //System.out.println("_entityManufacturer.getDeclaredAttributes(): " + entityManufacturer.getDeclaredAttributes());
1414
                //System.out.println("_entityManufacturer.getDeclaredId(type): " + entityManufacturer.getDeclaredId(manufacturer.getId().getClass()));
1415
                //System.out.println("_entityManufacturer.getIdType(): " + entityManufacturer.getIdType());
1416
                //System.out.println("_entityManufacturer.getJavaType(): " + entityManufacturer.getJavaType());
1417
                //System.out.println("_entityManufacturer.getName(): " + entityManufacturer.getName());
1418
                //System.out.println("_entityManufacturer.getSupertype(): " + entityManufacturer.getSupertype());
1419
                //entityManufacturer.getVersion(manufacturer.getVersion());
1420
1421
                /**
1323
                /**
1422
                 *  Return the entity name.
1324
                 *  Return the entity name.
1423
                 *  @return entity name
1325
                 *  @return entity name
Lines 1447-1456 Link Here
1447
                //e.printStackTrace();
1349
                //e.printStackTrace();
1448
                exceptionThrown = true;
1350
                exceptionThrown = true;
1449
            } finally {
1351
            } finally {
1352
                cleanup(em);
1450
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1353
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1451
                if(null != em) {
1452
                    cleanup(em);
1453
                }
1454
            }
1354
            }
1455
        }
1355
        }
1456
    }
1356
    }
Lines 1491-1500 Link Here
1491
                //e.printStackTrace();
1391
                //e.printStackTrace();
1492
                expectedIAExceptionThrown = true;
1392
                expectedIAExceptionThrown = true;
1493
            } finally {
1393
            } finally {
1394
                cleanup(em);
1494
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1395
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1495
                if(null != em) {
1496
                    cleanup(em);
1497
                }
1498
            }
1396
            }
1499
        }
1397
        }
1500
    }
1398
    }
Lines 1538-1547 Link Here
1538
                //e.printStackTrace();
1436
                //e.printStackTrace();
1539
                expectedIAExceptionThrown = true;
1437
                expectedIAExceptionThrown = true;
1540
            } finally {
1438
            } finally {
1439
                cleanup(em);
1541
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1440
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1542
                if(null != em) {
1543
                    cleanup(em);
1544
                }
1545
            }
1441
            }
1546
        }
1442
        }
1547
    }
1443
    }
Lines 1585-1594 Link Here
1585
                //e.printStackTrace();
1481
                //e.printStackTrace();
1586
                expectedIAExceptionThrown = true;
1482
                expectedIAExceptionThrown = true;
1587
            } finally {
1483
            } finally {
1484
                cleanup(em);
1588
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1485
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1589
                if(null != em) {
1590
                    cleanup(em);
1591
                }
1592
            }
1486
            }
1593
        }
1487
        }
1594
    }
1488
    }
Lines 1607-1631 Link Here
1607
1501
1608
                // Actual Test Case
1502
                // Actual Test Case
1609
                /**
1503
                /**
1610
                 *  Return the attribute that corresponds to the id attribute 
1611
                 *  declared by the entity or mapped superclass.
1612
                 *  @param type  the type of the represented declared id attribute
1613
                 *  @return declared id attribute
1614
                 *  @throws IllegalArgumentException if id attribute of the given
1615
                 *          type is not declared in the identifiable type or if
1616
                 *          the identifiable type has an id class
1617
                 */
1618
                //<Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type);
1619
                // Not declared  - invalid
1620
//                assertNotNull(aManufacturerType.getDeclaredId(Integer.class));
1621
                // declared and valid
1622
                
1623
                //*********************************************/
1624
                // Require a version on a MappedSuperclass
1625
                
1626
//                assertNotNull(msPerson1_.getDeclaredId(Integer.class));
1627
1628
                /**
1629
                 *  Return the attribute that corresponds to the version 
1504
                 *  Return the attribute that corresponds to the version 
1630
                 *  attribute declared by the entity or mapped superclass.
1505
                 *  attribute declared by the entity or mapped superclass.
1631
                 *  @param type  the type of the represented declared version 
1506
                 *  @param type  the type of the represented declared version 
Lines 1648-1657 Link Here
1648
                //e.printStackTrace();
1523
                //e.printStackTrace();
1649
                expectedIAExceptionThrown = true;
1524
                expectedIAExceptionThrown = true;
1650
            } finally {
1525
            } finally {
1526
                cleanup(em);
1651
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1527
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1652
                if(null != em) {
1653
                    cleanup(em);
1654
                }
1655
            }
1528
            }
1656
        }
1529
        }
1657
    }
1530
    }
Lines 1726-1735 Link Here
1726
                //e.printStackTrace();
1599
                //e.printStackTrace();
1727
                expectedIAExceptionThrown = true;
1600
                expectedIAExceptionThrown = true;
1728
            } finally {
1601
            } finally {
1602
                cleanup(em);
1729
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1603
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1730
                if(null != em) {
1731
                    cleanup(em);
1732
                }
1733
            }
1604
            }
1734
        }
1605
        }
1735
    }
1606
    }
Lines 1802-1811 Link Here
1802
                //e.printStackTrace();
1673
                //e.printStackTrace();
1803
                expectedIAExceptionThrown = true;
1674
                expectedIAExceptionThrown = true;
1804
            } finally {
1675
            } finally {
1676
                cleanup(em);
1805
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1677
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1806
                if(null != em) {
1807
                    cleanup(em);
1808
                }
1809
            }
1678
            }
1810
        }
1679
        }
1811
    }
1680
    }
Lines 1836-1845 Link Here
1836
                //e.printStackTrace();
1705
                //e.printStackTrace();
1837
                expectedIAExceptionThrown = true;
1706
                expectedIAExceptionThrown = true;
1838
            } finally {
1707
            } finally {
1708
                cleanup(em);
1839
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1709
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1840
                if(null != em) {
1841
                    cleanup(em);
1842
                }
1843
            }
1710
            }
1844
        }
1711
        }
1845
    }
1712
    }
Lines 1885-1894 Link Here
1885
                //e.printStackTrace();
1752
                //e.printStackTrace();
1886
                expectedIAExceptionThrown = true;
1753
                expectedIAExceptionThrown = true;
1887
            } finally {
1754
            } finally {
1755
                cleanup(em);
1888
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1756
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1889
                if(null != em) {
1890
                    cleanup(em);
1891
                }
1892
            }
1757
            }
1893
        }
1758
        }
1894
    }
1759
    }
Lines 1976-1995 Link Here
1976
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
1841
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
1977
                assertNotNull(msCorporation_);
1842
                assertNotNull(msCorporation_);
1978
                
1843
                
1979
                // replaced by testIdentifiableType_getIdType_handles_possible_null_cmppolicy()
1980
                /*try {
1981
                    personIdType = msPerson_.getIdType();
1982
                } catch (IllegalArgumentException iae) {
1983
                    // expecting no exception
1984
                    iae.printStackTrace();
1985
                    expectedIAExceptionThrown = true;            
1986
                }
1987
                assertFalse(expectedIAExceptionThrown);
1988
                assertNotNull(personIdType);
1989
                assertEquals(PersistenceType.BASIC, personIdType.getPersistenceType());
1990
                assertEquals(Integer.class, personIdType.getJavaType());
1991
                */
1992
                
1993
                // Verify all types (entities, embeddables, mappedsuperclasses and basic)
1844
                // Verify all types (entities, embeddables, mappedsuperclasses and basic)
1994
                try {
1845
                try {
1995
                    // get all 21 types (a non spec function - for testing introspection)
1846
                    // get all 21 types (a non spec function - for testing introspection)
Lines 2000-2016 Link Here
2000
                } catch (Exception e) {
1851
                } catch (Exception e) {
2001
                    e.printStackTrace();
1852
                    e.printStackTrace();
2002
                }
1853
                }
2003
                
2004
                
2005
                
2006
            } catch (Exception e) {
1854
            } catch (Exception e) {
2007
                //e.printStackTrace();
1855
                //e.printStackTrace();
2008
                expectedIAExceptionThrown = true;
1856
                expectedIAExceptionThrown = true;
2009
            } finally {
1857
            } finally {
1858
                cleanup(em);
2010
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
1859
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
2011
                if(null != em) {
2012
                    cleanup(em);
2013
                }
2014
            }
1860
            }
2015
        }
1861
        }
2016
    }
1862
    }
Lines 2031-2040 Link Here
2031
                //e.printStackTrace();
1877
                //e.printStackTrace();
2032
                exceptionThrown = true;
1878
                exceptionThrown = true;
2033
            } finally {
1879
            } finally {
1880
                cleanup(em);
2034
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
1881
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
2035
                if(null != em) {
2036
                    cleanup(em);
2037
                }
2038
            }
1882
            }
2039
        }
1883
        }
2040
    }
1884
    }
Lines 2190-2199 Link Here
2190
                assertNotNull(entityManufacturer_.getAttribute("aChar"));
2034
                assertNotNull(entityManufacturer_.getAttribute("aChar"));
2191
                assertTrue(entityManufacturer_.getAttribute("aChar").getPersistentAttributeType().equals(PersistentAttributeType.BASIC));
2035
                assertTrue(entityManufacturer_.getAttribute("aChar").getPersistentAttributeType().equals(PersistentAttributeType.BASIC));
2192
                assertEquals(char.class, entityManufacturer_.getAttribute("aChar").getJavaType());
2036
                assertEquals(char.class, entityManufacturer_.getAttribute("aChar").getJavaType());
2193
2194
                
2037
                
2195
2196
                
2197
                /**
2038
                /**
2198
                 *  Return the attributes declared by the managed type.
2039
                 *  Return the attributes declared by the managed type.
2199
                 *  Testing for Design Issue 52:
2040
                 *  Testing for Design Issue 52:
Lines 2256-2261 Link Here
2256
                    // name is declared 1 level above but is not visible in a ms-->ms hierarchy
2097
                    // name is declared 1 level above but is not visible in a ms-->ms hierarchy
2257
                    //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("name"))); //
2098
                    //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("name"))); //
2258
                    // corporateComputers is declared at this level
2099
                    // corporateComputers is declared at this level
2100
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
2259
                    assertTrue(declaredAttributesSetForCorporation.contains(msCorporation_.getAttribute("corporateComputers"))); //
2101
                    assertTrue(declaredAttributesSetForCorporation.contains(msCorporation_.getAttribute("corporateComputers"))); //
2260
                    // historicalEmployers is declared 1 level above but is not visible in a ms-->ms hierarchy
2102
                    // historicalEmployers is declared 1 level above but is not visible in a ms-->ms hierarchy
2261
                    //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("historicalEmployers"))); //                
2103
                    //assertFalse(declaredAttributesSetForCorporation.contains(msCorporation.getAttribute("historicalEmployers"))); //                
Lines 2276-2286 Link Here
2276
                    expectedIAExceptionThrown = true;            
2118
                    expectedIAExceptionThrown = true;            
2277
                }
2119
                }
2278
                assertFalse(expectedIAExceptionThrown);            
2120
                assertFalse(expectedIAExceptionThrown);            
2279
               
2280
                
2121
                
2281
                // Test Entity-->Entity hierarchy
2122
                // Test Entity-->Entity hierarchy
2282
                
2283
2284
                /**
2123
                /**
2285
                 *  Return the single-valued attribute of the managed 
2124
                 *  Return the single-valued attribute of the managed 
2286
                 *  type that corresponds to the specified name and Java type 
2125
                 *  type that corresponds to the specified name and Java type 
Lines 2697-2702 Link Here
2697
                expectedIAExceptionThrown = false;            
2536
                expectedIAExceptionThrown = false;            
2698
                try {
2537
                try {
2699
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2538
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2539
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
2700
                    // UC4 - the attribute is on the immediate superclass and is the correct COLLECTION - we still get an IAE
2540
                    // UC4 - the attribute is on the immediate superclass and is the correct COLLECTION - we still get an IAE
2701
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
2541
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
2702
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
2542
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
Lines 2779-2784 Link Here
2779
                try {
2619
                try {
2780
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2620
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2781
                    // UC4 - the attribute is on the immediate superclass
2621
                    // UC4 - the attribute is on the immediate superclass
2622
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
2782
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
2623
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
2783
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
2624
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
2784
                } catch (IllegalArgumentException iae) {
2625
                } catch (IllegalArgumentException iae) {
Lines 2880-2885 Link Here
2880
                try {
2721
                try {
2881
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2722
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2882
                    // UC4 - the attribute is on the immediate superclass
2723
                    // UC4 - the attribute is on the immediate superclass
2724
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
2883
                    Attribute<Manufacturer, ?> anAttribute = 
2725
                    Attribute<Manufacturer, ?> anAttribute = 
2884
                        entityManufacturer_.getDeclaredAttribute("corporateComputers");//, entityComputer.getJavaType());
2726
                        entityManufacturer_.getDeclaredAttribute("corporateComputers");//, entityComputer.getJavaType());
2885
                } catch (IllegalArgumentException iae) {
2727
                } catch (IllegalArgumentException iae) {
Lines 2934-2940 Link Here
2934
                try {
2776
                try {
2935
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2777
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2936
                    // the attribute is on the class
2778
                    // the attribute is on the class
2937
                    IdentifiableType corporation = entityManufacturer_.getSupertype();                
2779
                    IdentifiableType corporation = entityManufacturer_.getSupertype();
2780
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
2938
                    aCollectionAttribute2 = corporation.getDeclaredAttribute("corporateComputers");//, entityComputer.getJavaType());
2781
                    aCollectionAttribute2 = corporation.getDeclaredAttribute("corporateComputers");//, entityComputer.getJavaType());
2939
                } catch (IllegalArgumentException iae) {
2782
                } catch (IllegalArgumentException iae) {
2940
                    // expecting
2783
                    // expecting
Lines 3037-3042 Link Here
3037
                expectedIAExceptionThrown = false;            
2880
                expectedIAExceptionThrown = false;            
3038
                try {
2881
                try {
3039
                    // UC4 - the attribute is on the immediate superclass
2882
                    // UC4 - the attribute is on the immediate superclass
2883
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
3040
                    CollectionAttribute<Manufacturer, ?> anAttribute = 
2884
                    CollectionAttribute<Manufacturer, ?> anAttribute = 
3041
                        entityManufacturer_.getDeclaredCollection("corporateComputers");
2885
                        entityManufacturer_.getDeclaredCollection("corporateComputers");
3042
                } catch (IllegalArgumentException iae) {
2886
                } catch (IllegalArgumentException iae) {
Lines 3050-3055 Link Here
3050
2894
3051
                expectedIAExceptionThrown = false;
2895
                expectedIAExceptionThrown = false;
3052
                try {
2896
                try {
2897
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
3053
                    CollectionAttribute<Corporation, ?> anAttribute = 
2898
                    CollectionAttribute<Corporation, ?> anAttribute = 
3054
                        msCorporation_.getDeclaredCollection("corporateComputers");
2899
                        msCorporation_.getDeclaredCollection("corporateComputers");
3055
                } catch (IllegalArgumentException iae) {
2900
                } catch (IllegalArgumentException iae) {
Lines 3064-3069 Link Here
3064
                try {
2909
                try {
3065
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
2910
                    //<E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType);
3066
                    // UC4 - the attribute is on the immediate superclass
2911
                    // UC4 - the attribute is on the immediate superclass
2912
                    // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                    
3067
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
2913
                    CollectionAttribute<Manufacturer, Computer> anAttribute = 
3068
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
2914
                        entityManufacturer_.getDeclaredCollection("corporateComputers", entityComputer_.getJavaType());
3069
                } catch (IllegalArgumentException iae) {
2915
                } catch (IllegalArgumentException iae) {
Lines 3110-3119 Link Here
3110
                e.printStackTrace();
2956
                e.printStackTrace();
3111
                expectedIAExceptionThrown = true;
2957
                expectedIAExceptionThrown = true;
3112
            } finally {
2958
            } finally {
2959
                cleanup(em);
3113
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
2960
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3114
                if(null != em) {
3115
                    cleanup(em);
3116
                }
3117
            }
2961
            }
3118
        }
2962
        }
3119
    }
2963
    }
Lines 3144-3153 Link Here
3144
                e.printStackTrace();
2988
                e.printStackTrace();
3145
                expectedIAExceptionThrown = true;
2989
                expectedIAExceptionThrown = true;
3146
            } finally {
2990
            } finally {
2991
                cleanup(em);
3147
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
2992
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3148
                if(null != em) {
3149
                    cleanup(em);
3150
                }
3151
            }
2993
            }
3152
        }
2994
        }
3153
    }
2995
    }
Lines 3178-3187 Link Here
3178
                e.printStackTrace();
3020
                e.printStackTrace();
3179
                expectedIAExceptionThrown = true;
3021
                expectedIAExceptionThrown = true;
3180
            } finally {
3022
            } finally {
3023
                cleanup(em);
3181
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3024
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3182
                if(null != em) {
3183
                    cleanup(em);
3184
                }
3185
            }
3025
            }
3186
        }
3026
        }
3187
    }
3027
    }
Lines 3212-3221 Link Here
3212
                e.printStackTrace();
3052
                e.printStackTrace();
3213
                expectedIAExceptionThrown = true;
3053
                expectedIAExceptionThrown = true;
3214
            } finally {
3054
            } finally {
3055
                cleanup(em);
3215
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3056
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3216
                if(null != em) {
3217
                    cleanup(em);
3218
                }
3219
            }
3057
            }
3220
        }
3058
        }
3221
    }
3059
    }
Lines 3246-3255 Link Here
3246
                e.printStackTrace();
3084
                e.printStackTrace();
3247
                expectedIAExceptionThrown = true;
3085
                expectedIAExceptionThrown = true;
3248
            } finally {
3086
            } finally {
3087
                cleanup(em);
3249
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3088
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3250
                if(null != em) {
3251
                    cleanup(em);
3252
                }
3253
            }
3089
            }
3254
        }
3090
        }
3255
    }
3091
    }
Lines 3280-3289 Link Here
3280
                e.printStackTrace();
3116
                e.printStackTrace();
3281
                expectedIAExceptionThrown = true;
3117
                expectedIAExceptionThrown = true;
3282
            } finally {
3118
            } finally {
3119
                cleanup(em);
3283
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3120
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3284
                if(null != em) {
3285
                    cleanup(em);
3286
                }
3287
            }
3121
            }
3288
        }
3122
        }
3289
    }
3123
    }
Lines 3314-3323 Link Here
3314
                e.printStackTrace();
3148
                e.printStackTrace();
3315
                expectedIAExceptionThrown = true;
3149
                expectedIAExceptionThrown = true;
3316
            } finally {
3150
            } finally {
3151
                cleanup(em);
3317
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3152
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3318
                if(null != em) {
3319
                    cleanup(em);
3320
                }
3321
            }
3153
            }
3322
        }
3154
        }
3323
    }
3155
    }
Lines 3348-3357 Link Here
3348
                e.printStackTrace();
3180
                e.printStackTrace();
3349
                expectedIAExceptionThrown = true;
3181
                expectedIAExceptionThrown = true;
3350
            } finally {
3182
            } finally {
3183
                cleanup(em);
3351
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3184
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3352
                if(null != em) {
3353
                    cleanup(em);
3354
                }
3355
            }
3185
            }
3356
        }
3186
        }
3357
    }
3187
    }
Lines 3382-3391 Link Here
3382
                e.printStackTrace();
3212
                e.printStackTrace();
3383
                expectedIAExceptionThrown = true;
3213
                expectedIAExceptionThrown = true;
3384
            } finally {
3214
            } finally {
3215
                cleanup(em);
3385
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3216
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3386
                if(null != em) {
3387
                    cleanup(em);
3388
                }
3389
            }
3217
            }
3390
        }
3218
        }
3391
    }
3219
    }
Lines 3416-3425 Link Here
3416
                e.printStackTrace();
3244
                e.printStackTrace();
3417
                expectedIAExceptionThrown = true;
3245
                expectedIAExceptionThrown = true;
3418
            } finally {
3246
            } finally {
3247
                cleanup(em);
3419
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3248
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3420
                if(null != em) {
3421
                    cleanup(em);
3422
                }
3423
            }
3249
            }
3424
        }
3250
        }
3425
    }
3251
    }
Lines 3450-3459 Link Here
3450
                e.printStackTrace();
3276
                e.printStackTrace();
3451
                expectedIAExceptionThrown = true;
3277
                expectedIAExceptionThrown = true;
3452
            } finally {
3278
            } finally {
3279
                cleanup(em);
3453
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3280
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3454
                if(null != em) {
3455
                    cleanup(em);
3456
                }
3457
            }
3281
            }
3458
        }
3282
        }
3459
    }
3283
    }
Lines 3484-3493 Link Here
3484
                e.printStackTrace();
3308
                e.printStackTrace();
3485
                expectedIAExceptionThrown = true;
3309
                expectedIAExceptionThrown = true;
3486
            } finally {
3310
            } finally {
3311
                cleanup(em);
3487
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3312
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3488
                if(null != em) {
3489
                    cleanup(em);
3490
                }
3491
            }
3313
            }
3492
        }
3314
        }
3493
    }
3315
    }
Lines 3518-3527 Link Here
3518
                e.printStackTrace();
3340
                e.printStackTrace();
3519
                expectedIAExceptionThrown = true;
3341
                expectedIAExceptionThrown = true;
3520
            } finally {
3342
            } finally {
3343
                cleanup(em);
3521
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3344
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3522
                if(null != em) {
3523
                    cleanup(em);
3524
                }
3525
            }
3345
            }
3526
        }
3346
        }
3527
    }
3347
    }
Lines 3552-3561 Link Here
3552
                e.printStackTrace();
3372
                e.printStackTrace();
3553
                expectedIAExceptionThrown = true;
3373
                expectedIAExceptionThrown = true;
3554
            } finally {
3374
            } finally {
3375
                cleanup(em);
3555
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3376
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3556
                if(null != em) {
3557
                    cleanup(em);
3558
                }
3559
            }
3377
            }
3560
        }
3378
        }
3561
    }
3379
    }
Lines 3586-3595 Link Here
3586
                e.printStackTrace();
3404
                e.printStackTrace();
3587
                expectedIAExceptionThrown = true;
3405
                expectedIAExceptionThrown = true;
3588
            } finally {
3406
            } finally {
3407
                cleanup(em);
3589
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3408
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3590
                if(null != em) {
3591
                    cleanup(em);
3592
                }
3593
            }
3409
            }
3594
        }
3410
        }
3595
    }
3411
    }
Lines 3633-3642 Link Here
3633
                e.printStackTrace();
3449
                e.printStackTrace();
3634
                expectedIAExceptionThrown = true;
3450
                expectedIAExceptionThrown = true;
3635
            } finally {
3451
            } finally {
3452
                cleanup(em);
3636
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3453
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3637
                if(null != em) {
3638
                    cleanup(em);
3639
                }
3640
            }
3454
            }
3641
        }
3455
        }
3642
    }
3456
    }
Lines 3655-3661 Link Here
3655
                // This also tests getCollections()
3469
                // This also tests getCollections()
3656
                expectedIAExceptionThrown = false;            
3470
                expectedIAExceptionThrown = false;            
3657
                try {
3471
                try {
3658
                    Set<PluralAttribute<Computer, ?, ?>> collections = 
3472
                    Set<PluralAttribute<Computer, ?, ?>> collections =
3659
                        entityComputer_.getDeclaredPluralAttributes();
3473
                        entityComputer_.getDeclaredPluralAttributes();
3660
                    assertNotNull(collections);
3474
                    assertNotNull(collections);
3661
                    
3475
                    
Lines 3669-3682 Link Here
3669
                e.printStackTrace();
3483
                e.printStackTrace();
3670
                expectedIAExceptionThrown = true;
3484
                expectedIAExceptionThrown = true;
3671
            } finally {
3485
            } finally {
3486
                cleanup(em);
3672
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3487
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3673
                if(null != em) {
3674
                    cleanup(em);
3675
                }
3676
            }
3488
            }
3677
        }
3489
        }
3678
    }
3490
    }
3679
3491
3492
    // Requires test model expansion before enabling test
3680
    public void testManagedType_Interface_getDeclaredPluralAttributes_root_mappedSuperclass_Method() {
3493
    public void testManagedType_Interface_getDeclaredPluralAttributes_root_mappedSuperclass_Method() {
3681
        if(!this.isJPA10()) {
3494
        if(!this.isJPA10()) {
3682
            EntityManager em = null;
3495
            EntityManager em = null;
Lines 3693-3721 Link Here
3693
3506
3694
                // This also tests getCollections()
3507
                // This also tests getCollections()
3695
                expectedIAExceptionThrown = false;
3508
                expectedIAExceptionThrown = false;
3696
                // Not implemented yet - we require a plural declared attribute on a root mappedSuperclass
3509
                // historicalComputers is defined as a plural declared attribute on a root mappedSuperclass
3697
/*                try {
3510
                Set<PluralAttribute<Person, ?, ?>> collections = 
3698
                    Set<PluralAttribute<Manufacturer, ?, ?>> collections = 
3511
                    msPerson_.getDeclaredPluralAttributes();
3699
                        entityManufacturer_.getDeclaredPluralAttributes();
3700
                } catch (IllegalArgumentException iae) {
3701
                    iae.printStackTrace();
3702
                    expectedIAExceptionThrown = true;            
3703
                }
3704
                assertFalse(expectedIAExceptionThrown);            
3705
*/
3706
            } catch (Exception e) {
3512
            } catch (Exception e) {
3707
                e.printStackTrace();
3513
                e.printStackTrace();
3708
                expectedIAExceptionThrown = true;
3514
                expectedIAExceptionThrown = true;
3709
            } finally {
3515
            } finally {
3516
                cleanup(em);
3710
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3517
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3711
                if(null != em) {
3712
                    cleanup(em);
3713
                }
3714
            }
3518
            }
3715
        }
3519
        }
3716
    }
3520
    }
3717
    
3521
    
3718
    public void testManagedType_Interface_getAttribute_Method() {
3522
    public void testManagedType_Interface_getAttribute_on_Entity_Method() {
3719
        if(!this.isJPA10()) {
3523
        if(!this.isJPA10()) {
3720
            EntityManager em = null;
3524
            EntityManager em = null;
3721
            boolean expectedIAExceptionThrown = false;
3525
            boolean expectedIAExceptionThrown = false;
Lines 3726-3750 Link Here
3726
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3530
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3727
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3531
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3728
                assertNotNull(entityManufacturer_);
3532
                assertNotNull(entityManufacturer_);
3729
                MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl)metamodel.managedType(Person.class);
3533
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3730
                assertNotNull(msPerson_);
3534
                assertNotNull(entityHardwareDesigner_);
3731
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
3535
                
3536
                // Test case
3537
                Attribute anAttribute = entityManufacturer_.getAttribute("hardwareDesignersMapUC4");
3538
                assertNotNull(anAttribute);
3539
                assertEquals(PersistentAttributeType.ONE_TO_MANY, anAttribute.getPersistentAttributeType());
3540
                assertTrue(((AttributeImpl)anAttribute).isPlural());
3541
                assertTrue(anAttribute instanceof MapAttribute);
3542
                assertEquals(entityHardwareDesigner_, ((MapAttribute)anAttribute).getElementType());
3543
                assertEquals(CollectionType.MAP, ((MapAttribute)anAttribute).getCollectionType());                
3544
                assertEquals(String.class, ((MapAttribute)anAttribute).getKeyJavaType());
3545
                assertEquals(HardwareDesigner.class, anAttribute.getJavaType());
3546
            } catch (Exception e) {
3547
                e.printStackTrace();
3548
                expectedIAExceptionThrown = true;
3549
            } finally {
3550
                cleanup(em);
3551
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3552
            }
3553
        }
3554
    }
3555
3556
    public void testManagedType_Interface_getAttribute_on_MappedSuperclass_Method() {
3557
        if(!this.isJPA10()) {
3558
            EntityManager em = null;
3559
            boolean expectedIAExceptionThrown = false;
3560
            try {
3561
                em = privateTestSetup();
3562
                assertNotNull(em);
3563
                Metamodel metamodel = em.getMetamodel();
3564
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3565
                ManagedType<Corporation> msCorporation_  = metamodel.managedType(Corporation.class);
3732
                assertNotNull(msCorporation_);
3566
                assertNotNull(msCorporation_);
3733
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3734
                assertNotNull(entityLocation_);
3735
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3567
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3736
                assertNotNull(entityComputer_);
3568
                assertNotNull(entityComputer_);
3569
                
3570
                
3571
                // Test case
3572
                // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass
3573
                Attribute anAttribute = msCorporation_.getAttribute("corporateComputers");
3574
                assertNotNull(anAttribute);
3575
                assertEquals(PersistentAttributeType.ONE_TO_MANY, anAttribute.getPersistentAttributeType());
3576
                assertTrue(((AttributeImpl)anAttribute).isPlural());
3577
                assertTrue(anAttribute instanceof CollectionAttribute);
3578
                assertEquals(entityComputer_, ((CollectionAttribute)anAttribute).getElementType());
3579
                assertEquals(CollectionType.COLLECTION, ((CollectionAttribute)anAttribute).getCollectionType());                
3580
                assertEquals(Computer.class, anAttribute.getJavaType());
3581
            } catch (Exception e) {
3582
                e.printStackTrace();
3583
                expectedIAExceptionThrown = true;
3584
            } finally {
3585
                cleanup(em);
3586
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3587
            }
3588
        }
3589
    }
3590
    
3591
    public void testManagedType_Interface_getAttribute_doesNotExist_on_Entity_Method() {
3592
        if(!this.isJPA10()) {
3593
            EntityManager em = null;
3594
            boolean expectedIAExceptionThrown = false;
3595
            Attribute anAttribute = null;            
3596
            try {
3597
                em = privateTestSetup();
3598
                assertNotNull(em);
3599
                Metamodel metamodel = em.getMetamodel();
3600
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3601
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3602
                assertNotNull(entityManufacturer_);
3737
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3603
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3738
                assertNotNull(entityHardwareDesigner_);
3604
                assertNotNull(entityHardwareDesigner_);
3605
                
3606
                // Test case
3607
                anAttribute = entityManufacturer_.getAttribute("does_not_exist");
3608
            } catch (Exception e) {
3609
                // We expect and exception
3610
                //e.printStackTrace();
3611
                expectedIAExceptionThrown = true;
3612
            } finally {
3613
                cleanup(em);
3614
                assertNull(anAttribute);                
3615
                assertTrue("An IAE exception should have occured on a non-existent attribute.", expectedIAExceptionThrown);
3616
            }
3617
        }
3618
    }
3739
3619
3620
    public void testManagedType_Interface_getAttribute_doesNotExist_on_MappedSuperclass_Method() {
3621
        if(!this.isJPA10()) {
3622
            EntityManager em = null;
3623
            boolean expectedIAExceptionThrown = false;
3624
            Attribute anAttribute = null;            
3625
            try {
3626
                em = privateTestSetup();
3627
                assertNotNull(em);
3628
                Metamodel metamodel = em.getMetamodel();
3629
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3630
                ManagedType<Corporation> msCorporation_  = metamodel.managedType(Corporation.class);
3631
                assertNotNull(msCorporation_);
3632
                
3633
                // Test case
3634
                anAttribute = msCorporation_.getAttribute("does_not_exist");
3740
            } catch (Exception e) {
3635
            } catch (Exception e) {
3741
                e.printStackTrace();
3636
                // We expect and exception
3637
                //e.printStackTrace();
3742
                expectedIAExceptionThrown = true;
3638
                expectedIAExceptionThrown = true;
3743
            } finally {
3639
            } finally {
3744
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3640
                cleanup(em);
3745
                if(null != em) {
3641
                assertNull(anAttribute);                
3746
                    cleanup(em);
3642
                assertTrue("An IAE exception should have occured on a non-existent attribute.", expectedIAExceptionThrown);
3747
                }
3748
            }
3643
            }
3749
        }
3644
        }
3750
    }
3645
    }
Lines 3760-3792 Link Here
3760
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3655
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3761
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3656
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3762
                assertNotNull(entityManufacturer_);
3657
                assertNotNull(entityManufacturer_);
3763
                MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl)metamodel.managedType(Person.class);
3764
                assertNotNull(msPerson_);
3765
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
3766
                assertNotNull(msCorporation_);
3767
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3768
                assertNotNull(entityLocation_);
3769
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3770
                assertNotNull(entityComputer_);
3771
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3658
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3772
                assertNotNull(entityHardwareDesigner_);
3659
                assertNotNull(entityHardwareDesigner_);
3773
3660
                
3661
                // Test case
3662
                Attribute anAttribute = entityManufacturer_.getDeclaredAttribute("hardwareDesignersMapUC4");
3663
                assertNotNull(anAttribute);
3664
                assertEquals(PersistentAttributeType.ONE_TO_MANY, anAttribute.getPersistentAttributeType());
3665
                assertTrue(((AttributeImpl)anAttribute).isPlural());
3666
                assertTrue(anAttribute instanceof MapAttribute);
3667
                assertEquals(entityHardwareDesigner_, ((MapAttribute)anAttribute).getElementType());
3668
                assertEquals(CollectionType.MAP, ((MapAttribute)anAttribute).getCollectionType());                
3669
                assertEquals(String.class, ((MapAttribute)anAttribute).getKeyJavaType());
3670
                assertEquals(HardwareDesigner.class, anAttribute.getJavaType());
3774
            } catch (Exception e) {
3671
            } catch (Exception e) {
3775
                e.printStackTrace();
3672
                e.printStackTrace();
3776
                expectedIAExceptionThrown = true;
3673
                expectedIAExceptionThrown = true;
3777
            } finally {
3674
            } finally {
3675
                cleanup(em);
3778
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3676
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3779
                if(null != em) {
3780
                    cleanup(em);
3781
                }
3782
            }
3677
            }
3783
        }
3678
        }
3784
    }
3679
    }
3785
    
3680
3786
    public void testManagedType_Interface_getSingularAttribute_Method() {
3681
    public void testManagedType_Interface_getDeclaredAttribute_above_throws_iae_Method() {
3787
        if(!this.isJPA10()) {
3682
        if(!this.isJPA10()) {
3788
            EntityManager em = null;
3683
            EntityManager em = null;
3789
            boolean expectedIAExceptionThrown = false;
3684
            boolean expectedIAExceptionThrown = false;
3685
            Attribute anAttribute = null;
3790
            try {
3686
            try {
3791
                em = privateTestSetup();
3687
                em = privateTestSetup();
3792
                assertNotNull(em);
3688
                assertNotNull(em);
Lines 3794-3823 Link Here
3794
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3690
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3795
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3691
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3796
                assertNotNull(entityManufacturer_);
3692
                assertNotNull(entityManufacturer_);
3797
                MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl)metamodel.managedType(Person.class);
3693
3798
                assertNotNull(msPerson_);
3694
                // Test case
3799
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
3695
                // attribute is declared on a mappedsuperclass 
3800
                assertNotNull(msCorporation_);
3696
                // Note: internally EclipseLink treats a ONE_TO_MANY as a MANY_TO_MANY for the case of a unidirectional mapping on a MappedSuperclass                
3697
                anAttribute = entityManufacturer_.getDeclaredAttribute("corporateComputers ");
3698
            } catch (Exception e) {
3699
                // We expect and exception
3700
                //e.printStackTrace();
3701
                expectedIAExceptionThrown = true;
3702
            } finally {
3703
                cleanup(em);
3704
                assertNull(anAttribute);                
3705
                assertTrue("An IAE exception should have occured on an attribute declared above this entity.", expectedIAExceptionThrown);
3706
            }
3707
        }
3708
    }
3709
3710
    public void testManagedType_Interface_getDeclaredAttribute_doesNotExist_Method() {
3711
        if(!this.isJPA10()) {
3712
            EntityManager em = null;
3713
            boolean expectedIAExceptionThrown = false;
3714
            Attribute anAttribute = null;
3715
            try {
3716
                em = privateTestSetup();
3717
                assertNotNull(em);
3718
                Metamodel metamodel = em.getMetamodel();
3719
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3720
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3721
                assertNotNull(entityManufacturer_);
3722
3723
                // Test case
3724
                anAttribute = entityManufacturer_.getDeclaredAttribute("does_not_exist");
3725
            } catch (Exception e) {
3726
                // We expect and exception
3727
                //e.printStackTrace();
3728
                expectedIAExceptionThrown = true;
3729
            } finally {
3730
                cleanup(em);
3731
                assertNull(anAttribute);                
3732
                assertTrue("An IAE exception should have occured on a non-existent attribute.", expectedIAExceptionThrown);
3733
            }
3734
        }
3735
    }
3736
    
3737
    
3738
    public void testManagedType_Interface_getSingularAttribute_BASIC_Method() {
3739
        if(!this.isJPA10()) {
3740
            EntityManager em = null;
3741
            boolean expectedIAExceptionThrown = false;
3742
            try {
3743
                em = privateTestSetup();
3744
                assertNotNull(em);
3745
                Metamodel metamodel = em.getMetamodel();
3746
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3801
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3747
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3802
                assertNotNull(entityLocation_);
3748
                assertNotNull(entityLocation_);
3803
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3749
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3804
                assertNotNull(entityComputer_);
3750
                assertNotNull(entityComputer_);
3805
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3751
                
3806
                assertNotNull(entityHardwareDesigner_);
3752
                // Test case
3807
3753
                Attribute anAttribute = entityComputer_.getSingularAttribute("version");
3754
                assertNotNull(anAttribute);
3755
                assertEquals(PersistentAttributeType.BASIC, anAttribute.getPersistentAttributeType());
3756
                assertFalse(((AttributeImpl)anAttribute).isPlural());
3757
                assertTrue(anAttribute instanceof SingularAttribute);
3758
                assertEquals(int.class, anAttribute.getJavaType());
3808
            } catch (Exception e) {
3759
            } catch (Exception e) {
3809
                e.printStackTrace();
3760
                e.printStackTrace();
3810
                expectedIAExceptionThrown = true;
3761
                expectedIAExceptionThrown = true;
3811
            } finally {
3762
            } finally {
3763
                cleanup(em);
3812
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3764
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3813
                if(null != em) {
3814
                    cleanup(em);
3815
                }
3816
            }
3765
            }
3817
        }
3766
        }
3818
    }
3767
    }
3819
    
3768
    
3820
    public void testManagedType_Interface_getDeclaredSingularAttribute_Method() {
3769
    public void testManagedType_Interface_getSingularAttribute_EMBEDDED_Method() {
3821
        if(!this.isJPA10()) {
3770
        if(!this.isJPA10()) {
3822
            EntityManager em = null;
3771
            EntityManager em = null;
3823
            boolean expectedIAExceptionThrown = false;
3772
            boolean expectedIAExceptionThrown = false;
Lines 3826-3852 Link Here
3826
                assertNotNull(em);
3775
                assertNotNull(em);
3827
                Metamodel metamodel = em.getMetamodel();
3776
                Metamodel metamodel = em.getMetamodel();
3828
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3777
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3829
                EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
3830
                assertNotNull(entityManufacturer_);
3831
                MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl)metamodel.managedType(Person.class);
3832
                assertNotNull(msPerson_);
3833
                MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl)metamodel.managedType(Corporation.class);
3834
                assertNotNull(msCorporation_);
3835
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3778
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3836
                assertNotNull(entityLocation_);
3779
                assertNotNull(entityLocation_);
3837
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3780
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3838
                assertNotNull(entityComputer_);
3781
                assertNotNull(entityComputer_);
3839
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3782
                
3840
                assertNotNull(entityHardwareDesigner_);
3783
                // not implemented
3784
            } catch (Exception e) {
3785
                e.printStackTrace();
3786
                expectedIAExceptionThrown = true;
3787
            } finally {
3788
                cleanup(em);
3789
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3790
            }
3791
        }
3792
    }
3793
    
3794
    public void testManagedType_Interface_getDeclaredSingularAttribute_on_Entity_Method() {
3795
        if(!this.isJPA10()) {
3796
            EntityManager em = null;
3797
            boolean expectedIAExceptionThrown = false;
3798
            try {
3799
                em = privateTestSetup();
3800
                Metamodel metamodel = em.getMetamodel();
3801
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3802
                EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
3803
                assertNotNull(entityLocation_);
3804
                EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
3805
                assertNotNull(entityComputer_);
3806
                
3807
                // Test case
3808
                Attribute anAttribute = entityComputer_.getSingularAttribute("location");
3809
                assertNotNull(anAttribute);
3810
                assertEquals(PersistentAttributeType.ONE_TO_ONE, anAttribute.getPersistentAttributeType());
3811
                assertFalse(((AttributeImpl)anAttribute).isPlural());
3812
                assertTrue(anAttribute instanceof SingularAttribute);
3813
            } catch (Exception e) {
3814
                e.printStackTrace();
3815
                expectedIAExceptionThrown = true;
3816
            } finally {
3817
                cleanup(em);
3818
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3819
            }
3820
        }
3821
    }
3841
3822
3823
    public void testManagedType_Interface_getDeclaredSingularAttribute_on_MappedSuperclass_Method() {
3824
        if(!this.isJPA10()) {
3825
            EntityManager em = null;
3826
            boolean expectedIAExceptionThrown = false;
3827
            try {
3828
                em = privateTestSetup();
3829
                assertNotNull(em);
3830
                Metamodel metamodel = em.getMetamodel();
3831
                assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
3832
                MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl)metamodel.managedType(Person.class);
3833
                assertNotNull(msPerson_);
3834
                
3835
                // Test case
3836
                Attribute anAttribute = msPerson_.getSingularAttribute("name");
3837
                assertNotNull(anAttribute);
3838
                assertEquals(PersistentAttributeType.BASIC, anAttribute.getPersistentAttributeType());
3839
                assertFalse(((AttributeImpl)anAttribute).isPlural());
3840
                assertTrue(anAttribute instanceof SingularAttribute);
3841
                assertEquals(String.class, anAttribute.getJavaType());
3842
            } catch (Exception e) {
3842
            } catch (Exception e) {
3843
                e.printStackTrace();
3843
                e.printStackTrace();
3844
                expectedIAExceptionThrown = true;
3844
                expectedIAExceptionThrown = true;
3845
            } finally {
3845
            } finally {
3846
                cleanup(em);
3846
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3847
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3847
                if(null != em) {
3848
                    cleanup(em);
3849
                }
3850
            }
3848
            }
3851
        }
3849
        }
3852
    }
3850
    }
Lines 3877-3886 Link Here
3877
                e.printStackTrace();
3875
                e.printStackTrace();
3878
                expectedIAExceptionThrown = true;
3876
                expectedIAExceptionThrown = true;
3879
            } finally {
3877
            } finally {
3878
                cleanup(em);
3880
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3879
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3881
                if(null != em) {
3882
                    cleanup(em);
3883
                }
3884
            }
3880
            }
3885
        }
3881
        }
3886
    }
3882
    }
Lines 3911-3920 Link Here
3911
                e.printStackTrace();
3907
                e.printStackTrace();
3912
                expectedIAExceptionThrown = true;
3908
                expectedIAExceptionThrown = true;
3913
            } finally {
3909
            } finally {
3910
                cleanup(em);
3914
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3911
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3915
                if(null != em) {
3916
                    cleanup(em);
3917
                }
3918
            }
3912
            }
3919
        }
3913
        }
3920
    }
3914
    }
Lines 3940-3954 Link Here
3940
                assertNotNull(entityComputer_);
3934
                assertNotNull(entityComputer_);
3941
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3935
                EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
3942
                assertNotNull(entityHardwareDesigner_);
3936
                assertNotNull(entityHardwareDesigner_);
3937
                SetAttribute<? super Manufacturer, Computer> computersAttribute = 
3938
                    entityManufacturer_.getSet("computers", Computer.class);
3939
                assertNotNull("computers SetAttribute should not be null in Manufacturer_", computersAttribute);
3943
3940
3944
            } catch (Exception e) {
3941
            } catch (Exception e) {
3945
                e.printStackTrace();
3942
                e.printStackTrace();
3946
                expectedIAExceptionThrown = true;
3943
                expectedIAExceptionThrown = true;
3947
            } finally {
3944
            } finally {
3945
                cleanup(em);
3948
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3946
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3949
                if(null != em) {
3950
                    cleanup(em);
3951
                }
3952
            }
3947
            }
3953
        }
3948
        }
3954
    }
3949
    }
Lines 3979-3988 Link Here
3979
                e.printStackTrace();
3974
                e.printStackTrace();
3980
                expectedIAExceptionThrown = true;
3975
                expectedIAExceptionThrown = true;
3981
            } finally {
3976
            } finally {
3977
                cleanup(em);
3982
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3978
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
3983
                if(null != em) {
3984
                    cleanup(em);
3985
                }
3986
            }
3979
            }
3987
        }
3980
        }
3988
    }
3981
    }
Lines 4013-4022 Link Here
4013
                e.printStackTrace();
4006
                e.printStackTrace();
4014
                expectedIAExceptionThrown = true;
4007
                expectedIAExceptionThrown = true;
4015
            } finally {
4008
            } finally {
4009
                cleanup(em);
4016
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4010
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4017
                if(null != em) {
4018
                    cleanup(em);
4019
                }
4020
            }
4011
            }
4021
        }
4012
        }
4022
    }
4013
    }
Lines 4047-4056 Link Here
4047
                e.printStackTrace();
4038
                e.printStackTrace();
4048
                expectedIAExceptionThrown = true;
4039
                expectedIAExceptionThrown = true;
4049
            } finally {
4040
            } finally {
4041
                cleanup(em);
4050
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4042
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4051
                if(null != em) {
4052
                    cleanup(em);
4053
                }
4054
            }
4043
            }
4055
        }
4044
        }
4056
    }
4045
    }
Lines 4081-4090 Link Here
4081
                e.printStackTrace();
4070
                e.printStackTrace();
4082
                expectedIAExceptionThrown = true;
4071
                expectedIAExceptionThrown = true;
4083
            } finally {
4072
            } finally {
4073
                cleanup(em);
4084
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4074
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4085
                if(null != em) {
4086
                    cleanup(em);
4087
                }
4088
            }
4075
            }
4089
        }
4076
        }
4090
    }
4077
    }
Lines 4115-4124 Link Here
4115
                e.printStackTrace();
4102
                e.printStackTrace();
4116
                expectedIAExceptionThrown = true;
4103
                expectedIAExceptionThrown = true;
4117
            } finally {
4104
            } finally {
4105
                cleanup(em);
4118
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4106
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4119
                if(null != em) {
4120
                    cleanup(em);
4121
                }
4122
            }
4107
            }
4123
        }
4108
        }
4124
    }
4109
    }
Lines 4254-4274 Link Here
4254
                 */
4239
                 */
4255
                //Class<K> getKeyJavaType();
4240
                //Class<K> getKeyJavaType();
4256
4241
4257
                /**
4258
                 * Return the type representing the key type of the map.
4259
                 * @return type representing key type
4260
                 */
4261
                //Type<K> getKeyType();
4262
                
4263
                
4264
            } catch (Exception e) {
4242
            } catch (Exception e) {
4265
                //e.printStackTrace();
4243
                //e.printStackTrace();
4266
                exceptionThrown = true;
4244
                exceptionThrown = true;
4267
            } finally {
4245
            } finally {
4246
                cleanup(em);
4268
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4247
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4269
                if(null != em) {
4270
                    cleanup(em);
4271
                }
4272
            }
4248
            }
4273
        }
4249
        }
4274
    }
4250
    }
Lines 4285-4296 Link Here
4285
4261
4286
                // Actual Test Case
4262
                // Actual Test Case
4287
                /**
4263
                /**
4288
                 * Return the Java type of the map key.
4289
                 * @return Java key type
4290
                 */
4291
                //Class<K> getKeyJavaType();
4292
4293
                /**
4294
                 * Return the type representing the key type of the map.
4264
                 * Return the type representing the key type of the map.
4295
                 * @return type representing key type
4265
                 * @return type representing key type
4296
                 */
4266
                 */
Lines 4301-4310 Link Here
4301
                //e.printStackTrace();
4271
                //e.printStackTrace();
4302
                exceptionThrown = true;
4272
                exceptionThrown = true;
4303
            } finally {
4273
            } finally {
4274
                cleanup(em);
4304
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4275
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4305
                if(null != em) {
4306
                    cleanup(em);
4307
                }
4308
            }
4276
            }
4309
        }
4277
        }
4310
    }
4278
    }
Lines 4326-4335 Link Here
4326
                //e.printStackTrace();
4294
                //e.printStackTrace();
4327
                exceptionThrown = true;
4295
                exceptionThrown = true;
4328
            } finally {
4296
            } finally {
4297
                cleanup(em);
4329
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4298
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4330
                if(null != em) {
4331
                    cleanup(em);
4332
                }
4333
            }
4299
            }
4334
        }
4300
        }
4335
    }
4301
    }
Lines 4473-4482 Link Here
4473
                //e.printStackTrace();
4439
                //e.printStackTrace();
4474
                expectedIAExceptionThrown = true;
4440
                expectedIAExceptionThrown = true;
4475
            } finally {
4441
            } finally {
4442
                cleanup(em);
4476
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4443
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4477
                if(null != em) {
4478
                    cleanup(em);
4479
                }
4480
            }
4444
            }
4481
        }
4445
        }
4482
    }
4446
    }
Lines 4503-4512 Link Here
4503
                //e.printStackTrace();
4467
                //e.printStackTrace();
4504
                expectedIAExceptionThrown = true;
4468
                expectedIAExceptionThrown = true;
4505
            } finally {
4469
            } finally {
4470
                cleanup(em);
4506
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4471
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4507
                if(null != em) {
4508
                    cleanup(em);
4509
                }
4510
            }
4472
            }
4511
        }
4473
        }
4512
    }
4474
    }
Lines 4535-4544 Link Here
4535
                //e.printStackTrace();
4497
                //e.printStackTrace();
4536
                expectedIAExceptionThrown = true;
4498
                expectedIAExceptionThrown = true;
4537
            } finally {
4499
            } finally {
4500
                cleanup(em);
4538
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4501
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4539
                if(null != em) {
4540
                    cleanup(em);
4541
                }
4542
            }
4502
            }
4543
        }
4503
        }
4544
    }
4504
    }
Lines 4567-4576 Link Here
4567
                //e.printStackTrace();
4527
                //e.printStackTrace();
4568
                expectedIAExceptionThrown = true;
4528
                expectedIAExceptionThrown = true;
4569
            } finally {
4529
            } finally {
4530
                cleanup(em);
4570
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4531
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4571
                if(null != em) {
4572
                    cleanup(em);
4573
                }
4574
            }
4532
            }
4575
        }
4533
        }
4576
    }
4534
    }
Lines 4641-4650 Link Here
4641
                //e.printStackTrace();
4599
                //e.printStackTrace();
4642
                expectedIAExceptionThrown = true;
4600
                expectedIAExceptionThrown = true;
4643
            } finally {
4601
            } finally {
4602
                cleanup(em);
4644
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4603
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4645
                if(null != em) {
4646
                    cleanup(em);
4647
                }
4648
            }
4604
            }
4649
        }
4605
        }
4650
    }
4606
    }
Lines 4705-4714 Link Here
4705
                //e.printStackTrace();
4661
                //e.printStackTrace();
4706
                expectedIAExceptionThrown = true;
4662
                expectedIAExceptionThrown = true;
4707
            } finally {
4663
            } finally {
4664
                cleanup(em);
4708
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4665
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4709
                if(null != em) {
4710
                    cleanup(em);
4711
                }
4712
            }
4666
            }
4713
        }
4667
        }
4714
    }
4668
    }
Lines 4729-4738 Link Here
4729
                //e.printStackTrace();
4683
                //e.printStackTrace();
4730
                exceptionThrown = true;
4684
                exceptionThrown = true;
4731
            } finally {
4685
            } finally {
4686
                cleanup(em);
4732
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4687
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4733
                if(null != em) {
4734
                    cleanup(em);
4735
                }
4736
            }
4688
            }
4737
        }
4689
        }
4738
    }
4690
    }
Lines 4759-4768 Link Here
4759
                //e.printStackTrace();
4711
                //e.printStackTrace();
4760
                exceptionThrown = true;
4712
                exceptionThrown = true;
4761
            } finally {
4713
            } finally {
4714
                cleanup(em);
4762
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4715
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4763
                if(null != em) {
4764
                    cleanup(em);
4765
                }
4766
            }
4716
            }
4767
        }
4717
        }
4768
    }
4718
    }
Lines 4789-4798 Link Here
4789
                //e.printStackTrace();
4739
                //e.printStackTrace();
4790
                exceptionThrown = true;
4740
                exceptionThrown = true;
4791
            } finally {
4741
            } finally {
4742
                cleanup(em);
4792
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4743
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4793
                if(null != em) {
4794
                    cleanup(em);
4795
                }
4796
            }
4744
            }
4797
        }
4745
        }
4798
    }
4746
    }
Lines 4814-4823 Link Here
4814
                //e.printStackTrace();
4762
                //e.printStackTrace();
4815
                exceptionThrown = true;
4763
                exceptionThrown = true;
4816
            } finally {
4764
            } finally {
4765
                cleanup(em);
4817
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4766
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
4818
                if(null != em) {
4819
                    cleanup(em);
4820
                }
4821
            }
4767
            }
4822
        }
4768
        }
4823
    }
4769
    }
Lines 4852-4861 Link Here
4852
                //e.printStackTrace();
4798
                //e.printStackTrace();
4853
                expectedIAExceptionThrown = true;
4799
                expectedIAExceptionThrown = true;
4854
            } finally {
4800
            } finally {
4801
                cleanup(em);
4855
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4802
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4856
                if(null != em) {
4857
                    cleanup(em);
4858
                }
4859
            }
4803
            }
4860
        }
4804
        }
4861
    }
4805
    }
Lines 4891-4900 Link Here
4891
                //e.printStackTrace();
4835
                //e.printStackTrace();
4892
                expectedIAExceptionThrown = true;
4836
                expectedIAExceptionThrown = true;
4893
            } finally {
4837
            } finally {
4838
                cleanup(em);
4894
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4839
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4895
                if(null != em) {
4896
                    cleanup(em);
4897
                }
4898
            }
4840
            }
4899
        }
4841
        }
4900
    }
4842
    }
Lines 4929-4938 Link Here
4929
                //e.printStackTrace();
4871
                //e.printStackTrace();
4930
                expectedIAExceptionThrown = true;
4872
                expectedIAExceptionThrown = true;
4931
            } finally {
4873
            } finally {
4874
                cleanup(em);
4932
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4875
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4933
                if(null != em) {
4934
                    cleanup(em);
4935
                }
4936
            }
4876
            }
4937
        }
4877
        }
4938
    }
4878
    }
Lines 4957-4966 Link Here
4957
                e.printStackTrace();
4897
                e.printStackTrace();
4958
                expectedIAExceptionThrown = true;
4898
                expectedIAExceptionThrown = true;
4959
            } finally {
4899
            } finally {
4900
                cleanup(em);
4960
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4901
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4961
                if(null != em) {
4962
                    cleanup(em);
4963
                }
4964
            }
4902
            }
4965
        }
4903
        }
4966
    }
4904
    }
Lines 4989-4998 Link Here
4989
                //e.printStackTrace();
4927
                //e.printStackTrace();
4990
                expectedIAExceptionThrown = true;
4928
                expectedIAExceptionThrown = true;
4991
            } finally {
4929
            } finally {
4930
                cleanup(em);
4992
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4931
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4993
                if(null != em) {
4994
                    cleanup(em);
4995
                }
4996
            }
4932
            }
4997
        }
4933
        }
4998
    }
4934
    }
Lines 5015-5024 Link Here
5015
                //e.printStackTrace();
4951
                //e.printStackTrace();
5016
                expectedIAExceptionThrown = true;
4952
                expectedIAExceptionThrown = true;
5017
            } finally {
4953
            } finally {
4954
                cleanup(em);
5018
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4955
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
5019
                if(null != em) {
5020
                    cleanup(em);
5021
                }
5022
            }
4956
            }
5023
        }
4957
        }
5024
    }
4958
    }
Lines 5048-5057 Link Here
5048
                //e.printStackTrace();
4982
                //e.printStackTrace();
5049
                expectedIAExceptionThrown = true;
4983
                expectedIAExceptionThrown = true;
5050
            } finally {
4984
            } finally {
4985
                cleanup(em);
5051
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
4986
                assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
5052
                if(null != em) {
5053
                    cleanup(em);
5054
                }
5055
            }
4987
            }
5056
        }
4988
        }
5057
    }
4989
    }
Lines 5075-5093 Link Here
5075
                  */ 
5007
                  */ 
5076
                 //PersistenceType getPersistenceType();
5008
                 //PersistenceType getPersistenceType();
5077
5009
5078
                 /**
5079
                  *  Return the represented Java type.
5080
                  *  @return Java type
5081
                  */
5082
                 //Class<X> getJavaType();
5083
            } catch (Exception e) {
5010
            } catch (Exception e) {
5084
                //e.printStackTrace();
5011
                //e.printStackTrace();
5085
                exceptionThrown = true;
5012
                exceptionThrown = true;
5086
            } finally {
5013
            } finally {
5014
                cleanup(em);
5087
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5015
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5088
                if(null != em) {
5089
                    cleanup(em);
5090
                }
5091
            }
5016
            }
5092
        }
5017
        }
5093
    }
5018
    }
Lines 5120-5129 Link Here
5120
                //e.printStackTrace();
5045
                //e.printStackTrace();
5121
                exceptionThrown = true;
5046
                exceptionThrown = true;
5122
            } finally {
5047
            } finally {
5048
                cleanup(em);
5123
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5049
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5124
                if(null != em) {
5125
                    cleanup(em);
5126
                }
5127
            }
5050
            }
5128
        }
5051
        }
5129
    }
5052
    }
Lines 5140-5153 Link Here
5140
5063
5141
                // Actual Test Case
5064
                // Actual Test Case
5142
                //public static enum PersistenceType { ENTITY,  EMBEDDABLE, MAPPED_SUPERCLASS, BASIC }
5065
                //public static enum PersistenceType { ENTITY,  EMBEDDABLE, MAPPED_SUPERCLASS, BASIC }
5143
5144
                 /**
5066
                 /**
5145
                  *  Return the persistence type.
5146
                  *  @return persistence type
5147
                  */ 
5148
                 //PersistenceType getPersistenceType();
5149
5150
                 /**
5151
                  *  Return the represented Java type.
5067
                  *  Return the represented Java type.
5152
                  *  @return Java type
5068
                  *  @return Java type
5153
                  */
5069
                  */
Lines 5156-5165 Link Here
5156
                //e.printStackTrace();
5072
                //e.printStackTrace();
5157
                exceptionThrown = true;
5073
                exceptionThrown = true;
5158
            } finally {
5074
            } finally {
5075
                cleanup(em);
5159
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5076
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5160
                if(null != em) {
5161
                    cleanup(em);
5162
                }
5163
            }
5077
            }
5164
        }
5078
        }
5165
    }
5079
    }
Lines 5260-5274 Link Here
5260
                //e.printStackTrace();
5174
                //e.printStackTrace();
5261
                exceptionThrown = true;
5175
                exceptionThrown = true;
5262
            } finally {
5176
            } finally {
5177
                cleanup(em);
5263
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5178
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5264
                try {
5265
                } catch (Exception e) {
5266
                    e.printStackTrace();
5267
                } finally {
5268
                    if(null != em) {
5269
                        cleanup(em);
5270
                    }
5271
                }
5272
            }
5179
            }
5273
        }
5180
        }
5274
    }
5181
    }
Lines 5298-5782 Link Here
5298
                //e.printStackTrace();
5205
                //e.printStackTrace();
5299
                exceptionThrown = true;
5206
                exceptionThrown = true;
5300
            } finally {
5207
            } finally {
5208
                cleanup(em);
5301
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5209
                assertFalse("An IAE exception should not occur here.", exceptionThrown);
5302
                try {
5303
                } catch (Exception e) {
5304
                    e.printStackTrace();
5305
                } finally {
5306
                    if(null != em) {
5307
                        cleanup(em);
5308
                    }
5309
                }
5310
            }
5210
            }
5311
        }
5211
        }
5312
    }
5212
    }
5313
    
5314
    
5315
    /**
5316
     * The following large single test case contains signatures of all the spec functions.
5317
     * Those that have a test are implemented, the missing ones may still be in development.
5318
     */
5319
    public void test_MetamodelFullImplementation() {
5320
        if(!this.isJPA10()) {
5321
        EntityManager em = null;
5322
        Collection<Board> boardCollection = new HashSet<Board>();        
5323
        Set<Computer> computersList = new HashSet<Computer>();
5324
        Collection<Memory> vectorMemories = new LinkedHashSet<Memory>();
5325
        Collection<Memory> arrayMemories = new LinkedHashSet<Memory>();
5326
        Collection<Processor> vectorProcessors = new HashSet<Processor>();
5327
        Collection<Processor> arrayProcessors = new HashSet<Processor>();
5328
        List<HardwareDesigner> hardwareDesigners = new ArrayList<HardwareDesigner>();
5329
        Map<String, HardwareDesigner> mappedDesigners = new HashMap<String, HardwareDesigner>();
5330
        Computer arrayComputer1 = null;
5331
        Computer vectorComputer2 = null;
5332
        Manufacturer manufacturer = null;
5333
        User user = null;
5334
        HardwareDesigner hardwareDesigner1 = null;
5335
        SoftwareDesigner softwareDesigner1 = null;        
5336
        Processor vectorProcessor1 = null;
5337
        Processor arrayProcessor1 = null;
5338
        Board arrayBoard1 = null;
5339
        Board vectorBoard2 = null;
5340
        Memory arrayMemory1 = null;
5341
        Memory vectorMemory2 = null;
5342
        GalacticPosition location1 = null;
5343
        GalacticPosition location2 = null;   
5344
        
5345
        // Embedded objects
5346
        EmbeddedPK embeddedPKforLocation1 = new EmbeddedPK();        
5347
        EmbeddedPK embeddedPKforLocation2 = new EmbeddedPK();
5348
        
5349
        boolean exceptionThrown = false;
5350
        try {
5351
            em = privateTestSetup();
5352
            assertNotNull(em);
5353
            Metamodel metamodel = em.getMetamodel();
5354
            assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
5355
5356
            // SE only            
5357
            em.getTransaction().begin();
5358
5359
            // setup entity relationships
5360
            arrayComputer1 = new Computer();
5361
            vectorComputer2 = new Computer();
5362
            arrayMemory1 = new Memory();
5363
            vectorMemory2 = new Memory();
5364
            manufacturer = new Manufacturer();
5365
            user = new User();
5366
            hardwareDesigner1 = new HardwareDesigner();
5367
            softwareDesigner1 = new SoftwareDesigner();
5368
            vectorProcessor1 = new VectorProcessor();
5369
            arrayProcessor1 = new ArrayProcessor();
5370
            arrayBoard1 = new Board();
5371
            vectorBoard2 = new Board();
5372
            location1 = new GalacticPosition();
5373
            location2 = new GalacticPosition();        
5374
5375
            // setup collections
5376
            computersList.add(arrayComputer1);
5377
            computersList.add(vectorComputer2);
5378
            vectorProcessors.add(vectorProcessor1);
5379
            arrayProcessors.add(arrayProcessor1);
5380
            arrayMemories.add(arrayMemory1);
5381
            vectorMemories.add(vectorMemory2);
5382
            hardwareDesigners.add(hardwareDesigner1);
5383
            
5384
            mappedDesigners.put(hardwareDesigner1.getName(), hardwareDesigner1);
5385
            //manufacturer.setHardwareDesignersMap(mappedDesigners);
5386
            //manufacturer.setHardwareDesignersMapUC1a(mappedDesigners);
5387
            //manufacturer.setHardwareDesignersMapUC2(mappedDesigners);
5388
            //manufacturer.setHardwareDesignersMapUC4(mappedDesigners);
5389
            //manufacturer.setHardwareDesignersMapUC7(mappedDesigners);
5390
            //manufacturer.setHardwareDesignersMapUC8(mappedDesigners);            
5391
5392
            // set owning and inverse sides of 1:m and m:1 relationships
5393
            manufacturer.setComputers(computersList);
5394
            manufacturer.setHardwareDesigners(hardwareDesigners);
5395
            
5396
            hardwareDesigner1.setEmployer(manufacturer);
5397
            hardwareDesigner1.setPrimaryEmployer(manufacturer);
5398
            hardwareDesigner1.setSecondaryEmployer(manufacturer);
5399
            // both sides of the relationship are set
5400
            hardwareDesigner1.setMappedEmployer(manufacturer);
5401
            hardwareDesigner1.setMappedEmployerUC1a(manufacturer);
5402
            hardwareDesigner1.setMappedEmployerUC2(manufacturer);
5403
            hardwareDesigner1.setMappedEmployerUC4(manufacturer);
5404
            hardwareDesigner1.setMappedEmployerUC7(manufacturer);
5405
            hardwareDesigner1.setMappedEmployerUC8(manufacturer);            
5406
            
5407
            arrayComputer1.setManufacturer(manufacturer);
5408
            vectorComputer2.setManufacturer(manufacturer);
5409
            arrayBoard1.setMemories(arrayMemories);
5410
            vectorBoard2.setMemories(vectorMemories);
5411
            arrayMemory1.setBoard(arrayBoard1);
5412
            vectorMemory2.setBoard(vectorBoard2);
5413
            arrayBoard1.setProcessors(arrayProcessors);
5414
            vectorBoard2.setProcessors(vectorProcessors);
5415
            arrayProcessor1.setBoard(arrayBoard1);
5416
            vectorProcessor1.setBoard(vectorBoard2);            
5417
            
5418
            softwareDesigner1.setPrimaryEmployer(manufacturer);
5419
            softwareDesigner1.setSecondaryEmployer(manufacturer);
5420
            
5421
            arrayComputer1.setCircuitBoards(boardCollection);
5422
            arrayBoard1.setComputer(arrayComputer1);
5423
            vectorBoard2.setComputer(vectorComputer2);
5424
            
5425
            // set 1:1 relationships
5426
            arrayComputer1.setLocation(location1);
5427
            vectorComputer2.setLocation(location2);
5428
            // No get/set accessors on purpose for testing
5429
            //location1.futurePosition = location2;
5430
            //location2.futurePosition = location1;
5431
            
5432
            // set attributes
5433
            arrayComputer1.setName("CM-5");
5434
            vectorComputer2.setName("CDC-6600");
5435
            
5436
            // setup embedded objects
5437
            location1.setPrimaryKey(embeddedPKforLocation1);
5438
            location2.setPrimaryKey(embeddedPKforLocation2);
5439
                
5440
            // persist all entities to the database in a single transaction
5441
            em.persist(arrayComputer1);
5442
            em.persist(vectorComputer2);
5443
            em.persist(manufacturer);
5444
            em.persist(user);
5445
            em.persist(hardwareDesigner1);
5446
            em.persist(softwareDesigner1);
5447
            em.persist(vectorProcessor1);
5448
            em.persist(arrayProcessor1);
5449
            em.persist(arrayBoard1);
5450
            em.persist(vectorBoard2);
5451
            em.persist(arrayMemory1);
5452
            em.persist(vectorMemory2);
5453
            em.persist(location1);
5454
            em.persist(location2);        
5455
            
5456
            em.getTransaction().commit();            
5457
            
5458
            // Verify EntityType access to entities in the metamodel
5459
            // These entities are metamodel entities (1 per type) not JPA entity instances (IdentifiableType)
5460
            // TODO: temporarily used the impl classes - so F3 resolves in the IDE - revert to the interface for production
5461
            EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl)metamodel.entity(Computer.class);
5462
            assertNotNull(entityComputer_);
5463
            EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl)metamodel.entity(Manufacturer.class);
5464
            assertNotNull(entityManufacturer_);
5465
            EntityTypeImpl<User> entityUser_ = (EntityTypeImpl)metamodel.entity(User.class);
5466
            assertNotNull(entityUser_);
5467
            EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl)metamodel.entity(HardwareDesigner.class);
5468
            assertNotNull(entityHardwareDesigner_);
5469
            EntityTypeImpl<SoftwareDesigner> entitySoftwareDesigner_ = (EntityTypeImpl)metamodel.entity(SoftwareDesigner.class);
5470
            assertNotNull(entitySoftwareDesigner_);
5471
            EntityTypeImpl<Board> entityBoard_ = (EntityTypeImpl)metamodel.entity(Board.class);
5472
            assertNotNull(entityBoard_);
5473
            EntityTypeImpl<Memory> entityMemory_ = (EntityTypeImpl)metamodel.entity(Memory.class);
5474
            assertNotNull(entityMemory_);
5475
            EntityTypeImpl<GalacticPosition> entityLocation_ =(EntityTypeImpl) metamodel.entity(GalacticPosition.class);
5476
            assertNotNull(entityLocation_);
5477
            EntityTypeImpl<Processor> entityProcessor_ =(EntityTypeImpl) metamodel.entity(Processor.class);
5478
            assertNotNull(entityProcessor_);
5479
            EntityTypeImpl<VectorProcessor> entityVectorProcessor_ =(EntityTypeImpl) metamodel.entity(VectorProcessor.class);
5480
            assertNotNull(entityVectorProcessor_);
5481
            EntityTypeImpl<ArrayProcessor> entityArrayProcessor_ =(EntityTypeImpl) metamodel.entity(ArrayProcessor.class);
5482
            assertNotNull(entityArrayProcessor_);
5483
            
5484
            // Criteria queries (use the Metamodel)
5485
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
5486
/*            CriteriaBuilder qb = null;
5487
            List results = null;
5488
            try {
5489
                qb = em.getCriteriaBuilder();
5490
                //CriteriaQuery<String> cq = qb.createQuery(String.class);
5491
                CriteriaQuery<Computer> criteriaQuery = qb.createQuery(Computer.class);
5492
                Expression expression = new ClassTypeExpression(); // probably not the right expression impl
5493
                // somehow add "name" to the expression TBD                
5494
                //criteriaQuery.select((new SelectionImpl(String.class, expression)));
5495
                EntityTypeImpl<Computer> entityComputer2 = (EntityTypeImpl)metamodel.entity(Computer.class);                
5496
                Root from = criteriaQuery.from(entityComputer2);
5497
                Path path = from.get("name");
5498
                criteriaQuery.where(qb.equal(path, "CM-5"));  
5499
                Query query = em.createQuery(criteriaQuery);
5500
                results = query.getResultList();
5501
                if(!results.isEmpty()) {
5502
                    Computer computer = (Computer)results.get(0);
5503
                    assertNotNull(computer);
5504
                } else {
5505
                    fail("Results from criteria query (ReadAllQuery(referenceClass=Computer sql=SELECT COMPUTER_ID, NAME, COMPUTER_VERSION, MANUFACTURER_PERSON_ID, LOCATION_LOCATION_ID FROM CMP3_MM_COMPUTER WHERE NAME='CM-5') were expected");
5506
                }
5507
            } catch (Exception e) {
5508
                e.printStackTrace();
5509
            }
5510
*/
5511
            /* uncomment when the CriteriaBuilderImpl function below is implemented
5512
             * public <T> ParameterExpression<T> parameter(Class<T> paramClass, String name){
5513
            try {
5514
                qb = em.getCriteriaBuilder();
5515
                CriteriaQuery<Computer> cq = qb.createQuery(Computer.class);
5516
                Root from = cq.from(Computer.class);
5517
                Path c = from.get("name");
5518
                cq.where(qb.equal(c, qb.parameter(String.class, "emp_name")));
5519
                Query query = em.createQuery(cq);
5520
                results = query.getResultList();
5521
                Computer computer = (Computer)results.get(0);
5522
                assertNotNull(computer);
5523
            } catch (Exception e) {
5524
                e.printStackTrace();
5525
            }*/
5526
            
5527
            // SingularAttributeType
5528
            // Test getBindableType - this is for SVN rev# 4644
5529
            //http://fisheye2.atlassian.com/changelog/eclipselink/?cs=4644
5530
            // Basic
5531
            Class nameJavaType = ((SingularAttribute<Computer, String>)entityComputer_.getAttribute("name")).getBindableJavaType();
5532
            assertNotNull(nameJavaType);
5533
            assertEquals(String.class, nameJavaType);
5534
            
5535
            // OneToOne Entity
5536
            Class locationJavaType = ((SingularAttribute<Computer, GalacticPosition>)entityComputer_.getAttribute("location")).getBindableJavaType();
5537
            assertNotNull(locationJavaType);
5538
            assertEquals(GalacticPosition.class, locationJavaType);
5539
            
5540
            
5541
            /*
5542
             * Metamodel model toString
5543
             * ************************************************************************************
5544
    class org.eclipse.persistence.testing.models.jpa.metamodel.Person=MappedSuperclassTypeImpl@9206757 [ 
5545
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Person 
5546
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Person --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
5547
        mappings: [
5548
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5549
                id-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.PERSON_ID], 
5550
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5551
                name-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.NAME]]],
5552
    class org.eclipse.persistence.testing.models.jpa.metamodel.Corporation=MappedSuperclassTypeImpl@27921979 [ 
5553
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Corporation 
5554
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Corporation --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
5555
        mappings: [
5556
            org.eclipse.persistence.mappings.ManyToManyMapping[corporateComputers]]], 
5557
    class org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer=EntityTypeImpl@12565475 [ 
5558
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 
5559
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)]), 
5560
        mappings: [
5561
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5562
                id-->CMP3_MM_MANUF.PERSON_ID], 
5563
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5564
                name-->CMP3_MM_MANUF.NAME], 
5565
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5566
                version-->CMP3_MM_MANUF.MANUF_VERSION], 
5567
            org.eclipse.persistence.mappings.OneToManyMapping[
5568
                computers], 
5569
            org.eclipse.persistence.mappings.OneToManyMapping[
5570
                hardwareDesignersMap], 
5571
            org.eclipse.persistence.mappings.ManyToManyMapping[
5572
                corporateComputers], 
5573
            org.eclipse.persistence.mappings.OneToManyMapping[
5574
                hardwareDesigners]]], 
5575
    class org.eclipse.persistence.testing.models.jpa.metamodel.Memory=EntityTypeImpl@29905988 [ 
5576
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Memory 
5577
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Memory --> [DatabaseTable(CMP3_MM_MEMORY)]), 
5578
        mappings: [
5579
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5580
                id-->CMP3_MM_MEMORY.MEMORY_ID], 
5581
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5582
                version-->CMP3_MM_MEMORY.MEMORY_VERSION], 
5583
            org.eclipse.persistence.mappings.OneToOneMapping[
5584
                board]]], 
5585
    class org.eclipse.persistence.testing.models.jpa.metamodel.Designer=MappedSuperclassTypeImpl@25971327 [ 
5586
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Designer 
5587
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Designer --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
5588
        mappings: [
5589
            org.eclipse.persistence.mappings.OneToOneMapping[
5590
                secondaryEmployer], 
5591
            org.eclipse.persistence.mappings.OneToOneMapping[
5592
                primaryEmployer], 
5593
            org.eclipse.persistence.mappings.ManyToManyMapping[
5594
                historicalEmployers]]], 
5595
    class org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner=EntityTypeImpl@18107298 [ 
5596
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner 
5597
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner --> [DatabaseTable(CMP3_MM_HWDESIGNER)]), 
5598
        mappings: [
5599
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5600
                id-->CMP3_MM_HWDESIGNER.PERSON_ID], 
5601
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5602
                name-->CMP3_MM_HWDESIGNER.NAME], 
5603
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5604
                version-->CMP3_MM_HWDESIGNER.HWDESIGNER_VERSION], 
5605
            org.eclipse.persistence.mappings.OneToOneMapping[
5606
                employer], 
5607
            org.eclipse.persistence.mappings.OneToOneMapping[
5608
                mappedEmployer], 
5609
            org.eclipse.persistence.mappings.ManyToManyMapping[
5610
                historicalEmployers], 
5611
            org.eclipse.persistence.mappings.OneToOneMapping[
5612
                secondaryEmployer], 
5613
            org.eclipse.persistence.mappings.OneToOneMapping[
5614
                primaryEmployer]]], 
5615
    class org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner=EntityTypeImpl@26130360 [ 
5616
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner 
5617
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner --> [DatabaseTable(CMP3_MM_SWDESIGNER)]), 
5618
        mappings: [
5619
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5620
                id-->CMP3_MM_SWDESIGNER.PERSON_ID], 
5621
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5622
                name-->CMP3_MM_SWDESIGNER.NAME], 
5623
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5624
                version-->CMP3_MM_SWDESIGNER.SWDESIGNER_VERSION], 
5625
            org.eclipse.persistence.mappings.OneToOneMapping[
5626
                secondaryEmployer], 
5627
            org.eclipse.persistence.mappings.OneToOneMapping[
5628
                primaryEmployer], 
5629
            org.eclipse.persistence.mappings.ManyToManyMapping[
5630
                historicalEmployers]]], 
5631
    class org.eclipse.persistence.testing.models.jpa.metamodel.Board=EntityTypeImpl@24223536 [ 
5632
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Board 
5633
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Board --> [DatabaseTable(CMP3_MM_BOARD)]), 
5634
        mappings: [
5635
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5636
                id-->CMP3_MM_BOARD.BOARD_ID], 
5637
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5638
                version-->CMP3_MM_BOARD.BOARD_VERSION], 
5639
            org.eclipse.persistence.mappings.OneToManyMapping[
5640
                memories], 
5641
            org.eclipse.persistence.mappings.OneToManyMapping[
5642
                processors]]], 
5643
    class org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK=EmbeddableTypeImpl@29441291 [ 
5644
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK descriptor: 
5645
        RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK --> []), 
5646
        mappings: [
5647
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5648
                pk_part1-->LOCATION_ID]]], 
5649
    class org.eclipse.persistence.testing.models.jpa.metamodel.Location=EntityTypeImpl@9050487 [ 
5650
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Location 
5651
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Location --> [DatabaseTable(CMP3_MM_LOCATION)]), 
5652
        mappings: [
5653
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5654
                version-->CMP3_MM_LOCATION.LOCATION_VERSION], 
5655
            org.eclipse.persistence.mappings.AggregateObjectMapping[
5656
                primaryKey]]], 
5657
    class org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor=EntityTypeImpl@9300338 [ 
5658
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor 
5659
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor --> [DatabaseTable(CMP3_MM_PROC)]), 
5660
        mappings: [
5661
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5662
                id-->CMP3_MM_PROC.VECTPROC_ID], 
5663
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5664
                version-->CMP3_MM_PROC.VECTPROC_VERSION], 
5665
            org.eclipse.persistence.mappings.OneToOneMapping[
5666
                board]]], 
5667
    class org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor=EntityTypeImpl@14247087 [ 
5668
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor 
5669
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor --> [DatabaseTable(CMP3_MM_ARRAYPROC)]), 
5670
        mappings: [
5671
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5672
                id-->CMP3_MM_ARRAYPROC.ARRAYPROC_ID], 
5673
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5674
                version-->CMP3_MM_ARRAYPROC.ARRAYPROC_VERSION], 
5675
            org.eclipse.persistence.mappings.OneToOneMapping[
5676
                board]]], 
5677
    class org.eclipse.persistence.testing.models.jpa.metamodel.Computer=EntityTypeImpl@8355938 [ 
5678
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Computer 
5679
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Computer --> [DatabaseTable(CMP3_MM_COMPUTER)]), 
5680
        mappings: [
5681
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5682
                id-->CMP3_MM_COMPUTER.COMPUTER_ID], 
5683
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5684
                name-->CMP3_MM_COMPUTER.NAME], 
5685
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5686
                version-->CMP3_MM_COMPUTER.COMPUTER_VERSION], 
5687
            org.eclipse.persistence.mappings.OneToOneMapping[
5688
                manufacturer], 
5689
            org.eclipse.persistence.mappings.OneToOneMapping[
5690
                location]]], 
5691
    class org.eclipse.persistence.testing.models.jpa.metamodel.User=EntityTypeImpl@12968655 [ 
5692
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.User 
5693
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.User --> [DatabaseTable(CMP3_MM_USER)]), 
5694
        mappings: [
5695
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5696
                id-->CMP3_MM_USER.PERSON_ID], 
5697
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5698
                name-->CMP3_MM_USER.NAME], 
5699
            org.eclipse.persistence.mappings.DirectToFieldMapping[
5700
                version-->CMP3_MM_USER.USER_VERSION]]], 
5701
    class org.eclipse.persistence.testing.models.jpa.metamodel.Processor=MappedSuperclassTypeImpl@24044524 [ 
5702
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Processor 
5703
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Processor --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
5704
        mappings: []], 
5705
    class org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK=EmbeddableTypeImpl@6367194 [ 
5706
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK 
5707
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK --> []), 
5708
        mappings: []], 
5709
    class java.lang.Integer=BasicTypeImpl@33083511 [ 
5710
        javaType: class java.lang.Integer], 
5711
    class java.lang.String=BasicTypeImpl@4086417 [ 
5712
        javaType: class java.lang.String], 
5713
    int=BasicTypeImpl@28057122 [ 
5714
        javaType: int]}
5715
                */
5716
            
5717
            
5718
            // get some static (non-runtime) attributes parameterized by <Owning type, return Type>
5719
            // Note: the String based attribute names are non type-safe
5720
            /*
5721
            aMember CollectionAttributeImpl<X,E>  (id=183)  
5722
             elementType BasicImpl<X>  (id=188)  
5723
                javaClass   Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Computer) (id=126)   
5724
             managedType EntityTypeImpl<X>  (id=151) 
5725
                descriptor  RelationalDescriptor  (id=156)  
5726
                javaClass   Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer) (id=129)   
5727
                members HashMap<K,V>  (id=157)  
5728
                metamodel   MetamodelImpl  (id=52)  
5729
                supertype   null    
5730
            mapping OneToManyMapping  (id=191)  
5731
            */
5732
            // The attributes are in the field ManagedTypeImpl.members
5733
            // The managedType is the owner of the attribute
5734
            //hardwareDesigners=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[hardwareDesigners]], 
5735
            //computers=CollectionAttribute[org.eclipse.persistence.mappings.OneToManyMapping[computers]],
5736
            
5737
            // 20090707: We are getting a CCE because "all" Collections are defaulting to List 
5738
            // when they are lazy instantiated as IndirectList if persisted as a List independent of what the OneToOne mapping is defined as
5739
//            javax.persistence.metamodel.CollectionAttribute<? super Manufacturer, Computer> computersAttribute = 
5740
//                entityManufacturer.getCollection("computers", Computer.class);
5741
//            javax.persistence.metamodel.CollectionAttribute<? super Manufacturer, Computer> computersAttribute2 = 
5742
//                entityManufacturer.getCollection("computers", Computer.class);
5743
            javax.persistence.metamodel.SetAttribute<? super Manufacturer, Computer> computersAttribute = 
5744
                entityManufacturer_.getSet("computers", Computer.class);
5745
            
5746
            //version=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[version-->CMP3_MM_MANUF.MANUF_VERSION]], 
5747
            //name=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[name-->CMP3_MM_MANUF.NAME]], 
5748
            //id=Attribute[org.eclipse.persistence.mappings.DirectToFieldMapping[id-->CMP3_MM_MANUF.PERSON_ID]]
5749
            
5750
            
5751
            // Variant use cases
5752
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
5753
            boolean iae1thrown = false;
5754
            
5755
            // A Criteria API query that is expected to fail with an IAE
5756
            CriteriaBuilder qbForExceptions = null;
5757
            
5758
            iae1thrown = false;
5759
            try {
5760
                qbForExceptions = em.getCriteriaBuilder();
5761
                CriteriaQuery<Computer> cq = qbForExceptions.createQuery(Computer.class);
5762
                Root from = cq.from(Computer.class);
5763
                Path invalidPath = from.get("____unknown_attribute_name_should_fail_with_IAE_____");
5764
            } catch (Exception e) {
5765
                iae1thrown = true;
5766
                //e.printStackTrace();
5767
            }
5768
            assertTrue("We expect an AE exception here", iae1thrown);
5769
        } catch (Exception e) {
5770
            // we enter here on a failed commit() - for example if the table schema is incorrectly defined
5771
            e.printStackTrace();
5772
            exceptionThrown = true;
5773
        } finally {
5774
            // Runtime behavior should not affect the metamodel
5775
            assertFalse(exceptionThrown);
5776
            if(null != em) {
5777
                cleanup(em);
5778
            }
5779
        }
5780
        }
5781
    }
5782
}
5213
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java (-2 / +2 lines)
Lines 734-740 Link Here
734
        field4.setIsIdentity(false);
734
        field4.setIsIdentity(false);
735
        table.addField(field4);
735
        table.addField(field4);
736
736
737
        // 1:m does not require a JoinTable - only a JoinColumn
737
/*        // m:1 requires a JoinTable
738
        FieldDefinition field6 = new FieldDefinition();
738
        FieldDefinition field6 = new FieldDefinition();
739
        field6.setName("COMPUTER_COMPUTER_ID");
739
        field6.setName("COMPUTER_COMPUTER_ID");
740
        field6.setTypeName("NUMERIC");
740
        field6.setTypeName("NUMERIC");
Lines 745-751 Link Here
745
        field6.setIsIdentity(false);
745
        field6.setIsIdentity(false);
746
        field6.setForeignKeyFieldName("CMP3_MM_COMPUTER.COMPUTER_ID");
746
        field6.setForeignKeyFieldName("CMP3_MM_COMPUTER.COMPUTER_ID");
747
        table.addField(field6);        
747
        table.addField(field6);        
748
        
748
*/        
749
        return table;
749
        return table;
750
    }
750
    }
751
751
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/ManyToOneAccessor.java (+4 lines)
Lines 26-31 Link Here
26
import org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAccessibleObject;
26
import org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAccessibleObject;
27
import org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotation;
27
import org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotation;
28
28
29
import org.eclipse.persistence.mappings.ManyToManyMapping;
29
import org.eclipse.persistence.mappings.OneToOneMapping;
30
import org.eclipse.persistence.mappings.OneToOneMapping;
30
31
31
/**
32
/**
Lines 89-94 Link Here
89
        OneToOneMapping mapping = initOneToOneMapping();
90
        OneToOneMapping mapping = initOneToOneMapping();
90
        setMapping(mapping);
91
        setMapping(mapping);
91
        
92
        
93
        // 266912: If this n:1 accessor is different than the 1:1 mapping -track this
94
        mapping.setDefinedAsManyToOneMapping(true);
95
        
92
        // Process the owning keys for this mapping.
96
        // Process the owning keys for this mapping.
93
        processOwningMappingKeys(mapping);
97
        processOwningMappingKeys(mapping);
94
    }
98
    }
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/MappingAccessor.java (-3 / +24 lines)
Lines 124-130 Link Here
124
    private ClassAccessor m_classAccessor;
124
    private ClassAccessor m_classAccessor;
125
    private DatabaseMapping m_mapping;
125
    private DatabaseMapping m_mapping;
126
    private Map<String, PropertyMetadata> m_properties = new HashMap<String, PropertyMetadata>();
126
    private Map<String, PropertyMetadata> m_properties = new HashMap<String, PropertyMetadata>();
127
127
    
128
    /**
128
    /**
129
     * INTERNAL:
129
     * INTERNAL:
130
     */
130
     */
Lines 1674-1680 Link Here
1674
    
1674
    
1675
    /**
1675
    /**
1676
     * INTERNAL:
1676
     * INTERNAL:
1677
     * This will do two things:
1677
     * This will do three things:
1678
     * 1 - process any common level metadata for all mappings.
1678
     * 1 - process any common level metadata for all mappings.
1679
     * 2 - add the mapping to the internal descriptor.
1679
     * 2 - add the mapping to the internal descriptor.
1680
     * 3 - store the actual database mapping associated with this accessor.
1680
     * 3 - store the actual database mapping associated with this accessor.
Lines 1694-1700 Link Here
1694
        getDescriptor().getClassDescriptor().addMapping(mapping);
1694
        getDescriptor().getClassDescriptor().addMapping(mapping);
1695
        
1695
        
1696
        // Keep a reference back to this mapping for quick look up.
1696
        // Keep a reference back to this mapping for quick look up.
1697
        m_mapping = mapping;
1697
        m_mapping = mapping;  
1698
        
1699
        // REMOVE: The following commented block is for review of an abandoned version
1700
        // and will not be checked in
1701
        /**
1702
         * Since: EclipseLink 2.0 for the Metamodel API
1703
         * For 1:1 and m:m mappings - track the original externally defined mapping if different 
1704
         * Note: This field will provide differentiation for the following 
1705
         *   external to internal representations for mapping types<br>
1706
         *   - A OneToManyMapping will be represented by a ManyToManyMapping if on a MappedSuperclass<br>
1707
         *   - A ManyToOneMapping will be represented by a OneToOneMapping (without a FK constraint)<br>      
1708
         */
1709
/*        // If this n:1 accessor is different than the 1:1 mapping -track this
1710
        if((this.isManyToOne() && mapping.isOneToOneMapping())) {
1711
            ((OneToOneMapping)mapping).setDefinedAsManyToOneMapping(true);
1712
        }
1713
        // If this 1:n accessor is different than the n:n mapping - track this
1714
        if((this.isOneToMany() && mapping.isManyToManyMapping())) {
1715
            ((ManyToManyMapping)mapping).setDefinedAsOneToManyMapping(true);
1716
        }
1717
*/        
1718
1698
    }
1719
    }
1699
    
1720
    
1700
    /**
1721
    /**
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/OneToManyAccessor.java (-1 / +4 lines)
Lines 97-103 Link Here
97
    
97
    
98
    /**
98
    /**
99
     * INTERNAL:
99
     * INTERNAL:
100
     * Process an OneToMany accessor into an EclipseLink OneToManyMapping. If a 
100
     * Process a OneToMany accessor into an EclipseLink OneToManyMapping. If a 
101
     * JoinTable is found however, we must create a ManyToManyMapping.
101
     * JoinTable is found however, we must create a ManyToManyMapping.
102
     */
102
     */
103
    @Override
103
    @Override
Lines 149-154 Link Here
149
        // first followed by specific metadata.
149
        // first followed by specific metadata.
150
        ManyToManyMapping mapping = new ManyToManyMapping();
150
        ManyToManyMapping mapping = new ManyToManyMapping();
151
        process(mapping);
151
        process(mapping);
152
        
153
        // 266912: If this 1:n accessor is different than the n:n mapping - track this
154
        mapping.setDefinedAsOneToManyMapping(true);
152
                
155
                
153
        // Process the JoinTable metadata.
156
        // Process the JoinTable metadata.
154
        processJoinTable(mapping, mapping.getRelationTableMechanism(), getJoinTableMetadata());
157
        processJoinTable(mapping, mapping.getRelationTableMechanism(), getJoinTableMetadata());
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/AttributeImpl.java (-25 / +40 lines)
Lines 12-18 Link Here
12
 *     06/30/2009-2.0  mobrien - finish JPA Metadata API modifications in support
12
 *     06/30/2009-2.0  mobrien - finish JPA Metadata API modifications in support
13
 *       of the Metamodel implementation for EclipseLink 2.0 release involving
13
 *       of the Metamodel implementation for EclipseLink 2.0 release involving
14
 *       Map, ElementCollection and Embeddable types on MappedSuperclass descriptors
14
 *       Map, ElementCollection and Embeddable types on MappedSuperclass descriptors
15
 *       - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API)  
15
 *       - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API)
16
 *     29/10/2009-2.0  mobrien - m:1 and 1:m relationships require special handling
17
 *       in their internal m:m and 1:1 database mapping representations.
18
 *       http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_96:_20091019:_Attribute.getPersistentAttributeType.28.29_treats_ManyToOne_the_same_as_OneToOne   
16
 ******************************************************************************/
19
 ******************************************************************************/
17
package org.eclipse.persistence.internal.jpa.metamodel;
20
package org.eclipse.persistence.internal.jpa.metamodel;
18
21
Lines 27-34 Link Here
27
import org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor;
30
import org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor;
28
import org.eclipse.persistence.mappings.AttributeAccessor;
31
import org.eclipse.persistence.mappings.AttributeAccessor;
29
import org.eclipse.persistence.mappings.DatabaseMapping;
32
import org.eclipse.persistence.mappings.DatabaseMapping;
33
import org.eclipse.persistence.mappings.ManyToManyMapping;
30
import org.eclipse.persistence.mappings.OneToOneMapping;
34
import org.eclipse.persistence.mappings.OneToOneMapping;
31
import org.eclipse.persistence.mappings.VariableOneToOneMapping;
32
35
33
/**
36
/**
34
 * <p>
37
 * <p>
Lines 47-59 Link Here
47
 */ 
50
 */ 
48
public abstract class AttributeImpl<X, T> implements Attribute<X, T>, Serializable {
51
public abstract class AttributeImpl<X, T> implements Attribute<X, T>, Serializable {
49
52
50
    /** the ManagedType associated with this attribute **/
53
    /** The ManagedType associated with this attribute **/
51
    private ManagedTypeImpl<X> managedType;
54
    private ManagedTypeImpl<X> managedType;
52
55
53
    /** The databaseMapping associated with this attribute **/
56
    /** The databaseMapping associated with this attribute **/
54
    private DatabaseMapping mapping;
57
    private DatabaseMapping mapping;
55
    
58
    
56
57
    /**
59
    /**
58
     * INTERNAL:
60
     * INTERNAL:
59
     * 
61
     * 
Lines 162-201 Link Here
162
     *  Return the persistent attribute type for the attribute.
164
     *  Return the persistent attribute type for the attribute.
163
     *  @return persistent attribute type
165
     *  @return persistent attribute type
164
     */
166
     */
165
    public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
167
    public Attribute.PersistentAttributeType getPersistentAttributeType() {
166
        /**
168
        /**
167
         * process the following mappings
169
         * process the following mappings by referencing the Core API Mapping.
168
         * MANY_TO_ONE
170
         * MANY_TO_ONE (ONE_TO_ONE internally)
169
         * ONE_TO_ONE
171
         * ONE_TO_ONE (May originally be a MANY_TO_ONE)
170
         * BASIC
172
         * BASIC
171
         * EMBEDDED
173
         * EMBEDDED
172
         * MANY_TO_MANY
174
         * MANY_TO_MANY (May originally be a unidirectional ONE_TO_MANY on a mappedSuperclass)
173
         * ONE_TO_MANY
175
         * ONE_TO_MANY (MANY_TO_MANY internally for unidirectional mappings on MappedSuperclasses)
174
         * ELEMENT_COLLECTION
176
         * ELEMENT_COLLECTION
175
         */
177
         */ 
176
        if (getMapping().isDirectToFieldMapping()) {
178
        if (mapping.isDirectToFieldMapping()) {
177
            return PersistentAttributeType.BASIC;
179
            return PersistentAttributeType.BASIC;
178
        }
180
        }
179
        if (getMapping().isAggregateObjectMapping()) {
181
        if (mapping.isAggregateObjectMapping()) {
180
            return PersistentAttributeType.EMBEDDED;
182
            return PersistentAttributeType.EMBEDDED;
181
        }
183
        }
182
        if (getMapping().isOneToManyMapping()) {
184
        if (mapping.isOneToManyMapping()) {
183
            return PersistentAttributeType.ONE_TO_MANY;
185
            return PersistentAttributeType.ONE_TO_MANY;
184
        }
186
        }
185
        if (getMapping().isOneToOneMapping()) {
187
186
            return PersistentAttributeType.ONE_TO_ONE;
188
        /**
189
         * EclipseLink internally processes a ONE_TO_MANY on a MappedSuperclass as a MANY_TO_MANY
190
         * because the relationship is unidirectional.
191
         */
192
        if (mapping.isManyToManyMapping()) {
193
            // Check for a OneToMany on a MappedSuperclass being processed internally as a ManyToMany
194
            if(((ManyToManyMapping)mapping).isDefinedAsOneToManyMapping()) {
195
                return PersistentAttributeType.ONE_TO_MANY;
196
            } else {
197
                // Test coverage required
198
                return PersistentAttributeType.MANY_TO_MANY;
199
            }
187
        }
200
        }
188
        // Internally we treat m:1 as 1:1 - place this before the 1:1 check
201
        
189
        // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_96:_20091019:_Attribute.getPersistentAttributeType.28.29_treats_ManyToOne_the_same_as_OneToOne
202
        /**
190
        if (getMapping().isRelationalMapping() && 
203
         * EclipseLink internally processes a MANY_TO_ONE as a ONE_TO_ONE without a FK constraint.
191
                (getMapping() instanceof OneToOneMapping || getMapping() instanceof VariableOneToOneMapping)) {
204
         */
192
            return PersistentAttributeType.MANY_TO_ONE;
205
        if (mapping.isOneToOneMapping()) {
206
            // Check for a ManyToOne being processed internally as a OneToOne
207
            if(((OneToOneMapping)mapping).isDefinedAsManyToOneMapping()) {
208
                return PersistentAttributeType.MANY_TO_ONE;
209
            } else {
210
                return PersistentAttributeType.ONE_TO_ONE;
211
            }
193
        }
212
        }
194
        // Test coverage required
213
        // Test coverage required
195
        if (getMapping().isManyToManyMapping()) {
196
            return PersistentAttributeType.MANY_TO_MANY;
197
        }
198
        // Test coverage required
199
        return PersistentAttributeType.ELEMENT_COLLECTION;
214
        return PersistentAttributeType.ELEMENT_COLLECTION;
200
    }
215
    }
201
    
216
    

Return to bug 266912