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/internal/localization/i18n/ExceptionLocalizationResource.java (-1 / +3 lines)
Lines 119-125 Link Here
119
                                           { "metamodel_identifiable_id_attribute_type_incorrect", "Expected id attribute type [{2}] on the existing id attribute [{0}] on the identifiable type [{1}] but found attribute type [{3}]." },
119
                                           { "metamodel_identifiable_id_attribute_type_incorrect", "Expected id attribute type [{2}] on the existing id attribute [{0}] on the identifiable type [{1}] but found attribute type [{3}]." },
120
                                           { "metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass", "The declared attribute [{0}] from the managed type [{1}] is not present - however, it is declared on a superclass." },
120
                                           { "metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass", "The declared attribute [{0}] from the managed type [{1}] is not present - however, it is declared on a superclass." },
121
                                           { "metamodel_managed_type_attribute_return_type_incorrect", "Expected attribute return type [{2}] on the existing attribute [{0}] on the managed type [{1}] but found attribute return type [{3}]." },
121
                                           { "metamodel_managed_type_attribute_return_type_incorrect", "Expected attribute return type [{2}] on the existing attribute [{0}] on the managed type [{1}] but found attribute return type [{3}]." },
122
                                           { "metamodel_incompatible_persistence_config_for_getIdType", "Incompatible persistence configuration getting Metamodel Id Type for the ManagedType [{0}]." }                                           
122
                                           { "metamodel_incompatible_persistence_config_for_getIdType", "Incompatible persistence configuration getting Metamodel Id Type for the ManagedType [{0}]." },
123
                                           { "metamodel_class_incorrect_type_instance", "The type [{2}] is not the expected [{1}] for the key class [{0}]." }                                           
124
                                                                                      
123
    };
125
    };
124
126
125
    /**
127
    /**
(-)foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/TraceLocalizationResource.java (-1 / +3 lines)
Lines 308-314 Link Here
308
                                            { "mbean_get_application_name", "The applicationName for the MBean attached to session [{0}] is [{1}]" },
308
                                            { "mbean_get_application_name", "The applicationName for the MBean attached to session [{0}] is [{1}]" },
309
                                            { "mbean_get_module_name", "The moduleName for the MBean attached to session [{0}] is [{1}]" },
309
                                            { "mbean_get_module_name", "The moduleName for the MBean attached to session [{0}] is [{1}]" },
310
                                            { "active_thread_is_different_from_current_thread", "Forcing the activeThread \"{0}\" on the mergeManager \"{1}\" to be the currentThread \"{2}\" because they are different." },
310
                                            { "active_thread_is_different_from_current_thread", "Forcing the activeThread \"{0}\" on the mergeManager \"{1}\" to be the currentThread \"{2}\" because they are different." },
311
                                            { "dead_lock_encountered_on_write_no_cachekey", "Potential deadlock encountered while thread: {2} attempted to lock object of class: {0} with id: {1}, entering deadlock avoidance algorithm.  This is a notice only."},                                            
311
                                            { "dead_lock_encountered_on_write_no_cachekey", "Potential deadlock encountered while thread: {2} attempted to lock object of class: {0} with id: {1}, entering deadlock avoidance algorithm.  This is a notice only."},
312
                                            { "metamodel_attribute_class_type_is_null", "The class type is null for the attribute: {0}" },
313
                                            { "metamodel_mapping_type_is_unsupported", "The mapping type [{0}] in the attribute [{1} is unsupported by this metamodel implementation." }
312
    };
314
    };
313
315
314
    /**
316
    /**
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Designer.java (-1 / +21 lines)
Lines 15-30 Link Here
15
 ******************************************************************************/  
15
 ******************************************************************************/  
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
17
17
18
import static javax.persistence.CascadeType.ALL;
18
import static javax.persistence.FetchType.EAGER;
19
import static javax.persistence.FetchType.EAGER;
19
20
21
import java.util.Collection;
22
import java.util.HashSet;
23
20
import javax.persistence.JoinColumn;
24
import javax.persistence.JoinColumn;
25
import javax.persistence.JoinTable;
21
import javax.persistence.ManyToOne;
26
import javax.persistence.ManyToOne;
22
import javax.persistence.MappedSuperclass;
27
import javax.persistence.MappedSuperclass;
28
import javax.persistence.OneToMany;
23
import javax.persistence.OneToOne;
29
import javax.persistence.OneToOne;
24
30
25
@MappedSuperclass
31
@MappedSuperclass
26
public abstract class Designer extends Person {
32
public abstract class Designer extends Person {
27
33
34
    // Verify special handling for PK for OneToMany (custom descriptor with fake PK name)
35
    // If a JoinTable with a JoinColumn is used - then we need a mappedBy on the inverse side here
36
    // However, bidirectional relationships are not allowed to MappedSuperclasses - as they have no identity
37
    @OneToMany(fetch=EAGER, cascade=ALL)
38
    @JoinTable(name="CMP3_MM_HIST_EMPLOY", 
39
                joinColumns = @JoinColumn(name="PERSON_ID"))   
40
    private Collection<Manufacturer> historicalEmployers = new HashSet<Manufacturer>();    
41
    
28
    // The M:1 side is the owning side - but this is a unidirectional mapping
42
    // The M:1 side is the owning side - but this is a unidirectional mapping
29
    // The ManyToOne will resolve to a OneToOne internally without a unique PK restriction
43
    // The ManyToOne will resolve to a OneToOne internally without a unique PK restriction
30
    @ManyToOne(fetch=EAGER)//LAZY)
44
    @ManyToOne(fetch=EAGER)//LAZY)
Lines 56-60 Link Here
56
        this.secondaryEmployer = employer;
70
        this.secondaryEmployer = employer;
57
    }
71
    }
58
    
72
    
59
    
73
    public Collection<Manufacturer> getHistoricalEmployers() {
74
        return historicalEmployers;
75
    }
76
77
    public void setHistoricalEmployers(Collection<Manufacturer> historicalEmployers) {
78
        this.historicalEmployers = historicalEmployers;
79
    }
60
}
80
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-283 / +747 lines)
Lines 27-48 Link Here
27
import javax.persistence.EntityManager;
27
import javax.persistence.EntityManager;
28
import javax.persistence.EntityManagerFactory;
28
import javax.persistence.EntityManagerFactory;
29
import javax.persistence.Query;
29
import javax.persistence.Query;
30
import javax.persistence.Tuple;
31
import javax.persistence.TypedQuery;
32
import javax.persistence.criteria.CriteriaQuery;
30
import javax.persistence.criteria.CriteriaQuery;
33
import javax.persistence.criteria.Join;
34
import javax.persistence.criteria.ParameterExpression;
35
import javax.persistence.criteria.Path;
31
import javax.persistence.criteria.Path;
36
import javax.persistence.criteria.QueryBuilder;
32
import javax.persistence.criteria.QueryBuilder;
37
import javax.persistence.criteria.Root;
33
import javax.persistence.criteria.Root;
38
import javax.persistence.metamodel.Attribute;
34
import javax.persistence.metamodel.Attribute;
35
import javax.persistence.metamodel.Bindable;
39
import javax.persistence.metamodel.CollectionAttribute;
36
import javax.persistence.metamodel.CollectionAttribute;
37
import javax.persistence.metamodel.EmbeddableType;
38
import javax.persistence.metamodel.EntityType;
40
import javax.persistence.metamodel.IdentifiableType;
39
import javax.persistence.metamodel.IdentifiableType;
41
import javax.persistence.metamodel.ListAttribute;
40
import javax.persistence.metamodel.ListAttribute;
42
import javax.persistence.metamodel.MapAttribute;
41
import javax.persistence.metamodel.ManagedType;
43
import javax.persistence.metamodel.Metamodel;
42
import javax.persistence.metamodel.Metamodel;
44
import javax.persistence.metamodel.PluralAttribute;
43
import javax.persistence.metamodel.PluralAttribute;
45
import javax.persistence.metamodel.SetAttribute;
46
import javax.persistence.metamodel.SingularAttribute;
44
import javax.persistence.metamodel.SingularAttribute;
47
import javax.persistence.metamodel.Type;
45
import javax.persistence.metamodel.Type;
48
import javax.persistence.metamodel.Type.PersistenceType;
46
import javax.persistence.metamodel.Type.PersistenceType;
Lines 50-85 Link Here
50
import junit.framework.Test;
48
import junit.framework.Test;
51
import junit.framework.TestSuite;
49
import junit.framework.TestSuite;
52
50
53
import org.eclipse.persistence.config.CacheUsage;
54
import org.eclipse.persistence.config.QueryHints;
55
import org.eclipse.persistence.descriptors.RelationalDescriptor;
51
import org.eclipse.persistence.descriptors.RelationalDescriptor;
56
import org.eclipse.persistence.expressions.Expression;
52
import org.eclipse.persistence.expressions.Expression;
57
import org.eclipse.persistence.internal.expressions.ClassTypeExpression;
53
import org.eclipse.persistence.internal.expressions.ClassTypeExpression;
54
import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl;
55
import org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl;
56
import org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTypeImpl;
58
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl;
57
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl;
58
import org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl;
59
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl;
59
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl;
60
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
60
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
61
import org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl;
61
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
62
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
62
import org.eclipse.persistence.internal.jpa.querydef.ExpressionImpl;
63
import org.eclipse.persistence.internal.jpa.querydef.SelectionImpl;
64
import org.eclipse.persistence.mappings.DatabaseMapping;
63
import org.eclipse.persistence.mappings.DatabaseMapping;
65
import org.eclipse.persistence.testing.framework.QuerySQLTracker;
64
import org.eclipse.persistence.sessions.DatabaseRecord;
66
import org.eclipse.persistence.testing.models.jpa.advanced.Address;
65
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
67
import org.eclipse.persistence.testing.models.jpa.advanced.Employee;
68
import org.eclipse.persistence.testing.models.jpa.metamodel.Board;
66
import org.eclipse.persistence.testing.models.jpa.metamodel.Board;
69
import org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK;
70
import org.eclipse.persistence.testing.models.jpa.metamodel.Computer;
67
import org.eclipse.persistence.testing.models.jpa.metamodel.Computer;
71
import org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK;
68
import org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK;
72
import org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner;
69
import org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner;
73
import org.eclipse.persistence.testing.models.jpa.metamodel.Location;
70
import org.eclipse.persistence.testing.models.jpa.metamodel.Location;
74
import org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer;
71
import org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer;
75
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory;
72
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory;
73
import org.eclipse.persistence.testing.models.jpa.metamodel.Person;
76
import org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner;
74
import org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner;
77
import org.eclipse.persistence.testing.models.jpa.metamodel.User;
75
import org.eclipse.persistence.testing.models.jpa.metamodel.User;
78
import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor;
76
import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor;
79
77
80
/**
78
/**
81
 * Disclaimer:
79
 * Disclaimer:
82
 *    Yes I know the following are true for this test suite - but implementation time must be ""triaged"", and this testing code is at the bottom of the list when placed against actual implementation in the time provided.
80
 *    Yes, the following are true for this test suite - but implementation time must be ""triaged"", and this testing code is at the bottom of the list when placed against actual implementation in the time provided.
83
 *    - Tests must be modular - not one big huge test case that either passes or fails - it is better to have 10's of granular failures instead of only 1
81
 *    - Tests must be modular - not one big huge test case that either passes or fails - it is better to have 10's of granular failures instead of only 1
84
 *    - proper and fully optimized test cases
82
 *    - proper and fully optimized test cases
85
 *    - full exception handling
83
 *    - full exception handling
Lines 123-128 Link Here
123
    
121
    
124
    public void setUp() {
122
    public void setUp() {
125
        super.setUp();
123
        super.setUp();
124
        // Drop all tables : Thank you Chris
125
        /*java.util.Vector v = JUnitTestCase.getServerSession("metamodel1").executeSQL("select tablename from sys.systables where tabletype='T'");
126
        for (int i=0; i<v.size(); i++){
127
            try{
128
                DatabaseRecord dr = (DatabaseRecord)v.get(i);
129
                JUnitTestCase.getServerSession().executeNonSelectingSQL("Drop table "+dr.getValues().get(0));
130
            } catch (Exception e){
131
                System.out.println(e);
132
            }
133
        }*/        
134
        /*JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_HIST_EMPLOY");
135
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_HWDES_MAP");
136
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_CORPCOMPUTER");
137
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_COMPUTER");
138
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF_MM_HWDESIGNER");
139
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_MM_MEMORY");
140
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_MM_PRO");
141
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_COMPUTER_MM_USER");
142
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD_SEQ");
143
144
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_COMPUTER");
145
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_USER");
146
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_HWDESIGNER");
147
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MEMORY");
148
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_PROC");
149
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_LOCATION");
150
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_BOARD");
151
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_SWDESIGNER");
152
        JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME).executeNonSelectingSQL("DROP TABLE CMP3_MM_MANUF");
153
        */        
126
    }
154
    }
127
    
155
    
128
    public static Test suite() {
156
    public static Test suite() {
Lines 130-387 Link Here
130
158
131
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelStringBasedQuery"));
159
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelStringBasedQuery"));
132
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelTypeSafeBasedQuery"));
160
        //suite.addTest(new MetamodelMetamodelTest("testMetamodelTypeSafeBasedQuery"));
133
        suite.addTest(new MetamodelMetamodelTest("testImplementation"));
161
        suite.addTest(new MetamodelMetamodelTest("testMetamodelFullImplementation"));
134
        return suite;
162
        return suite;
135
    }
163
    }
136
164
137
    /**
165
    /**
138
     * Test the Metamodel API using a TypeSafe query via the Criteria API (a user of the Metamodel)
166
     * The following large single test case contains signatures of all the spec functions.
167
     * Those that have a test are implemented, the missing ones may still be in development.
139
     */
168
     */
140
    public void testMetamodelTypeSafeBasedQuery() {
169
    public void testMetamodelFullImplementation() {
141
        EntityManagerFactory emf = null;
170
        EntityManagerFactory emf = null;
142
        EntityManager em = null;
171
        EntityManager em = null;
143
        
144
        Set<Computer> computersList = new HashSet();
145
        List<Memory> memories = new ArrayList();
146
        List<VectorProcessor> processors = new ArrayList();
147
        List<HardwareDesigner> hardwareDesigners = new ArrayList();
148
        Computer computer1 = null;
149
        Computer computer2 = null;
150
        Manufacturer manufacturer = null;
151
        User user = null;
152
        HardwareDesigner hardwareDesigner1 = null;
153
        SoftwareDesigner softwareDesigner1 = null;
154
        VectorProcessor vectorProcessor1 = null;
155
        Board board1 = null;
156
        Memory memory1 = null;
157
        Memory memory2 = null;
158
        Location location1 = null;
159
        Location location2 = null;        
160
        boolean exceptionThrown = false;
161
        Metamodel metamodel = null;
162
163
        try {
164
            emf = initialize();
165
            em = emf.createEntityManager();
166
            em.getTransaction().begin();
167
168
            // setup entity relationships
169
            computer1 = new Computer();
170
            computer2 = new Computer();
171
            memory1 = new Memory();
172
            memory2 = new Memory();
173
            manufacturer = new Manufacturer();
174
            user = new User();
175
            hardwareDesigner1 = new HardwareDesigner();
176
            softwareDesigner1 = new SoftwareDesigner();
177
            vectorProcessor1 = new VectorProcessor();
178
            board1 = new Board();
179
            location1 = new Location();
180
            location2 = new Location();        
181
182
            // setup collections
183
            computersList.add(computer1);
184
            computersList.add(computer2);
185
            processors.add(vectorProcessor1);
186
            memories.add(memory1);
187
            memories.add(memory2);
188
            hardwareDesigners.add(hardwareDesigner1);
189
190
            // set owning and inverse sides of 1:m and m:1 relationships
191
            manufacturer.setComputers(computersList);
192
            manufacturer.setHardwareDesigners(hardwareDesigners);
193
            hardwareDesigner1.setEmployer(manufacturer);
194
            hardwareDesigner1.setPrimaryEmployer(manufacturer);
195
            hardwareDesigner1.setSecondaryEmployer(manufacturer);
196
            computer1.setManufacturer(manufacturer);
197
            computer2.setManufacturer(manufacturer);
198
            board1.setMemories(memories);
199
            memory1.setBoard(board1);
200
            memory2.setBoard(board1);
201
            board1.setProcessors(processors);
202
            vectorProcessor1.setBoard(board1);            
203
            softwareDesigner1.setPrimaryEmployer(manufacturer);
204
            softwareDesigner1.setSecondaryEmployer(manufacturer);
205
            
206
            // set 1:1 relationships
207
            computer1.setLocation(location1);
208
            computer2.setLocation(location2);
209
            
210
            // set attributes
211
            computer1.setName("CDC-6600");
212
            computer2.setName("CM-5");
213
            
214
            // persist all entities to the database in a single transaction
215
            em.persist(computer1);
216
            em.persist(computer2);
217
            em.persist(manufacturer);
218
            em.persist(user);
219
            em.persist(hardwareDesigner1);
220
            em.persist(softwareDesigner1);
221
            em.persist(vectorProcessor1);
222
            em.persist(board1);
223
            em.persist(memory1);
224
            em.persist(memory2);
225
            em.persist(location1);
226
            em.persist(location2);        
227
            
228
            em.getTransaction().commit();            
229
            
230
            // get Metamodel representation of the entity schema
231
            metamodel = em.getMetamodel();
232
            assertNotNull(metamodel);
233
234
            // Setup TypeSafe Criteria API query  
235
            QueryBuilder aQueryBuilder = em.getQueryBuilder();
236
            // Setup a query to get a list (the JPA 1.0 way) and compare it to the (JPA 2.0 way)
237
            // avoid a NPE on .where in query.setExpressionBuilder(((ExpressionImpl)this.where).getCurrentNode().getBuilder());
238
            //TypedQuery<Computer> aManufacturerQuery = em.createQuery(aQueryBuilder.createQuery(Computer.class));
239
            Query aManufacturerQuery = em.createQuery(aQueryBuilder.createQuery(Computer.class));
240
            List<Computer> computersResultsList = aManufacturerQuery.getResultList();
241
            Computer aComputer = (Computer)computersResultsList.get(0);
242
/*
243
            // Get the primary key of the Computer
244
            CriteriaQuery<Tuple> aCriteriaQuery = aQueryBuilder.createQuery(Tuple.class);
245
            Root from = cq.from(Employee.class);
246
            cq.multiselect(from.get("id"), from.get("firstName"));
247
            cq.where(qb.equal(from.get("id"), qb.parameter(from.get("id").getModel().getBindableJavaType(), "id")).add(qb.equal(from.get("firstName"), qb.parameter(from.get("firstName").getModel().getBindableJavaType(), "firstName"))));
248
            TypedQuery<Tuple> typedQuery = em.createQuery(cq);
249
250
            typedQuery.setParameter("id", employee.getId());
251
            typedQuery.setParameter("firstName", employee.getFirstName());
252
253
            Tuple queryResult = typedQuery.getSingleResult();
254
            assertTrue("Query Results do not match selection", queryResult.get(0).equals(employee.getId()) && queryResult.get(1).equals(employee.getFirstName()));
255
*/            
256
        } catch (Exception e) {
257
            // we enter here on a failed commit() - for example if the table schema is incorrectly defined
258
            e.printStackTrace();
259
            exceptionThrown = true;
260
        } finally {
261
            assertFalse(exceptionThrown);
262
            //finalizeForTest(em, entityMap);
263
            if(null != em) {
264
                cleanup(em);
265
            }
266
        }
267
    }
268
    
269
    /**
270
     * Test the Metamodel API or lack of using it via a Criteria API using string based queries
271
     */
272
    public void testMetamodelStringBasedQuery() {
273
        EntityManagerFactory emf = null;
274
        EntityManager em = null;
275
        Set<Computer> computersList = new HashSet();
276
        List<Memory> memories = new ArrayList();
277
        List<VectorProcessor> processors = new ArrayList();
278
        List<HardwareDesigner> hardwareDesigners = new ArrayList();
279
        Computer computer1 = null;
280
        Computer computer2 = null;
281
        Manufacturer manufacturer = null;
282
        User user = null;
283
        HardwareDesigner hardwareDesigner1 = null;
284
        SoftwareDesigner softwareDesigner1 = null;
285
        VectorProcessor vectorProcessor1 = null;
286
        //ArrayProcessor arrayProcessor1 = null;
287
        Board board1 = null;
288
        Memory memory1 = null;
289
        Memory memory2 = null;
290
        Location location1 = null;
291
        Location location2 = null;        
292
        boolean exceptionThrown = false;
293
        Metamodel metamodel = null;
294
295
        try {
296
            emf = initialize();
297
            em = emf.createEntityManager();
298
            em.getTransaction().begin();
299
300
            // setup entity relationships
301
            computer1 = new Computer();
302
            computer2 = new Computer();
303
            memory1 = new Memory();
304
            memory2 = new Memory();
305
            manufacturer = new Manufacturer();
306
            user = new User();
307
            hardwareDesigner1 = new HardwareDesigner();
308
            softwareDesigner1 = new SoftwareDesigner();
309
            vectorProcessor1 = new VectorProcessor();
310
            board1 = new Board();
311
            location1 = new Location();
312
            location2 = new Location();        
313
314
            // setup collections
315
            computersList.add(computer1);
316
            computersList.add(computer2);
317
            processors.add(vectorProcessor1);
318
            memories.add(memory1);
319
            memories.add(memory2);
320
            hardwareDesigners.add(hardwareDesigner1);
321
322
            // set owning and inverse sides of 1:m and m:1 relationships
323
            manufacturer.setComputers(computersList);
324
            manufacturer.setHardwareDesigners(hardwareDesigners);
325
            hardwareDesigner1.setEmployer(manufacturer);
326
            hardwareDesigner1.setPrimaryEmployer(manufacturer);
327
            hardwareDesigner1.setSecondaryEmployer(manufacturer);
328
            computer1.setManufacturer(manufacturer);
329
            computer2.setManufacturer(manufacturer);
330
            board1.setMemories(memories);
331
            memory1.setBoard(board1);
332
            memory2.setBoard(board1);
333
            board1.setProcessors(processors);
334
            vectorProcessor1.setBoard(board1);            
335
            softwareDesigner1.setPrimaryEmployer(manufacturer);
336
            softwareDesigner1.setSecondaryEmployer(manufacturer);
337
            
338
            // set 1:1 relationships
339
            computer1.setLocation(location1);
340
            computer2.setLocation(location2);
341
            
342
            // set attributes
343
            computer1.setName("CDC-6600");
344
            computer2.setName("CM-5");
345
            
346
            // persist all entities to the database in a single transaction
347
            em.persist(computer1);
348
            em.persist(computer2);
349
            em.persist(manufacturer);
350
            em.persist(user);
351
            em.persist(hardwareDesigner1);
352
            em.persist(softwareDesigner1);
353
            em.persist(vectorProcessor1);
354
            //em.persist(arrayProcessor1);
355
            em.persist(board1);
356
            em.persist(memory1);
357
            em.persist(memory2);
358
            em.persist(location1);
359
            em.persist(location2);        
360
            
361
            em.getTransaction().commit();            
362
            
363
            // get Metamodel representation of the entity schema
364
            metamodel = em.getMetamodel();
365
            assertNotNull(metamodel);
366
367
            // Setup a non TypeSafe Criteria API query
368
            
369
        } catch (Exception e) {
370
            // we enter here on a failed commit() - for example if the table schema is incorrectly defined
371
            e.printStackTrace();
372
            exceptionThrown = true;
373
        } finally {
374
            assertFalse(exceptionThrown);
375
            //finalizeForTest(em, entityMap);
376
            if(null != em) {
377
                cleanup(em);
378
            }
379
        }
380
    }
381
    
382
    public void testImplementation() {
383
        EntityManagerFactory emf = null;
384
        EntityManager em = null;
385
        Set<Computer> computersList = new HashSet<Computer>();
172
        Set<Computer> computersList = new HashSet<Computer>();
386
        Collection<Memory> memories = new HashSet<Memory>();
173
        Collection<Memory> memories = new HashSet<Memory>();
387
        Collection<VectorProcessor> processors = new HashSet<VectorProcessor>();
174
        Collection<VectorProcessor> processors = new HashSet<VectorProcessor>();
Lines 410-421 Link Here
410
197
411
        try {
198
        try {
412
            emf = initialize();
199
            emf = initialize();
413
            //emf = initialize();
414
            em = emf.createEntityManager();
200
            em = emf.createEntityManager();
415
201
202
            // Unset the metamodel - for repeated runs through this test
203
            ((EntityManagerFactoryImpl)emf).setMetamodel(null);
416
            // Pre-Persist: get Metamodel representation of the entity schema
204
            // Pre-Persist: get Metamodel representation of the entity schema
417
            metamodel = em.getMetamodel();
205
            metamodel = em.getMetamodel();
418
            assertNotNull(metamodel);
206
            assertNotNull(metamodel);
207
            //System.out.println("_Metamodel just after initialization: " + metamodel);
419
208
420
            em.getTransaction().begin();
209
            em.getTransaction().begin();
421
210
Lines 541-554 Link Here
541
                EntityTypeImpl<Computer> entityComputer2 = (EntityTypeImpl)metamodel.entity(Computer.class);                
330
                EntityTypeImpl<Computer> entityComputer2 = (EntityTypeImpl)metamodel.entity(Computer.class);                
542
                Root from = criteriaQuery.from(entityComputer2);
331
                Root from = criteriaQuery.from(entityComputer2);
543
                Path path = from.get("name");
332
                Path path = from.get("name");
544
                criteriaQuery.where(qb.equal(path, "CM-5"));
333
                criteriaQuery.where(qb.equal(path, "CM-5"));  
545
                Query query = em.createQuery(criteriaQuery);
334
                Query query = em.createQuery(criteriaQuery);
546
                results = query.getResultList();
335
                results = query.getResultList();
547
                if(results.size() > 0) {
336
                if(results.size() > 0) {
548
                    Computer computer = (Computer)results.get(0);
337
                    Computer computer = (Computer)results.get(0);
549
                    assertNotNull(computer);
338
                    assertNotNull(computer);
550
                } else {
339
                } else {
551
                    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");
340
                    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");
552
                }
341
                }
553
            } catch (Exception e) {
342
            } catch (Exception e) {
554
                e.printStackTrace();
343
                e.printStackTrace();
Lines 716-722 Link Here
716
             *  Return the type that represents the type of the id.
505
             *  Return the type that represents the type of the id.
717
             *  @return type of id
506
             *  @return type of id
718
             */
507
             */
719
            //Type<?> getIdType();            
508
            //Type<?> getIdType();       
509
            
510
            // Test EntityType
511
            
720
            // Test normal path for an [Embeddable] type via @EmbeddedId
512
            // Test normal path for an [Embeddable] type via @EmbeddedId
721
            expectedIAExceptionThrown = false;
513
            expectedIAExceptionThrown = false;
722
            Type<?> locationIdType = null;
514
            Type<?> locationIdType = null;
Lines 732-738 Link Here
732
            assertEquals(PersistenceType.EMBEDDABLE, locationIdType.getPersistenceType());
524
            assertEquals(PersistenceType.EMBEDDABLE, locationIdType.getPersistenceType());
733
            assertEquals(EmbeddedPK.class, locationIdType.getJavaType());
525
            assertEquals(EmbeddedPK.class, locationIdType.getJavaType());
734
526
527
            // check that the elementType and the owningType (managedType) are set correctly
528
            // See issue 50 where some mapping types were not setting the elementType correctly (this includes aggregate types like Embeddable)
529
            // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_50:_20090727:_Handle_all_mapping_types_in_the_SingularAttribute_constructor
530
            // Get the ManagedType and check this SingularAttribute PK
531
            Attribute locationIdAttribute = entityLocation.getAttribute("primaryKey");
532
            assertNotNull(locationIdAttribute);
533
            assertTrue(locationIdAttribute instanceof SingularAttributeImpl);
534
            assertFalse(locationIdAttribute.isCollection());
535
            assertFalse(((AttributeImpl)locationIdAttribute).isPlural()); // non-spec.
536
            ManagedType locationIdAttributeManagedType = locationIdAttribute.getDeclaringType();
537
            assertEquals(entityLocation, locationIdAttributeManagedType);
538
            ManagedTypeImpl locationIdAttributeManagedTypeImpl = ((SingularAttributeImpl)locationIdAttribute).getManagedTypeImpl();
539
            assertEquals(locationIdType.getJavaType(), ((SingularAttributeImpl)locationIdAttribute).getBindableJavaType());
540
            assertEquals(Bindable.BindableType.SINGULAR_ATTRIBUTE, ((SingularAttributeImpl)locationIdAttribute).getBindableType());
541
            assertEquals(locationIdType.getJavaType(), locationIdAttribute.getJavaType());
542
            Type embeddableType = ((SingularAttributeImpl)locationIdAttribute).getType();
543
            assertNotNull(embeddableType);
544
            assertNotSame(embeddableType, locationIdAttributeManagedType);
545
            
735
546
547
736
            // Test normal path for a [Basic] type
548
            // Test normal path for a [Basic] type
737
            expectedIAExceptionThrown = false;
549
            expectedIAExceptionThrown = false;
738
            Type<?> computerIdType = null;
550
            Type<?> computerIdType = null;
Lines 749-758 Link Here
749
            assertEquals(Integer.class, computerIdType.getJavaType());
561
            assertEquals(Integer.class, computerIdType.getJavaType());
750
562
751
            
563
            
564
            
565
            // Test MappedSuperclassType
566
            // Test normal path for a [Basic] type
567
            expectedIAExceptionThrown = false;
568
            Type<?> personIdType = null;
569
            MappedSuperclassTypeImpl<Person> msPerson = (MappedSuperclassTypeImpl)metamodel.type(Person.class);
570
            assertNotNull(msPerson);
571
            
572
            try {
573
                personIdType = msPerson.getIdType();
574
            } catch (IllegalArgumentException iae) {
575
                // expecting no exception
576
                iae.printStackTrace();
577
                expectedIAExceptionThrown = true;            
578
            }
579
            assertFalse(expectedIAExceptionThrown);
580
            assertNotNull(personIdType);
581
            assertEquals(PersistenceType.BASIC, personIdType.getPersistenceType());
582
            assertEquals(Integer.class, personIdType.getJavaType());
583
            
752
            // Verify all types (entities, embeddables, mappedsuperclasses and basic)
584
            // Verify all types (entities, embeddables, mappedsuperclasses and basic)
753
            try {
585
            try {
754
                // get all 19 types (a non spec function - for testing introspection)
586
                // get all 19 types (a non spec function - for testing introspection)
755
                Map<Class, TypeImpl<?>> typesMap = ((MetamodelImpl)metamodel).getTypes();
587
                Map<Class, TypeImpl<?>> typesMap = ((MetamodelImpl)metamodel).getTypes();
588
                System.out.println("_MetamodelMetamodelTest: all Types: " + typesMap);
756
                // verify each one
589
                // verify each one
757
                assertNotNull(typesMap);
590
                assertNotNull(typesMap);
758
                assertEquals(19, typesMap.size());
591
                assertEquals(19, typesMap.size());
Lines 760-784 Link Here
760
                e.printStackTrace();
593
                e.printStackTrace();
761
            }
594
            }
762
            /*
595
            /*
763
            {class org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner --> [DatabaseTable(CMP3_MM_SWDESIGNER)])], 
596
             * Metamodel model toString
764
                class org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK --> [])], 
597
             * ************************************************************************************
765
                class org.eclipse.persistence.testing.models.jpa.metamodel.User=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.User --> [DatabaseTable(CMP3_MM_USER)])], 
598
    class org.eclipse.persistence.testing.models.jpa.metamodel.Person=MappedSuperclassTypeImpl@9206757 [ 
766
                class org.eclipse.persistence.testing.models.jpa.metamodel.Location=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Location --> [DatabaseTable(CMP3_MM_LOCATION)])], 
599
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Person 
767
                class org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK --> [])], 
600
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Person --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
768
                class org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor --> [DatabaseTable(CMP3_MM_ARRAYPROC)])], 
601
        mappings: [
769
                class org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)])], 
602
            org.eclipse.persistence.mappings.DirectToFieldMapping[
770
                class org.eclipse.persistence.testing.models.jpa.metamodel.Memory=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Memory --> [DatabaseTable(CMP3_MM_MEMORY)])], 
603
                id-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.PERSON_ID], 
771
                class org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor --> [DatabaseTable(CMP3_MM_PROC)])], 
604
            org.eclipse.persistence.mappings.DirectToFieldMapping[
772
                class org.eclipse.persistence.testing.models.jpa.metamodel.Board=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Board --> [DatabaseTable(CMP3_MM_BOARD)])], 
605
                name-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.NAME]]],
773
                class org.eclipse.persistence.testing.models.jpa.metamodel.Computer=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Computer --> [DatabaseTable(CMP3_MM_COMPUTER)])], 
606
    class org.eclipse.persistence.testing.models.jpa.metamodel.Corporation=MappedSuperclassTypeImpl@27921979 [ 
774
                class org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner=ManagedTypeImpl[RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner --> [DatabaseTable(CMP3_MM_HWDESIGNER)])], 
607
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Corporation 
775
                class org.eclipse.persistence.testing.models.jpa.metamodel.Corporation=MappedSuperclassTypeImpl@24202381 [descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Corporation --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), mappings: [org.eclipse.persistence.mappings.ManyToManyMapping[corporateComputers]]], 
608
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Corporation --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
776
                class org.eclipse.persistence.testing.models.jpa.metamodel.Designer=MappedSuperclassTypeImpl@22595578 [descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Designer --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), mappings: [org.eclipse.persistence.mappings.OneToOneMapping[secondaryEmployer], org.eclipse.persistence.mappings.OneToOneMapping[primaryEmployer]]], 
609
        mappings: [
777
                class org.eclipse.persistence.testing.models.jpa.metamodel.Processor=MappedSuperclassTypeImpl@28381082 [descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Processor --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), mappings: []], 
610
            org.eclipse.persistence.mappings.ManyToManyMapping[corporateComputers]]], 
778
                class org.eclipse.persistence.testing.models.jpa.metamodel.Person=MappedSuperclassTypeImpl@24600030 [descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Person --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), mappings: [org.eclipse.persistence.mappings.DirectToFieldMapping[id-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.PERSON_ID], org.eclipse.persistence.mappings.DirectToFieldMapping[name-->__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME.NAME]]], 
611
    class org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer=EntityTypeImpl@12565475 [ 
779
                class java.lang.Integer=org.eclipse.persistence.internal.jpa.metamodel.BasicTypeImpl@1b7e37, 
612
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer 
780
                class java.lang.String=org.eclipse.persistence.internal.jpa.metamodel.BasicTypeImpl@fb541d, 
613
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer --> [DatabaseTable(CMP3_MM_MANUF)]), 
781
                int=org.eclipse.persistence.internal.jpa.metamodel.BasicTypeImpl@4f5403}
614
        mappings: [
615
            org.eclipse.persistence.mappings.DirectToFieldMapping[
616
                id-->CMP3_MM_MANUF.PERSON_ID], 
617
            org.eclipse.persistence.mappings.DirectToFieldMapping[
618
                name-->CMP3_MM_MANUF.NAME], 
619
            org.eclipse.persistence.mappings.DirectToFieldMapping[
620
                version-->CMP3_MM_MANUF.MANUF_VERSION], 
621
            org.eclipse.persistence.mappings.OneToManyMapping[
622
                computers], 
623
            org.eclipse.persistence.mappings.OneToManyMapping[
624
                hardwareDesignersMap], 
625
            org.eclipse.persistence.mappings.ManyToManyMapping[
626
                corporateComputers], 
627
            org.eclipse.persistence.mappings.OneToManyMapping[
628
                hardwareDesigners]]], 
629
    class org.eclipse.persistence.testing.models.jpa.metamodel.Memory=EntityTypeImpl@29905988 [ 
630
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Memory 
631
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Memory --> [DatabaseTable(CMP3_MM_MEMORY)]), 
632
        mappings: [
633
            org.eclipse.persistence.mappings.DirectToFieldMapping[
634
                id-->CMP3_MM_MEMORY.MEMORY_ID], 
635
            org.eclipse.persistence.mappings.DirectToFieldMapping[
636
                version-->CMP3_MM_MEMORY.MEMORY_VERSION], 
637
            org.eclipse.persistence.mappings.OneToOneMapping[
638
                board]]], 
639
    class org.eclipse.persistence.testing.models.jpa.metamodel.Designer=MappedSuperclassTypeImpl@25971327 [ 
640
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Designer 
641
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Designer --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
642
        mappings: [
643
            org.eclipse.persistence.mappings.OneToOneMapping[
644
                secondaryEmployer], 
645
            org.eclipse.persistence.mappings.OneToOneMapping[
646
                primaryEmployer], 
647
            org.eclipse.persistence.mappings.ManyToManyMapping[
648
                historicalEmployers]]], 
649
    class org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner=EntityTypeImpl@18107298 [ 
650
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner 
651
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.HardwareDesigner --> [DatabaseTable(CMP3_MM_HWDESIGNER)]), 
652
        mappings: [
653
            org.eclipse.persistence.mappings.DirectToFieldMapping[
654
                id-->CMP3_MM_HWDESIGNER.PERSON_ID], 
655
            org.eclipse.persistence.mappings.DirectToFieldMapping[
656
                name-->CMP3_MM_HWDESIGNER.NAME], 
657
            org.eclipse.persistence.mappings.DirectToFieldMapping[
658
                version-->CMP3_MM_HWDESIGNER.HWDESIGNER_VERSION], 
659
            org.eclipse.persistence.mappings.OneToOneMapping[
660
                employer], 
661
            org.eclipse.persistence.mappings.OneToOneMapping[
662
                mappedEmployer], 
663
            org.eclipse.persistence.mappings.ManyToManyMapping[
664
                historicalEmployers], 
665
            org.eclipse.persistence.mappings.OneToOneMapping[
666
                secondaryEmployer], 
667
            org.eclipse.persistence.mappings.OneToOneMapping[
668
                primaryEmployer]]], 
669
    class org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner=EntityTypeImpl@26130360 [ 
670
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner 
671
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner --> [DatabaseTable(CMP3_MM_SWDESIGNER)]), 
672
        mappings: [
673
            org.eclipse.persistence.mappings.DirectToFieldMapping[
674
                id-->CMP3_MM_SWDESIGNER.PERSON_ID], 
675
            org.eclipse.persistence.mappings.DirectToFieldMapping[
676
                name-->CMP3_MM_SWDESIGNER.NAME], 
677
            org.eclipse.persistence.mappings.DirectToFieldMapping[
678
                version-->CMP3_MM_SWDESIGNER.SWDESIGNER_VERSION], 
679
            org.eclipse.persistence.mappings.OneToOneMapping[
680
                secondaryEmployer], 
681
            org.eclipse.persistence.mappings.OneToOneMapping[
682
                primaryEmployer], 
683
            org.eclipse.persistence.mappings.ManyToManyMapping[
684
                historicalEmployers]]], 
685
    class org.eclipse.persistence.testing.models.jpa.metamodel.Board=EntityTypeImpl@24223536 [ 
686
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Board 
687
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Board --> [DatabaseTable(CMP3_MM_BOARD)]), 
688
        mappings: [
689
            org.eclipse.persistence.mappings.DirectToFieldMapping[
690
                id-->CMP3_MM_BOARD.BOARD_ID], 
691
            org.eclipse.persistence.mappings.DirectToFieldMapping[
692
                version-->CMP3_MM_BOARD.BOARD_VERSION], 
693
            org.eclipse.persistence.mappings.OneToManyMapping[
694
                memories], 
695
            org.eclipse.persistence.mappings.OneToManyMapping[
696
                processors]]], 
697
    class org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK=EmbeddableTypeImpl@29441291 [ 
698
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK descriptor: 
699
        RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK --> []), 
700
        mappings: [
701
            org.eclipse.persistence.mappings.DirectToFieldMapping[
702
                pk_part1-->LOCATION_ID]]], 
703
    class org.eclipse.persistence.testing.models.jpa.metamodel.Location=EntityTypeImpl@9050487 [ 
704
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Location 
705
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Location --> [DatabaseTable(CMP3_MM_LOCATION)]), 
706
        mappings: [
707
            org.eclipse.persistence.mappings.DirectToFieldMapping[
708
                version-->CMP3_MM_LOCATION.LOCATION_VERSION], 
709
            org.eclipse.persistence.mappings.AggregateObjectMapping[
710
                primaryKey]]], 
711
    class org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor=EntityTypeImpl@9300338 [ 
712
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor 
713
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor --> [DatabaseTable(CMP3_MM_PROC)]), 
714
        mappings: [
715
            org.eclipse.persistence.mappings.DirectToFieldMapping[
716
                id-->CMP3_MM_PROC.VECTPROC_ID], 
717
            org.eclipse.persistence.mappings.DirectToFieldMapping[
718
                version-->CMP3_MM_PROC.VECTPROC_VERSION], 
719
            org.eclipse.persistence.mappings.OneToOneMapping[
720
                board]]], 
721
    class org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor=EntityTypeImpl@14247087 [ 
722
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor 
723
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.ArrayProcessor --> [DatabaseTable(CMP3_MM_ARRAYPROC)]), 
724
        mappings: [
725
            org.eclipse.persistence.mappings.DirectToFieldMapping[
726
                id-->CMP3_MM_ARRAYPROC.ARRAYPROC_ID], 
727
            org.eclipse.persistence.mappings.DirectToFieldMapping[
728
                version-->CMP3_MM_ARRAYPROC.ARRAYPROC_VERSION], 
729
            org.eclipse.persistence.mappings.OneToOneMapping[
730
                board]]], 
731
    class org.eclipse.persistence.testing.models.jpa.metamodel.Computer=EntityTypeImpl@8355938 [ 
732
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Computer 
733
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Computer --> [DatabaseTable(CMP3_MM_COMPUTER)]), 
734
        mappings: [
735
            org.eclipse.persistence.mappings.DirectToFieldMapping[
736
                id-->CMP3_MM_COMPUTER.COMPUTER_ID], 
737
            org.eclipse.persistence.mappings.DirectToFieldMapping[
738
                name-->CMP3_MM_COMPUTER.NAME], 
739
            org.eclipse.persistence.mappings.DirectToFieldMapping[
740
                version-->CMP3_MM_COMPUTER.COMPUTER_VERSION], 
741
            org.eclipse.persistence.mappings.OneToOneMapping[
742
                manufacturer], 
743
            org.eclipse.persistence.mappings.OneToOneMapping[
744
                location]]], 
745
    class org.eclipse.persistence.testing.models.jpa.metamodel.User=EntityTypeImpl@12968655 [ 
746
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.User 
747
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.User --> [DatabaseTable(CMP3_MM_USER)]), 
748
        mappings: [
749
            org.eclipse.persistence.mappings.DirectToFieldMapping[
750
                id-->CMP3_MM_USER.PERSON_ID], 
751
            org.eclipse.persistence.mappings.DirectToFieldMapping[
752
                name-->CMP3_MM_USER.NAME], 
753
            org.eclipse.persistence.mappings.DirectToFieldMapping[
754
                version-->CMP3_MM_USER.USER_VERSION]]], 
755
    class org.eclipse.persistence.testing.models.jpa.metamodel.Processor=MappedSuperclassTypeImpl@24044524 [ 
756
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.Processor 
757
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.Processor --> [DatabaseTable(__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME)]), 
758
        mappings: []], 
759
    class org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK=EmbeddableTypeImpl@6367194 [ 
760
        javaType: class org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK 
761
        descriptor: RelationalDescriptor(org.eclipse.persistence.testing.models.jpa.metamodel.CompositePK --> []), 
762
        mappings: []], 
763
    class java.lang.Integer=BasicTypeImpl@33083511 [ 
764
        javaType: class java.lang.Integer], 
765
    class java.lang.String=BasicTypeImpl@4086417 [ 
766
        javaType: class java.lang.String], 
767
    int=BasicTypeImpl@28057122 [ 
768
        javaType: int]}
782
                */
769
                */
783
            
770
            
784
            // Verify ManagedType operations
771
            // Verify ManagedType operations
Lines 813-818 Link Here
813
             *  Return the attributes declared by the managed type.
800
             *  Return the attributes declared by the managed type.
814
             */
801
             */
815
             //java.util.Set<Attribute<X, ?>> getDeclaredAttributes();
802
             //java.util.Set<Attribute<X, ?>> getDeclaredAttributes();
803
            expectedIAExceptionThrown = false;            
804
            try {
805
                /**
806
                 * Hierarchy:
807
                 *   Person : MappedSuperclass
808
                 *     +
809
                 *     +- id : Integer
810
                 *     +- name : String
811
                 *     
812
                 *     Corporation : MappedSuperclass extends Person
813
                 *       +
814
                 *       +- corpComputers : Set 
815
                 *       
816
                 *       Manufacturer : Entity extends Corporation
817
                 *         +
818
                 *         +- computers : Set
819
                 *         +- hardwareDesigners : Set
820
                 *         +- hardwareDesignersMap : Map
821
                 *         +- version : int
822
                 */
823
                Set<Attribute<Manufacturer, ?>> declaredAttributesSet = entityManufacturer.getDeclaredAttributes();
824
                //System.out.println("entityManufacturer.getDeclaredAttributes() " + declaredAttributesSet);
825
                assertNotNull(declaredAttributesSet);
826
                // We should see 4 declared out of 7 attributes for Manufacturer 
827
                assertEquals(4, declaredAttributesSet.size());
828
                // Id is declared 2 levels above
829
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("id"))); //
830
                // name is declared 2 levels above
831
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("name"))); //
832
                // corpComputers is declared 1 level above
833
                assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("corporateComputers"))); //
834
                // version is declared at this level
835
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("version"))); //
836
                // computers is declared at this level
837
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("computers"))); //
838
                // hardwareDesigners is declared at this level
839
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesigners"))); //
840
                // hardwareDesignersMap is declared at this level
841
                assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesignersMap"))); //                
842
            } catch (IllegalArgumentException iae) {
843
                iae.printStackTrace();
844
                expectedIAExceptionThrown = true;            
845
            }
846
            assertFalse(expectedIAExceptionThrown);            
847
           
848
            
816
849
817
            /**
850
            /**
818
             *  Return the single-valued attribute of the managed 
851
             *  Return the single-valued attribute of the managed 
Lines 1374-1382 Link Here
1374
             */
1407
             */
1375
            //public boolean hasVersionAttribute() {
1408
            //public boolean hasVersionAttribute() {
1376
1409
1410
1411
            // Verify MetamodelImpl operations
1412
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////
1413
            /**
1414
             *  Return the metamodel entity type representing the entity.
1415
             *  @param cls  the type of the represented entity
1416
             *  @return the metamodel entity type
1417
             *  @throws IllegalArgumentException if not an entity
1418
             */
1419
            //<X> EntityType<X> entity(Class<X> cls);
1420
            // test normal path
1421
            expectedIAExceptionThrown = false;            
1422
            try {
1423
                EntityType<Manufacturer> aType = metamodel.entity(Manufacturer.class);
1424
            } catch (IllegalArgumentException iae) {
1425
                //iae.printStackTrace();
1426
                expectedIAExceptionThrown = true;            
1427
            }
1428
            assertFalse(expectedIAExceptionThrown);            
1377
            
1429
            
1430
            // test variant path: null causes IAE
1431
            expectedIAExceptionThrown = false;            
1432
            try {
1433
                EntityType<Manufacturer> aType = metamodel.entity(null);
1434
            } catch (IllegalArgumentException iae) {
1435
                //iae.printStackTrace();
1436
                expectedIAExceptionThrown = true;            
1437
            }
1438
            assertTrue(expectedIAExceptionThrown);            
1439
1440
            // test variant path: wrong type (java simple type)
1441
            expectedIAExceptionThrown = false;            
1442
            try {
1443
                EntityType<Integer> aType = metamodel.entity(Integer.class);
1444
            } catch (IllegalArgumentException iae) {
1445
                //iae.printStackTrace();
1446
                expectedIAExceptionThrown = true;            
1447
            }
1448
            assertTrue(expectedIAExceptionThrown);            
1449
1450
            // test variant path: wrong type (BasicType)
1378
            
1451
            
1452
1453
            /**
1454
             *  Return the metamodel managed type representing the 
1455
             *  entity, mapped superclass, or embeddable class.
1456
             *  @param cls  the type of the represented managed class
1457
             *  @return the metamodel managed type
1458
             *  @throws IllegalArgumentException if not a managed class
1459
             */
1460
            //<X> ManagedType<X> type(Class<X> cls);
1461
            // test normal path (subtype = Basic)
1462
/*            expectedIAExceptionThrown = false;            
1463
            try {
1464
                Type<Manufacturer> aType = metamodel.type(Basic.class);
1465
            } catch (IllegalArgumentException iae) {
1466
                iae.printStackTrace();
1467
                expectedIAExceptionThrown = true;            
1468
            }
1469
            assertFalse(expectedIAExceptionThrown);            
1470
*/
1471
            // test normal path (subtype = Embeddable)
1472
            expectedIAExceptionThrown = false;            
1473
            try {
1474
                Type<EmbeddedPK> aType = metamodel.type(EmbeddedPK.class);
1475
            } catch (IllegalArgumentException iae) {
1476
                iae.printStackTrace();
1477
                expectedIAExceptionThrown = true;            
1478
            }
1479
            assertFalse(expectedIAExceptionThrown);            
1379
            
1480
            
1481
            // test normal path: (subtype = Entity)
1482
            expectedIAExceptionThrown = false;            
1483
            try {
1484
                Type<Manufacturer> aType = metamodel.type(Manufacturer.class);
1485
            } catch (IllegalArgumentException iae) {
1486
                iae.printStackTrace();
1487
                expectedIAExceptionThrown = true;            
1488
            }
1489
            assertFalse(expectedIAExceptionThrown);            
1490
1491
            // test normal path: (subtype = MappedSuperclass)
1492
            expectedIAExceptionThrown = false;            
1493
            try {
1494
                Type<Person> aType = metamodel.type(Person.class);
1495
            } catch (IllegalArgumentException iae) {
1496
                iae.printStackTrace();
1497
                expectedIAExceptionThrown = true;            
1498
            }
1499
            assertFalse(expectedIAExceptionThrown);            
1500
1501
            // 20090803: 2 tests below commented until bug# 285512 is fixed
1502
/*            
1503
            // test variant path: null causes IAE
1504
            expectedIAExceptionThrown = false;            
1505
            try {
1506
                Type<?> aType = metamodel.type(null);
1507
            } catch (IllegalArgumentException iae) {
1508
                //iae.printStackTrace();
1509
                expectedIAExceptionThrown = true;            
1510
            }
1511
            assertTrue(expectedIAExceptionThrown);            
1512
1513
            // test variant path: wrong type (java simple type)
1514
            expectedIAExceptionThrown = false;            
1515
            try {
1516
                Type<?> aType = metamodel.embeddable(Integer.class);
1517
            } catch (IllegalArgumentException iae) {
1518
                //iae.printStackTrace();
1519
                expectedIAExceptionThrown = true;            
1520
            }
1521
            assertTrue(expectedIAExceptionThrown);            
1522
1523
            // test variant path: wrong type (BasicType)
1524
*/
1525
            /**
1526
             *  Return the metamodel embeddable type representing the
1527
             *  embeddable class.
1528
             *  @param cls  the type of the represented embeddable class
1529
             *  @return the metamodel embeddable type
1530
             *  @throws IllegalArgumentException if not an embeddable class
1531
             */
1532
            //<X> EmbeddableType<X> embeddable(Class<X> cls);
1533
            // test normal path
1534
            expectedIAExceptionThrown = false;            
1535
            try {
1536
                EmbeddableType<EmbeddedPK> aType = metamodel.embeddable(EmbeddedPK.class);
1537
            } catch (IllegalArgumentException iae) {
1538
                iae.printStackTrace();
1539
                expectedIAExceptionThrown = true;            
1540
            }
1541
            assertFalse(expectedIAExceptionThrown);            
1542
            
1543
            // test variant path: null causes IAE
1544
            expectedIAExceptionThrown = false;            
1545
            try {
1546
                EmbeddableType<Manufacturer> aType = metamodel.embeddable(null);
1547
            } catch (IllegalArgumentException iae) {
1548
                //iae.printStackTrace();
1549
                expectedIAExceptionThrown = true;            
1550
            }
1551
            assertTrue(expectedIAExceptionThrown);            
1552
1553
            // test variant path: wrong type (subtype = Entity)
1554
            expectedIAExceptionThrown = false;            
1555
            try {
1556
                EmbeddableType<Manufacturer> aType = metamodel.embeddable(Manufacturer.class);
1557
            } catch (IllegalArgumentException iae) {
1558
                //iae.printStackTrace();
1559
                expectedIAExceptionThrown = true;            
1560
            }
1561
            assertTrue(expectedIAExceptionThrown);            
1562
1563
            // test variant path: wrong type (java simple type)
1564
            expectedIAExceptionThrown = false;            
1565
            try {
1566
                EmbeddableType<?> aType = metamodel.embeddable(Integer.class);
1567
            } catch (IllegalArgumentException iae) {
1568
                //iae.printStackTrace();
1569
                expectedIAExceptionThrown = true;            
1570
            }
1571
            assertTrue(expectedIAExceptionThrown);            
1572
1573
            // test variant path: wrong type (BasicType)
1574
1575
            /**
1576
             *  Return the metamodel managed types.
1577
             *  @return the metamodel managed types
1578
             */
1579
            //java.util.Set<ManagedType<?>> getManagedTypes();
1580
1581
            /**
1582
             * Return the metamodel entity types.
1583
             * @return the metamodel entity types
1584
             */
1585
            //java.util.Set<EntityType<?>> getEntities();
1586
1587
            /**
1588
             * Return the metamodel embeddable types.
1589
             * @return the metamodel embeddable types
1590
             */
1591
            //java.util.Set<EmbeddableType<?>> getEmbeddables();            
1592
            
1593
            
1380
            // get some static (non-runtime) attributes parameterized by <Owning type, return Type>
1594
            // get some static (non-runtime) attributes parameterized by <Owning type, return Type>
1381
            // Note: the String based attribute names are non type-safe
1595
            // Note: the String based attribute names are non type-safe
1382
            /*
1596
            /*
Lines 1557-1562 Link Here
1557
            e.printStackTrace();
1771
            e.printStackTrace();
1558
            exceptionThrown = true;
1772
            exceptionThrown = true;
1559
        } finally {
1773
        } finally {
1774
            // Runtime behavior should not affect the metamodel
1775
            // MetamodelImpl@15868511 [ 19 Types: , 16 ManagedTypes: , 10 EntityTypes: , 4 MappedSuperclassTypes: , 2 EmbeddableTypes: ]
1776
            //System.out.println("_Metamodel at test end: " + metamodel);
1560
            assertFalse(exceptionThrown);
1777
            assertFalse(exceptionThrown);
1561
            //finalizeForTest(em, entityMap);
1778
            //finalizeForTest(em, entityMap);
1562
            try {
1779
            try {
Lines 1607-1610 Link Here
1607
        public java.util.Set<MappedSuperclassTypeImpl<?>> getMappedSuperclasses() {
1824
        public java.util.Set<MappedSuperclassTypeImpl<?>> getMappedSuperclasses() {
1608
        public void setMappedSuperclasses(
1825
        public void setMappedSuperclasses(
1609
*/
1826
*/
1827
    
1828
    /**
1829
     * Test the Metamodel API using a TypeSafe query via the Criteria API (a user of the Metamodel)
1830
     */
1831
    public void testMetamodelTypeSafeBasedQuery() {
1832
        EntityManagerFactory emf = null;
1833
        EntityManager em = null;
1834
        
1835
        Set<Computer> computersList = new HashSet();
1836
        List<Memory> memories = new ArrayList();
1837
        List<VectorProcessor> processors = new ArrayList();
1838
        List<HardwareDesigner> hardwareDesigners = new ArrayList();
1839
        Computer computer1 = null;
1840
        Computer computer2 = null;
1841
        Manufacturer manufacturer = null;
1842
        User user = null;
1843
        HardwareDesigner hardwareDesigner1 = null;
1844
        SoftwareDesigner softwareDesigner1 = null;
1845
        VectorProcessor vectorProcessor1 = null;
1846
        Board board1 = null;
1847
        Memory memory1 = null;
1848
        Memory memory2 = null;
1849
        Location location1 = null;
1850
        Location location2 = null;        
1851
        boolean exceptionThrown = false;
1852
        Metamodel metamodel = null;
1853
1854
        try {
1855
            emf = initialize();
1856
            em = emf.createEntityManager();
1857
            em.getTransaction().begin();
1858
1859
            // setup entity relationships
1860
            computer1 = new Computer();
1861
            computer2 = new Computer();
1862
            memory1 = new Memory();
1863
            memory2 = new Memory();
1864
            manufacturer = new Manufacturer();
1865
            user = new User();
1866
            hardwareDesigner1 = new HardwareDesigner();
1867
            softwareDesigner1 = new SoftwareDesigner();
1868
            vectorProcessor1 = new VectorProcessor();
1869
            board1 = new Board();
1870
            location1 = new Location();
1871
            location2 = new Location();        
1872
1873
            // setup collections
1874
            computersList.add(computer1);
1875
            computersList.add(computer2);
1876
            processors.add(vectorProcessor1);
1877
            memories.add(memory1);
1878
            memories.add(memory2);
1879
            hardwareDesigners.add(hardwareDesigner1);
1880
1881
            // set owning and inverse sides of 1:m and m:1 relationships
1882
            manufacturer.setComputers(computersList);
1883
            manufacturer.setHardwareDesigners(hardwareDesigners);
1884
            hardwareDesigner1.setEmployer(manufacturer);
1885
            hardwareDesigner1.setPrimaryEmployer(manufacturer);
1886
            hardwareDesigner1.setSecondaryEmployer(manufacturer);
1887
            computer1.setManufacturer(manufacturer);
1888
            computer2.setManufacturer(manufacturer);
1889
            board1.setMemories(memories);
1890
            memory1.setBoard(board1);
1891
            memory2.setBoard(board1);
1892
            board1.setProcessors(processors);
1893
            vectorProcessor1.setBoard(board1);            
1894
            softwareDesigner1.setPrimaryEmployer(manufacturer);
1895
            softwareDesigner1.setSecondaryEmployer(manufacturer);
1896
            
1897
            // set 1:1 relationships
1898
            computer1.setLocation(location1);
1899
            computer2.setLocation(location2);
1900
            
1901
            // set attributes
1902
            computer1.setName("CDC-6600");
1903
            computer2.setName("CM-5");
1904
            
1905
            // persist all entities to the database in a single transaction
1906
            em.persist(computer1);
1907
            em.persist(computer2);
1908
            em.persist(manufacturer);
1909
            em.persist(user);
1910
            em.persist(hardwareDesigner1);
1911
            em.persist(softwareDesigner1);
1912
            em.persist(vectorProcessor1);
1913
            em.persist(board1);
1914
            em.persist(memory1);
1915
            em.persist(memory2);
1916
            em.persist(location1);
1917
            em.persist(location2);        
1918
            
1919
            em.getTransaction().commit();            
1920
            
1921
            // get Metamodel representation of the entity schema
1922
            metamodel = em.getMetamodel();
1923
            assertNotNull(metamodel);
1924
1925
            // Setup TypeSafe Criteria API query  
1926
            QueryBuilder aQueryBuilder = em.getQueryBuilder();
1927
            // Setup a query to get a list (the JPA 1.0 way) and compare it to the (JPA 2.0 way)
1928
            // avoid a NPE on .where in query.setExpressionBuilder(((ExpressionImpl)this.where).getCurrentNode().getBuilder());
1929
            //TypedQuery<Computer> aManufacturerQuery = em.createQuery(aQueryBuilder.createQuery(Computer.class));
1930
            Query aManufacturerQuery = em.createQuery(aQueryBuilder.createQuery(Computer.class));
1931
            List<Computer> computersResultsList = aManufacturerQuery.getResultList();
1932
            Computer aComputer = (Computer)computersResultsList.get(0);
1933
/*
1934
            // Get the primary key of the Computer
1935
            CriteriaQuery<Tuple> aCriteriaQuery = aQueryBuilder.createQuery(Tuple.class);
1936
            Root from = cq.from(Employee.class);
1937
            cq.multiselect(from.get("id"), from.get("firstName"));
1938
            cq.where(qb.equal(from.get("id"), qb.parameter(from.get("id").getModel().getBindableJavaType(), "id")).add(qb.equal(from.get("firstName"), qb.parameter(from.get("firstName").getModel().getBindableJavaType(), "firstName"))));
1939
            TypedQuery<Tuple> typedQuery = em.createQuery(cq);
1940
1941
            typedQuery.setParameter("id", employee.getId());
1942
            typedQuery.setParameter("firstName", employee.getFirstName());
1943
1944
            Tuple queryResult = typedQuery.getSingleResult();
1945
            assertTrue("Query Results do not match selection", queryResult.get(0).equals(employee.getId()) && queryResult.get(1).equals(employee.getFirstName()));
1946
*/            
1947
        } catch (Exception e) {
1948
            // we enter here on a failed commit() - for example if the table schema is incorrectly defined
1949
            e.printStackTrace();
1950
            exceptionThrown = true;
1951
        } finally {
1952
            assertFalse(exceptionThrown);
1953
            //finalizeForTest(em, entityMap);
1954
            if(null != em) {
1955
                cleanup(em);
1956
            }
1957
        }
1958
    }
1959
    
1960
    /**
1961
     * Test the Metamodel API or lack of using it via a Criteria API using string based queries
1962
     */
1963
    public void testMetamodelStringBasedQuery() {
1964
        EntityManagerFactory emf = null;
1965
        EntityManager em = null;
1966
        Set<Computer> computersList = new HashSet();
1967
        List<Memory> memories = new ArrayList();
1968
        List<VectorProcessor> processors = new ArrayList();
1969
        List<HardwareDesigner> hardwareDesigners = new ArrayList();
1970
        Computer computer1 = null;
1971
        Computer computer2 = null;
1972
        Manufacturer manufacturer = null;
1973
        User user = null;
1974
        HardwareDesigner hardwareDesigner1 = null;
1975
        SoftwareDesigner softwareDesigner1 = null;
1976
        VectorProcessor vectorProcessor1 = null;
1977
        //ArrayProcessor arrayProcessor1 = null;
1978
        Board board1 = null;
1979
        Memory memory1 = null;
1980
        Memory memory2 = null;
1981
        Location location1 = null;
1982
        Location location2 = null;        
1983
        boolean exceptionThrown = false;
1984
        Metamodel metamodel = null;
1985
1986
        try {
1987
            emf = initialize();
1988
            em = emf.createEntityManager();
1989
            em.getTransaction().begin();
1990
1991
            // setup entity relationships
1992
            computer1 = new Computer();
1993
            computer2 = new Computer();
1994
            memory1 = new Memory();
1995
            memory2 = new Memory();
1996
            manufacturer = new Manufacturer();
1997
            user = new User();
1998
            hardwareDesigner1 = new HardwareDesigner();
1999
            softwareDesigner1 = new SoftwareDesigner();
2000
            vectorProcessor1 = new VectorProcessor();
2001
            board1 = new Board();
2002
            location1 = new Location();
2003
            location2 = new Location();        
2004
2005
            // setup collections
2006
            computersList.add(computer1);
2007
            computersList.add(computer2);
2008
            processors.add(vectorProcessor1);
2009
            memories.add(memory1);
2010
            memories.add(memory2);
2011
            hardwareDesigners.add(hardwareDesigner1);
2012
2013
            // set owning and inverse sides of 1:m and m:1 relationships
2014
            manufacturer.setComputers(computersList);
2015
            manufacturer.setHardwareDesigners(hardwareDesigners);
2016
            hardwareDesigner1.setEmployer(manufacturer);
2017
            hardwareDesigner1.setPrimaryEmployer(manufacturer);
2018
            hardwareDesigner1.setSecondaryEmployer(manufacturer);
2019
            computer1.setManufacturer(manufacturer);
2020
            computer2.setManufacturer(manufacturer);
2021
            board1.setMemories(memories);
2022
            memory1.setBoard(board1);
2023
            memory2.setBoard(board1);
2024
            board1.setProcessors(processors);
2025
            vectorProcessor1.setBoard(board1);            
2026
            softwareDesigner1.setPrimaryEmployer(manufacturer);
2027
            softwareDesigner1.setSecondaryEmployer(manufacturer);
2028
            
2029
            // set 1:1 relationships
2030
            computer1.setLocation(location1);
2031
            computer2.setLocation(location2);
2032
            
2033
            // set attributes
2034
            computer1.setName("CDC-6600");
2035
            computer2.setName("CM-5");
2036
            
2037
            // persist all entities to the database in a single transaction
2038
            em.persist(computer1);
2039
            em.persist(computer2);
2040
            em.persist(manufacturer);
2041
            em.persist(user);
2042
            em.persist(hardwareDesigner1);
2043
            em.persist(softwareDesigner1);
2044
            em.persist(vectorProcessor1);
2045
            //em.persist(arrayProcessor1);
2046
            em.persist(board1);
2047
            em.persist(memory1);
2048
            em.persist(memory2);
2049
            em.persist(location1);
2050
            em.persist(location2);        
2051
            
2052
            em.getTransaction().commit();            
2053
            
2054
            // get Metamodel representation of the entity schema
2055
            metamodel = em.getMetamodel();
2056
            assertNotNull(metamodel);
2057
2058
            // Setup a non TypeSafe Criteria API query
2059
            
2060
        } catch (Exception e) {
2061
            // we enter here on a failed commit() - for example if the table schema is incorrectly defined
2062
            e.printStackTrace();
2063
            exceptionThrown = true;
2064
        } finally {
2065
            assertFalse(exceptionThrown);
2066
            //finalizeForTest(em, entityMap);
2067
            if(null != em) {
2068
                cleanup(em);
2069
            }
2070
        }
2071
    }
2072
    
2073
    
1610
}
2074
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java (-2 / +45 lines)
Lines 22-27 Link Here
22
    /**
22
    /**
23
     * 
23
     * 
24
     * DDL schema cleanup order
24
     * DDL schema cleanup order
25
DROP TABLE CMP3_MM_HIST_EMPLOY
25
DROP TABLE CMP3_MM_MANUF_MM_HWDES_MAP
26
DROP TABLE CMP3_MM_MANUF_MM_HWDES_MAP
26
DROP TABLE CMP3_MM_MANUF_MM_CORPCOMPUTER
27
DROP TABLE CMP3_MM_MANUF_MM_CORPCOMPUTER
27
DROP TABLE CMP3_MM_MANUF_MM_COMPUTER
28
DROP TABLE CMP3_MM_MANUF_MM_COMPUTER
Lines 59-64 Link Here
59
        addTableDefinition(buildMANUFACTURER_CORPCOMPUTER_JOINTable());
60
        addTableDefinition(buildMANUFACTURER_CORPCOMPUTER_JOINTable());
60
        addTableDefinition(buildMANUFACTURER_HARDWAREDESIGNER_JOINTable());
61
        addTableDefinition(buildMANUFACTURER_HARDWAREDESIGNER_JOINTable());
61
        addTableDefinition(buildMANUFACTURER_HARDWAREDESIGNER_MAP_JOINTable());
62
        addTableDefinition(buildMANUFACTURER_HARDWAREDESIGNER_MAP_JOINTable());
63
        addTableDefinition(buildMANUFACTURER_HARDWAREDESIGNER_HISTORICAL_JOINTable());        
62
        addTableDefinition(buildBOARD_MEMORY_JOINTable());
64
        addTableDefinition(buildBOARD_MEMORY_JOINTable());
63
        addTableDefinition(buildBOARD_PROCESSORTable());
65
        addTableDefinition(buildBOARD_PROCESSORTable());
64
        // n:n
66
        // n:n
Lines 176-182 Link Here
176
        table.addField(field9);        
178
        table.addField(field9);        
177
179
178
        // from MappedSuperclass
180
        // from MappedSuperclass
179
        // 1:1 unidrectional
181
        // 1:1 unidirectional
180
        FieldDefinition field7 = new FieldDefinition();
182
        FieldDefinition field7 = new FieldDefinition();
181
        field7.setName("PRIME_EMPLOYER_PERSON_ID");
183
        field7.setName("PRIME_EMPLOYER_PERSON_ID");
182
        field7.setTypeName("NUMERIC");
184
        field7.setTypeName("NUMERIC");
Lines 252-258 Link Here
252
        table.addField(field6);
254
        table.addField(field6);
253
*/        
255
*/        
254
        // from MappedSuperclass
256
        // from MappedSuperclass
255
        // 1:1 unidrectional
257
        // 1:1 unidirectional
256
        FieldDefinition field7 = new FieldDefinition();
258
        FieldDefinition field7 = new FieldDefinition();
257
        field7.setName("PRIME_EMPLOYER_PERSON_ID");
259
        field7.setName("PRIME_EMPLOYER_PERSON_ID");
258
        field7.setTypeName("NUMERIC");
260
        field7.setTypeName("NUMERIC");
Lines 275-280 Link Here
275
        field8.setIsIdentity(false);
277
        field8.setIsIdentity(false);
276
        field8.setForeignKeyFieldName("CMP3_MM_MANUF.PERSON_ID");
278
        field8.setForeignKeyFieldName("CMP3_MM_MANUF.PERSON_ID");
277
        table.addField(field8);        
279
        table.addField(field8);        
280
281
        // 1:m with JoinTable - by default
282
/*        FieldDefinition field9 = new FieldDefinition();
283
        field9.setName("HIST_EMPLOYER_PERSON_ID");
284
        field9.setTypeName("NUMERIC");
285
        field9.setSize(15);
286
        field9.setShouldAllowNull(false);
287
        field9.setIsPrimaryKey(false);
288
        field9.setUnique(false);
289
        field9.setIsIdentity(false);
290
        field9.setForeignKeyFieldName("CMP3_MM_MANUF.PERSON_ID");
291
        table.addField(field9);*/        
278
        
292
        
279
        
293
        
280
        return table;
294
        return table;
Lines 668-673 Link Here
668
        return table;
682
        return table;
669
    }
683
    }
670
684
685
    public static TableDefinition buildMANUFACTURER_HARDWAREDESIGNER_HISTORICAL_JOINTable() {
686
        TableDefinition table = new TableDefinition();
687
        table.setName("CMP3_MM_HIST_EMPLOY");
688
689
        FieldDefinition field1 = new FieldDefinition();
690
        field1.setName("MANUF_ID");
691
        field1.setTypeName("NUMERIC");
692
        field1.setSize(15);
693
        field1.setShouldAllowNull(false);
694
        field1.setIsPrimaryKey(false);
695
        field1.setUnique(false);
696
        field1.setIsIdentity(false);
697
        field1.setForeignKeyFieldName("CMP3_MM_MANUF.PERSON_ID");
698
        table.addField(field1);        
699
700
        FieldDefinition field2 = new FieldDefinition();
701
        field2.setName("DESIGNER_ID");
702
        field2.setTypeName("NUMERIC");
703
        field2.setSize(15);
704
        field2.setShouldAllowNull(false);
705
        field2.setIsPrimaryKey(false);
706
        field2.setUnique(false);
707
        field2.setIsIdentity(false);
708
        field2.setForeignKeyFieldName("CMP3_MM_HWDESIGNER.PERSON_ID");
709
        table.addField(field2);        
710
711
        return table;
712
    }
713
    
671
    public static TableDefinition buildMANUFACTURER_HARDWAREDESIGNER_MAP_JOINTable() {
714
    public static TableDefinition buildMANUFACTURER_HARDWAREDESIGNER_MAP_JOINTable() {
672
        TableDefinition table = new TableDefinition();
715
        TableDefinition table = new TableDefinition();
673
        table.setName("CMP3_MM_MANUF_MM_HWDES_MAP");
716
        table.setName("CMP3_MM_MANUF_MM_HWDES_MAP");
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/EntityManagerFactoryImpl.java (+14 lines)
Lines 418-423 Link Here
418
        return metaModel;
418
        return metaModel;
419
    }
419
    }
420
420
421
    /**
422
     * INTERNAL:
423
     * Convenience function to allow us to reset the Metamodel 
424
     * in the possible case that we want to regenerate it.
425
     * This function is outside of the JPA 2.0 specification.
426
     * @param aMetamodel
427
     */
428
    public void setMetamodel(Metamodel aMetamodel) {
429
        if(!this.isOpen()) {
430
            throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory"));
431
        }
432
        metaModel = aMetamodel;
433
    }
434
    
421
	/**
435
	/**
422
	 * @see javax.persistence.EntityManagerFactory#getSupportedProperties()
436
	 * @see javax.persistence.EntityManagerFactory#getSupportedProperties()
423
	 * @since Java Persistence API 2.0
437
	 * @since Java Persistence API 2.0
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataConstants.java (-1 / +4 lines)
Lines 30-36 Link Here
30
    public static final String FIELD = "FIELD";
30
    public static final String FIELD = "FIELD";
31
    public static final String PROPERTY = "PROPERTY";
31
    public static final String PROPERTY = "PROPERTY";
32
32
33
    /** Metamodel processing for MappedSuperclasses non-functional names */
33
    /** 
34
     * Metamodel processing for MappedSuperclasses non-functional names.<p>
35
     * @See MetadataProject.addMappedSuperclassAccessor() 
36
     **/
34
    public static final String MAPPED_SUPERCLASS_RESERVED_PK_NAME = "__PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME";
37
    public static final String MAPPED_SUPERCLASS_RESERVED_PK_NAME = "__PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME";
35
    public static final String MAPPED_SUPERCLASS_RESERVED_TABLE_NAME = "__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME";    
38
    public static final String MAPPED_SUPERCLASS_RESERVED_TABLE_NAME = "__METAMODEL_RESERVED_IN_MEM_ONLY_TABLE_NAME";    
36
39
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/AttributeImpl.java (-4 / +2 lines)
Lines 98-107 Link Here
98
     *  Return the Java type of the represented attribute.
98
     *  Return the Java type of the represented attribute.
99
     *  @return Java type
99
     *  @return Java type
100
     */
100
     */
101
    public Class<T> getJavaType() {
101
    public abstract Class<T> getJavaType();
102
        return getMapping().getAttributeClassification(); // returns null for OneToManyMapping
102
103
    }
104
    
105
    /**
103
    /**
106
     * INTERNAL:
104
     * INTERNAL:
107
     * Return the managed type representing the type in which the member was
105
     * Return the managed type representing the type in which the member was
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/BasicTypeImpl.java (+29 lines)
Lines 49-54 Link Here
49
    
49
    
50
    /**
50
    /**
51
     * INTERNAL:
51
     * INTERNAL:
52
     * Return whether this type is an Entity (true) or MappedSuperclass (false) or Embeddable (false)
53
     * @return
54
     */
55
    @Override
56
    public boolean isEntity() {
57
        return false;
58
    }
59
    
60
    /**
61
     * INTERNAL:
52
     * Return whether this type is identifiable.
62
     * Return whether this type is identifiable.
53
     * This would be EntityType and MappedSuperclassType
63
     * This would be EntityType and MappedSuperclassType
54
     * @return
64
     * @return
Lines 69-72 Link Here
69
        return false;
79
        return false;
70
    }
80
    }
71
    
81
    
82
    /**
83
     * INTERNAL:
84
     * Return whether this type is an MappedSuperclass (true) or Entity (false) or Embeddable (false)
85
     * @return
86
     */
87
    @Override
88
    public boolean isMappedSuperclass() {
89
        return isEntity();
90
    }
91
    
92
    /**
93
     * INTERNAL:
94
     * Append the partial string representation of the receiver to the StringBuffer.
95
     */
96
    @Override
97
    protected void toStringHelper(StringBuffer aBuffer) {
98
        // No state information to add
99
        return;
100
    }
72
}
101
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/CollectionAttributeImpl.java (-1 / +12 lines)
Lines 45-52 Link Here
45
     * @param mapping
45
     * @param mapping
46
     */
46
     */
47
    protected CollectionAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
47
    protected CollectionAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
48
        super(managedType, mapping);
48
        this(managedType, mapping, false);
49
    }
49
    }
50
    
51
    /**
52
     * INTERNAL:
53
     * Construct an instance of Collection for the managed type managedType
54
     * @param managedType
55
     * @param mapping
56
     * @param validationEnabled
57
     */
58
    protected CollectionAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
59
        super(managedType, mapping, validationEnabled);
60
    }
50
61
51
    /**
62
    /**
52
     * Return the collection type.
63
     * Return the collection type.
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/EmbeddableTypeImpl.java (+20 lines)
Lines 48-51 Link Here
48
        return PersistenceType.EMBEDDABLE;
48
        return PersistenceType.EMBEDDABLE;
49
    }
49
    }
50
50
51
    /**
52
     * INTERNAL:
53
     * Return whether this type is an Entity (true) or MappedSuperclass (false) or Embeddable (false)
54
     * @return
55
     */
56
    @Override
57
    public boolean isEntity() {
58
        return false;
59
    }
60
    
61
    /**
62
     * INTERNAL:
63
     * Return whether this type is an MappedSuperclass (true) or Entity (false) or Embeddable (false)
64
     * @return
65
     */
66
    @Override
67
    public boolean isMappedSuperclass() {
68
        return isEntity();
69
    }
70
    
51
}
71
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/EntityTypeImpl.java (-38 / +21 lines)
Lines 26-36 Link Here
26
import javax.persistence.metamodel.EntityType;
26
import javax.persistence.metamodel.EntityType;
27
import javax.persistence.metamodel.Type;
27
import javax.persistence.metamodel.Type;
28
28
29
import org.eclipse.persistence.descriptors.CMPPolicy;
30
import org.eclipse.persistence.descriptors.RelationalDescriptor;
29
import org.eclipse.persistence.descriptors.RelationalDescriptor;
31
import org.eclipse.persistence.internal.jpa.CMP3Policy;
32
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
33
import org.eclipse.persistence.mappings.DatabaseMapping;
34
30
35
/**
31
/**
36
 * <p>
32
 * <p>
Lines 75-114 Link Here
75
    }
71
    }
76
    
72
    
77
    /**
73
    /**
78
     *  Return the type that represents the type of the id.
79
     *  @return type of id
80
     */
81
    @Override
82
    public Type<?> getIdType() {
83
        // NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor
84
        // descriptor.getPrimaryKeyPolicy().getIdClass();
85
        CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy();
86
        
87
        if (null == cmpPolicy) {
88
            // Composite key support (IE: @EmbeddedId)
89
            java.util.List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings();
90
            
91
            if (pkMappings.size() == 1) {
92
                Class aClass = pkMappings.get(0).getAttributeClassification(); // null for OneToOneMapping
93
                // lookup class in our types map
94
                Type<?> aType = this.metamodel.getType(aClass);
95
                return aType;
96
            }
97
        }
98
        
99
        // Single Key support using any Java class - built in or user defined
100
        // There already is an instance of the PKclass on the policy
101
        if (cmpPolicy instanceof CMP3Policy) {
102
            // BasicType, EntityType or IdentifiableType are handled here, lookup the class in the types map and create a wrapper if it does not exist yet
103
            return this.metamodel.getType(((CMP3Policy) cmpPolicy).getPKClass());
104
        }
105
        // Non-specification mandated exception        
106
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
107
                "metamodel_incompatible_persistence_config_for_getIdType", 
108
                new Object[] { this }));        
109
    }
110
    
111
    /**
112
     *  Return the entity name
74
     *  Return the entity name
113
     *  @return entity name
75
     *  @return entity name
114
     */
76
     */
Lines 123-126 Link Here
123
    public Type.PersistenceType getPersistenceType() {
85
    public Type.PersistenceType getPersistenceType() {
124
        return Type.PersistenceType.ENTITY;
86
        return Type.PersistenceType.ENTITY;
125
    }
87
    }
88
    
89
    /**
90
     * INTERNAL:
91
     * Return whether this type is an Entity (true) or MappedSuperclass (false) or Embeddable (false)
92
     * @return
93
     */
94
    @Override
95
    public boolean isEntity() {
96
        return true;
97
    }
98
    
99
    /**
100
     * INTERNAL:
101
     * Return whether this type is an MappedSuperclass (true) or Entity (false) or Embeddable (false)
102
     * @return
103
     */
104
    @Override
105
    public boolean isMappedSuperclass() {
106
        return !isEntity();
107
    }
108
    
126
}
109
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/IdentifiableTypeImpl.java (-2 / +54 lines)
Lines 14-28 Link Here
14
 ******************************************************************************/
14
 ******************************************************************************/
15
package org.eclipse.persistence.internal.jpa.metamodel;
15
package org.eclipse.persistence.internal.jpa.metamodel;
16
16
17
import java.util.Iterator;
18
import java.util.List;
17
import java.util.Set;
19
import java.util.Set;
18
20
19
import javax.persistence.PersistenceException;
21
import javax.persistence.PersistenceException;
22
import javax.persistence.metamodel.Attribute;
20
import javax.persistence.metamodel.IdentifiableType;
23
import javax.persistence.metamodel.IdentifiableType;
21
import javax.persistence.metamodel.SingularAttribute;
24
import javax.persistence.metamodel.SingularAttribute;
22
import javax.persistence.metamodel.Type;
25
import javax.persistence.metamodel.Type;
23
26
27
import org.eclipse.persistence.descriptors.CMPPolicy;
24
import org.eclipse.persistence.descriptors.RelationalDescriptor;
28
import org.eclipse.persistence.descriptors.RelationalDescriptor;
29
import org.eclipse.persistence.internal.helper.DatabaseField;
30
import org.eclipse.persistence.internal.jpa.CMP3Policy;
25
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
31
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
32
import org.eclipse.persistence.mappings.DatabaseMapping;
26
33
27
/**
34
/**
28
 * <p>
35
 * <p>
Lines 105-110 Link Here
105
    public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
112
    public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) {
106
        SingularAttribute<? super X, Y> anAttribute = null;
113
        SingularAttribute<? super X, Y> anAttribute = null;
107
        Class<Y> realType = null;
114
        Class<Y> realType = null;
115
        //boolean isId = this.accessor.isId();
108
        if(type != realType) {
116
        if(type != realType) {
109
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
117
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
110
                "metamodel_identifiable_id_attribute_type_incorrect", 
118
                "metamodel_identifiable_id_attribute_type_incorrect", 
Lines 117-123 Link Here
117
     *  Return the type that represents the type of the id.
125
     *  Return the type that represents the type of the id.
118
     *  @return type of id
126
     *  @return type of id
119
     */
127
     */
120
    public abstract Type<?> getIdType();
128
    public Type<?> getIdType() {
129
        // NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor
130
        // descriptor.getPrimaryKeyPolicy().getIdClass();
131
        CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy();
132
133
        if (null == cmpPolicy) {
134
            // Composite key support (IE: @EmbeddedId)            
135
            List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings();
136
            // Check the primaryKeyFields on the descriptor - for MappedSuperclass pseudo-Descriptors
137
            if(pkMappings.size() == 0) {
138
                // Search the mappings for Id mappings
139
                DatabaseMapping aMapping = null;
140
                for(Iterator<DatabaseMapping> mappingsIterator = getDescriptor().getMappings().iterator(); mappingsIterator.hasNext();) {
141
                    aMapping = mappingsIterator.next();
142
                    if(aMapping.isDerivedIdMapping()) {
143
                        String attributeName = aMapping.getAttributeName();
144
                        // get the attribute Id (declared or not)
145
                        Attribute anAttribute = this.getAttribute(attributeName);
146
                        if(anAttribute != null) {
147
                            return this.getMetamodel().getType(anAttribute.getJavaType());
148
                        }
149
                        
150
                    }
151
                }
152
            }
153
            
154
            if (pkMappings.size() == 1) {
155
                Class aClass = pkMappings.get(0).getAttributeClassification(); // null for OneToOneMapping
156
                // lookup class in our types map
157
                Type<?> aType = this.metamodel.getType(aClass);
158
                return aType;
159
            }
160
        }
161
        
162
        // Single Key support using any Java class - built in or user defined
163
        // There already is an instance of the PKclass on the policy
164
        if (cmpPolicy instanceof CMP3Policy) {
165
            // BasicType, EntityType or IdentifiableType are handled here, lookup the class in the types map and create a wrapper if it does not exist yet
166
            return this.metamodel.getType(((CMP3Policy) cmpPolicy).getPKClass());
167
        }
168
        // Non-specification mandated exception        
169
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
170
                "metamodel_incompatible_persistence_config_for_getIdType", 
171
                new Object[] { this }));        
172
    }
121
    
173
    
122
    /**
174
    /**
123
     *  Return the identifiable type that corresponds to the most
175
     *  Return the identifiable type that corresponds to the most
Lines 178-184 Link Here
178
    public boolean isIdentifiableType() {
230
    public boolean isIdentifiableType() {
179
        return true;
231
        return true;
180
    }
232
    }
181
    
233
182
    /**
234
    /**
183
     * INTERNAL:
235
     * INTERNAL:
184
     * Set the superType for this IdentifiableType - only after all ManagedTypes 
236
     * Set the superType for this IdentifiableType - only after all ManagedTypes 
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ListAttributeImpl.java (-1 / +16 lines)
Lines 38-48 Link Here
38
 */ 
38
 */ 
39
public class ListAttributeImpl<X, V> extends PluralAttributeImpl<X, java.util.List<V>, V> implements ListAttribute<X, V> {
39
public class ListAttributeImpl<X, V> extends PluralAttributeImpl<X, java.util.List<V>, V> implements ListAttribute<X, V> {
40
40
41
    /**
42
     * INTERNAL:
43
     * @param managedType
44
     * @param mapping
45
     */
41
    protected ListAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
46
    protected ListAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
42
        super(managedType, mapping);
47
        super(managedType, mapping, false);
43
    }
48
    }
44
49
45
    /**
50
    /**
51
     * 
52
     * @param managedType
53
     * @param mapping
54
     * @param validationEnabled
55
     */
56
    protected ListAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
57
        super(managedType, mapping, validationEnabled);
58
    }
59
60
    /**
46
     * Return the collection type.
61
     * Return the collection type.
47
     * @return collection type
62
     * @return collection type
48
     */
63
     */
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java (-18 / +27 lines)
Lines 94-101 Link Here
94
        this.metamodel = metamodel;
94
        this.metamodel = metamodel;
95
        // Cache the ManagedType on the descriptor 
95
        // Cache the ManagedType on the descriptor 
96
        descriptor.setProperty(getClass().getName(), this);
96
        descriptor.setProperty(getClass().getName(), this);
97
        // Note: Full initialization of the ManagedType occurs during MetamodelImpl.initialize()
97
        // Note: Full initialization of the ManagedType occurs during MetamodelImpl.initialize() after all types are instantiated
98
        //initialize(); // initialize after all types are instantiated
99
    }
98
    }
100
99
101
    /**
100
    /**
Lines 925-931 Link Here
925
            }
924
            }
926
        } else {            
925
        } else {            
927
           // Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType
926
           // Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType
928
           //if(aSuperType.isMappedSuperclass()) { // merge later with getIdType() changes in queue 
927
           if(aSuperType.isMappedSuperclass()) {  
929
               Attribute aSuperTypeAttribute = aSuperType.getMembers().get(attributeName);
928
               Attribute aSuperTypeAttribute = aSuperType.getMembers().get(attributeName);
930
               // UC1.3 The immediate mappedSuperclass may have the attribute - we check it in the base case of the next recursive call 
929
               // UC1.3 The immediate mappedSuperclass may have the attribute - we check it in the base case of the next recursive call 
931
               if(null != aSuperTypeAttribute) {
930
               if(null != aSuperTypeAttribute) {
Lines 945-958 Link Here
945
                       }
944
                       }
946
                   }
945
                   }
947
               }
946
               }
948
           /*} else {
947
           } else {
949
               // superType (Entity) may declare the attribute higher up - we do not need to check this
948
               // superType (Entity) may declare the attribute higher up - we do not need to check this
949
               // TODO: verify handling of XML mapped non-Entity (plain Java Class) inherited mappings
950
               // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_53:_20090729:_Verify_that_inheritied_non-JPA_class_mappings_are_handled_by_the_Metamodel
950
               if(null == anAttribute) {
951
               if(null == anAttribute) {
951
                   return false;
952
                   return false;
952
               } else {
953
               } else {
953
                   return true;
954
                   return true;
954
               }
955
               }
955
           }*/
956
           }
956
        }
957
        }
957
    }
958
    }
958
    
959
    
Lines 965-978 Link Here
965
     */
966
     */
966
    protected void initialize() { // TODO: Check all is*Policy() calls
967
    protected void initialize() { // TODO: Check all is*Policy() calls
967
        /*
968
        /*
968
         * Issue 1: The hierarchy of the Metamodel API has Collection alongside List, Set and Map.
969
         * Design Issue 37:
969
         *              However, in a normal Java collections framework Collection is an 
970
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_37:_20090708:_CollectionAttribute_acts_as_a_peer_of_Map.2C_Set.2C_List_but_should_be_a_super_interface 
970
         *              abstract superclass of List, Set and Map (with Map not really a Collection).
971
         *     The hierarchy of the Metamodel API has Collection alongside List, Set and Map.
971
         *              We therefore need to treat Collection here as a peer of the other "collections".
972
         * However, in a normal Java collections framework Collection is an 
973
         * abstract superclass of List, Set and Map (with Map not really a Collection).
974
         * We therefore need to treat Collection here as a peer of the other "collections".
972
         */
975
         */
973
        this.members = new HashMap<String, Attribute<X, ?>>();
976
        this.members = new HashMap<String, Attribute<X, ?>>();
974
977
975
        // Get all mappings on the relationalDescriptor
978
        // Get and process all mappings on the relationalDescriptor
976
        for (Iterator<DatabaseMapping> i = getDescriptor().getMappings().iterator(); i.hasNext();) {
979
        for (Iterator<DatabaseMapping> i = getDescriptor().getMappings().iterator(); i.hasNext();) {
977
            DatabaseMapping mapping = (DatabaseMapping) i.next();
980
            DatabaseMapping mapping = (DatabaseMapping) i.next();
978
            AttributeImpl<X, ?> member = null;
981
            AttributeImpl<X, ?> member = null;
Lines 983-1006 Link Here
983
                CollectionMapping colMapping = (CollectionMapping) mapping;
986
                CollectionMapping colMapping = (CollectionMapping) mapping;
984
                if (colMapping.getContainerPolicy().isMapPolicy()) {
987
                if (colMapping.getContainerPolicy().isMapPolicy()) {
985
                    // Handle Map type mappings
988
                    // Handle Map type mappings
986
                    member = new MapAttributeImpl(this, colMapping);
989
                    member = new MapAttributeImpl(this, colMapping, true);
987
                    // check mapping.attributeAcessor.attributeField.type=Collection
990
                    // check mapping.attributeAcessor.attributeField.type=Collection
988
                } else if (colMapping.getContainerPolicy().isListPolicy()) { // TODO: isListPolicy() will return true for IndirectList (a lazy Collection)                    
991
                } else if (colMapping.getContainerPolicy().isListPolicy()) { // TODO: isListPolicy() will return true for IndirectList (a lazy Collection)                    
989
                    // Handle List type mappings
992
                    // Handle List type mappings
990
                    member = new ListAttributeImpl(this, colMapping);
993
                    member = new ListAttributeImpl(this, colMapping, true);
991
                } else {
994
                } else {
992
                    // Handle Set type mappings (IndirectSet.isAssignableFrom(Set.class) == false)
995
                    // Handle Set type mappings (IndirectSet.isAssignableFrom(Set.class) == false)
993
                    if (colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(Set.class) ||
996
                    if (colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(Set.class) ||
994
                            colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(IndirectSet.class)) {
997
                            colMapping.getContainerPolicy().getContainerClass().isAssignableFrom(IndirectSet.class)) {
995
                        member = new SetAttributeImpl(this, colMapping);
998
                        member = new SetAttributeImpl(this, colMapping, true);
996
                    } else {
999
                    } else {
997
                        // Handle Collection type mappings as a default
1000
                        // Handle Collection type mappings as a default
998
                        member = new CollectionAttributeImpl(this, colMapping);
1001
                        member = new CollectionAttributeImpl(this, colMapping, true);
999
                    }
1002
                    }
1000
                }
1003
                }
1001
            } else {
1004
            } else {
1002
                // Handle 1:1 single object and direct mappings
1005
                // Handle 1:1 single object and direct mappings
1003
                member = new SingularAttributeImpl(this, mapping);
1006
                member = new SingularAttributeImpl(this, mapping, true);
1004
            }
1007
            }
1005
1008
1006
            this.members.put(mapping.getAttributeName(), member);
1009
            this.members.put(mapping.getAttributeName(), member);
Lines 1030-1039 Link Here
1030
    }
1033
    }
1031
   
1034
   
1032
    /**
1035
    /**
1033
     * Return the string representation of the receiver.
1036
     * INTERNAL:
1037
     * Append the partial string representation of the receiver to the StringBuffer.
1034
     */
1038
     */
1035
    @Override
1039
    @Override
1036
    public String toString() {
1040
    protected void toStringHelper(StringBuffer aBuffer) {    
1037
        return "ManagedTypeImpl[" + getDescriptor() + "]";
1041
        aBuffer.append(" descriptor: ");
1042
        aBuffer.append(this.getDescriptor());
1043
        if(null != this.getDescriptor()) {
1044
            aBuffer.append(", mappings: ");
1045
            aBuffer.append(this.getDescriptor().getMappings());
1046
        }
1038
    }
1047
    }
1039
}
1048
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MapAttributeImpl.java (-4 / +22 lines)
Lines 51-59 Link Here
51
    /** The key type that this Map type is based on **/
51
    /** The key type that this Map type is based on **/
52
    private Type<K> keyType;
52
    private Type<K> keyType;
53
    
53
    
54
    /**
55
     * INTERNAL:
56
     * @param managedType
57
     * @param mapping
58
     */
54
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
59
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
55
        super(managedType, mapping);
60
        this(managedType, mapping, false);
61
    }
56
62
63
    /**
64
     * INTERNAL:
65
     * @param managedType
66
     * @param mapping
67
     * @param validationEnabled
68
     */
69
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
70
        super(managedType, mapping, validationEnabled);
71
57
        MapContainerPolicy policy = (MapContainerPolicy) mapping.getContainerPolicy();
72
        MapContainerPolicy policy = (MapContainerPolicy) mapping.getContainerPolicy();
58
        Object policyKeyType = policy.getKeyType(); // returns a Class<?> or descriptor (via AggregateObjectMapping)        
73
        Object policyKeyType = policy.getKeyType(); // returns a Class<?> or descriptor (via AggregateObjectMapping)        
59
        Type<?> aKeyType = null;
74
        Type<?> aKeyType = null;
Lines 68-74 Link Here
68
                } else {
83
                } else {
69
                    if(null == policy.getElementDescriptor()) {
84
                    if(null == policy.getElementDescriptor()) {
70
                        // check for a keyMapping on the mapping
85
                        // check for a keyMapping on the mapping
71
                        if(policy.isMappedKeyMapPolicy()) {
86
                        if(policy.isMappedKeyMapPolicy()) {                            
72
                            MapKeyMapping mapKeyMapping = ((MappedKeyMapContainerPolicy)policy).getKeyMapping();
87
                            MapKeyMapping mapKeyMapping = ((MappedKeyMapContainerPolicy)policy).getKeyMapping();
73
                            RelationalDescriptor descriptor = (RelationalDescriptor)((DatabaseMapping)mapKeyMapping).getDescriptor();
88
                            RelationalDescriptor descriptor = (RelationalDescriptor)((DatabaseMapping)mapKeyMapping).getDescriptor();
74
                            // If the reference descriptor is null then we are on a direct mapping
89
                            // If the reference descriptor is null then we are on a direct mapping
Lines 76-83 Link Here
76
                                throw new IllegalArgumentException("Unsupported operation on " + managedType);
91
                                throw new IllegalArgumentException("Unsupported operation on " + managedType);
77
                            } else {
92
                            } else {
78
                                if(null == descriptor.getCMPPolicy()) { // for __PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME
93
                                if(null == descriptor.getCMPPolicy()) { // for __PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME
79
                                    //throw new IllegalArgumentException("Unsupported operation on " + managedType);
94
                                    javaClass = ((DatabaseMapping)mapKeyMapping).getAttributeClassification();
80
                                    javaClass = Object.class;
95
                                    if(null == javaClass) {
96
                                        javaClass = Object.class;
97
                                    }
81
                                } else {
98
                                } else {
82
                                    javaClass = descriptor.getCMPPolicy().getPKClass();        
99
                                    javaClass = descriptor.getCMPPolicy().getPKClass();        
83
                                }
100
                                }
Lines 88-93 Link Here
88
                }
105
                }
89
            } else {
106
            } else {
90
                // Handle EmbeddableType
107
                // Handle EmbeddableType
108
                System.out.println("_embeddableType: " + this + " mapping: " + mapping);
91
            }
109
            }
92
        } else {            
110
        } else {            
93
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
111
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MappedSuperclassTypeImpl.java (-25 / +14 lines)
Lines 20-28 Link Here
20
 ******************************************************************************/
20
 ******************************************************************************/
21
package org.eclipse.persistence.internal.jpa.metamodel;
21
package org.eclipse.persistence.internal.jpa.metamodel;
22
22
23
import javax.persistence.PersistenceException;
24
import javax.persistence.metamodel.MappedSuperclassType;
23
import javax.persistence.metamodel.MappedSuperclassType;
25
import javax.persistence.metamodel.Type;
26
24
27
import org.eclipse.persistence.descriptors.RelationalDescriptor;
25
import org.eclipse.persistence.descriptors.RelationalDescriptor;
28
26
Lines 58-72 Link Here
58
    }
56
    }
59
    
57
    
60
    /**
58
    /**
61
     *  Return the type that represents the type of the id.
62
     *  @return type of id
63
     */
64
    @Override
65
    public Type<?> getIdType() {
66
        throw new PersistenceException("Not Yet Implemented");
67
    }
68
69
    /**
70
     *  Return the persistence type.
59
     *  Return the persistence type.
71
     *  @return persistence type
60
     *  @return persistence type
72
     */ 
61
     */ 
Lines 76-96 Link Here
76
65
77
    /**
66
    /**
78
     * INTERNAL:
67
     * INTERNAL:
79
     * Return the string representation of the receiver.
68
     * Return whether this type is an Entity (true) or MappedSuperclass (false) or Embeddable (false)
69
     * @return
80
     */
70
     */
81
    @Override
71
    @Override
82
    public String toString() {
72
    public boolean isEntity() {
83
        StringBuffer aBuffer = new StringBuffer();
73
        return false;
84
        aBuffer.append(this.getClass().getSimpleName());
85
        aBuffer.append("@");
86
        aBuffer.append(hashCode());
87
        aBuffer.append(" [descriptor: ");
88
        aBuffer.append(this.getDescriptor());
89
        if(null != this.getDescriptor()) {
90
            aBuffer.append(", mappings: ");
91
            aBuffer.append(this.getDescriptor().getMappings());
92
        }
93
        aBuffer.append("]");
94
        return aBuffer.toString();
95
    }
74
    }
75
   
76
    /**
77
     * INTERNAL:
78
     * Return whether this type is an MappedSuperclass (true) or Entity (false) or Embeddable (false)
79
     * @return
80
     */
81
    @Override
82
    public boolean isMappedSuperclass() {
83
        return !isEntity();
84
    }
96
}
85
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (-69 / +149 lines)
Lines 42-47 Link Here
42
42
43
import org.eclipse.persistence.descriptors.RelationalDescriptor;
43
import org.eclipse.persistence.descriptors.RelationalDescriptor;
44
import org.eclipse.persistence.internal.helper.ClassConstants;
44
import org.eclipse.persistence.internal.helper.ClassConstants;
45
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
45
import org.eclipse.persistence.jpa.JpaHelper;
46
import org.eclipse.persistence.jpa.JpaHelper;
46
import org.eclipse.persistence.sessions.DatabaseSession;
47
import org.eclipse.persistence.sessions.DatabaseSession;
47
import org.eclipse.persistence.sessions.Project;
48
import org.eclipse.persistence.sessions.Project;
Lines 85-107 Link Here
85
        initialize();
86
        initialize();
86
    }
87
    }
87
88
88
    public MetamodelImpl(EntityManagerFactory emf) {
89
        // Create a new Metamodel using the EclipseLink session on the EMF
90
        this(JpaHelper.getServerSession(emf));
91
    }
92
93
    public MetamodelImpl(EntityManager em) {
89
    public MetamodelImpl(EntityManager em) {
94
        // Create a new Metamodel using the EclipseLink session on the EM
90
        // Create a new Metamodel using the EclipseLink session on the EM
95
        this(JpaHelper.getEntityManager(em).getServerSession());
91
        this(JpaHelper.getEntityManager(em).getServerSession());
96
    }
92
    }
97
93
98
    /**
94
    public MetamodelImpl(EntityManagerFactory emf) {
99
     * INTERNAL:
95
        // Create a new Metamodel using the EclipseLink session on the EMF
100
     * Return the DatabaseSession associated with this Metamodel
96
        this(JpaHelper.getServerSession(emf));
101
     * @return
102
     */
103
    public DatabaseSession getSession() {
104
        return this.session;
105
    }
97
    }
106
98
107
    /**
99
    /**
Lines 112-118 Link Here
112
     *  @throws IllegalArgumentException if not an embeddable class
104
     *  @throws IllegalArgumentException if not an embeddable class
113
     */
105
     */
114
    public <X> EmbeddableType<X> embeddable(Class<X> clazz) {
106
    public <X> EmbeddableType<X> embeddable(Class<X> clazz) {
115
        return (EmbeddableType<X>) this.embeddables.get(clazz);
107
        Object aType = this.embeddables.get(clazz);
108
        if(aType instanceof EmbeddableType) {
109
            return (EmbeddableType<X>) this.embeddables.get(clazz);
110
        } else {
111
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
112
                    "metamodel_class_incorrect_type_instance", 
113
                    new Object[] { clazz, "EmbeddableType", aType}));
114
        }
116
    }
115
    }
117
116
118
    /**
117
    /**
Lines 122-142 Link Here
122
     *  @throws IllegalArgumentException if not an entity
121
     *  @throws IllegalArgumentException if not an entity
123
     */
122
     */
124
    public <X> EntityType<X> entity(Class<X> clazz) {
123
    public <X> EntityType<X> entity(Class<X> clazz) {
125
        return (EntityType<X>) this.entities.get(clazz);
124
        Object aType = this.entities.get(clazz);
125
        if(aType instanceof EntityType) {
126
            return (EntityType<X>) this.entities.get(clazz);
127
        } else {
128
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
129
                    "metamodel_class_incorrect_type_instance", 
130
                    new Object[] { clazz, "EntityType", aType}));
131
        }
132
        
133
        
126
    }
134
    }
127
135
    
128
    /**
136
    /**
129
     *  Return the metamodel managed type representing the 
130
     *  entity, mapped superclass, or embeddable class.
131
     *  @param clazz  the type of the represented managed class
132
     *  @return the metamodel managed type
133
     *  @throws IllegalArgumentException if not a managed class
134
     */
135
    public <X> ManagedType<X> type(Class<X> clazz) {
136
        return (ManagedType<X>) this.managedTypes.get(clazz);
137
    }
138
139
    /**
140
     * Return the metamodel embeddable types.
137
     * Return the metamodel embeddable types.
141
     * @return the metamodel embeddable types
138
     * @return the metamodel embeddable types
142
     */
139
     */
Lines 162-167 Link Here
162
159
163
    /**
160
    /**
164
     * INTERNAL:
161
     * INTERNAL:
162
     * Return the Set of MappedSuperclassType objects
163
     * @return
164
     */
165
    public Set<MappedSuperclassTypeImpl<?>> getMappedSuperclasses() {
166
        return mappedSuperclasses;
167
    }
168
    
169
    /**
170
     * INTERNAL:
171
     * Return the DatabaseSession associated with this Metamodel
172
     * @return
173
     */
174
    public DatabaseSession getSession() {
175
        return this.session;
176
    }
177
178
    /**
179
     * INTERNAL:
180
     * Return a Type representation of a java Class for use by the Metamodel Attributes.<p>
181
     * This function will handle all Metamodel defined and core java classes.
182
     * 
183
     * @param javaClass
184
     * @return
185
     */
186
    public <X> TypeImpl<X> getType(Class<X> javaClass) {
187
        // Return an existing matching type on the metamodel keyed on class name
188
        TypeImpl type = this.types.get(javaClass);
189
        // No longer required because of delayed initialization on Types
190
        
191
        // the type was not cached yet on the metamodel - lets add it - usually a non Metamodel class like Integer
192
        if (null == type) {
193
            // make types field modification thread-safe
194
            synchronized (this.types) {
195
                // check for a cached type right after we synchronize
196
                type = this.types.get(javaClass);
197
                // We make the type one of Entity, Basic, Embeddable or MappedSuperclass
198
                if(null == type) {                    
199
                    type = new BasicTypeImpl<X>(javaClass);
200
                    // add the type to the types map keyed on Java class
201
                    this.types.put(javaClass, type);
202
                }
203
            } // synchronized end
204
        }        
205
        return type;
206
    }
207
208
    /**
209
     * INTERNAL:
210
     * Return the Map of types on this metamodel.
211
     * This includes all Entity, MappedSuperclass, Embeddable and Basic types
212
     * @return
213
     */
214
    public Map<Class, TypeImpl<?>> getTypes() {
215
        return types;
216
    }
217
    
218
    /**
219
     * INTERNAL:
165
     * Initialize the JPA metamodel that wraps the EclipseLink JPA metadata created descriptors.
220
     * Initialize the JPA metamodel that wraps the EclipseLink JPA metadata created descriptors.
166
     */
221
     */
167
    private void initialize() {
222
    private void initialize() {
Lines 208-218 Link Here
208
                // Add the MappedSuperclass to our Set of MappedSuperclasses
263
                // Add the MappedSuperclass to our Set of MappedSuperclasses
209
                this.mappedSuperclasses.add(mappedSuperclassType);
264
                this.mappedSuperclasses.add(mappedSuperclassType);
210
                
265
                
211
                // Also add the MappedSuperclass to the Map of ManagedTypes
266
                // Add the MappedSuperclass to the Map of ManagedTypes
212
                // So we can find hierarchies of the form [Entity --> MappedSuperclass(abstract) --> Entity]
267
                // So we can find hierarchies of the form [Entity --> MappedSuperclass(abstract) --> Entity]
213
                this.managedTypes.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
268
                this.managedTypes.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
214
                
269
                
215
                // Also add this MappedSuperclass to the Collection of Types
270
                // Add this MappedSuperclass to the Collection of Types
216
                this.types.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
271
                this.types.put(mappedSuperclassType.getJavaType(), mappedSuperclassType);
217
            }
272
            }
218
        } catch (Exception e) {
273
        } catch (Exception e) {
Lines 250-301 Link Here
250
    }
305
    }
251
306
252
    /**
307
    /**
253
     * INTERNAL:
308
     *  Return the metamodel managed type representing the 
254
     * Return a Type representation of a java Class for use by the Metamodel Attributes.<p>
309
     *  entity, mapped superclass, or embeddable class.
255
     * This function will handle all Metamodel defined and core java classes.
310
     *  @param clazz  the type of the represented managed class
256
     * 
311
     *  @return the metamodel managed type
257
     * @param javaClass
312
     *  @throws IllegalArgumentException if not a managed class
258
     * @return
259
     */
313
     */
260
    public <X> TypeImpl<X> getType(Class<X> javaClass) {
314
    public <X> ManagedType<X> type(Class<X> clazz) {
261
        // Return an existing matching type on the metamodel keyed on class name
315
        Object aType = this.managedTypes.get(clazz);
262
        TypeImpl type = this.types.get(javaClass);
316
        return (ManagedType<X>)aType;
263
        // No longer required because of delayed initialization on Types
317
        // IAE exception is disabled until bug# 285512 is fixed
264
        
318
/*        if(aType instanceof ManagedType) {
265
        // the type was not cached yet on the metamodel - lets add it - usually a non Metamodel class like Integer
319
            return (ManagedType<X>) this.managedTypes.get(clazz);
266
        if (null == type) {
320
        } else {
267
            // make types field modification thread-safe
321
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
268
            synchronized (this.types) {
322
                    "metamodel_class_incorrect_type_instance", 
269
                // check for a cached type right after we synchronize
323
                    new Object[] { clazz, "ManagedType", aType}));
270
                type = this.types.get(javaClass);
324
        }*/
271
                // We make the type one of Entity, Basic, Embeddable or MappedSuperclass
272
                if(null == type) {                    
273
                    type = new BasicTypeImpl<X>(javaClass);
274
                    // add the type to the types map keyed on Java class
275
                    this.types.put(javaClass, type);
276
                }
277
            } // synchronized end
278
        }        
279
        return type;
280
    }
325
    }
281
282
    /**
283
     * INTERNAL:
284
     * Return the Map of types on this metamodel.
285
     * This includes all Entity, MappedSuperclass, Embeddable and Basic types
286
     * @return
287
     */
288
    public Map<Class, TypeImpl<?>> getTypes() {
289
        return types;
290
    }
291
    
326
    
292
    /**
327
    /**
293
     * INTERNAL:
328
     * INTERNAL:
294
     * Return the Set of MappedSuperclassType objects
329
     * Return the string representation of the receiver.
295
     * @return
296
     */
330
     */
297
    public Set<MappedSuperclassTypeImpl<?>> getMappedSuperclasses() {
331
    @Override
298
        return mappedSuperclasses;
332
    public String toString() {
333
        StringBuffer aBuffer = new StringBuffer();
334
        aBuffer.append(this.getClass().getSimpleName());
335
        aBuffer.append("@");
336
        aBuffer.append(hashCode());
337
        aBuffer.append(" [");
338
        if(null != this.types) {
339
            aBuffer.append(" ");            
340
            aBuffer.append(this.types.size());
341
            aBuffer.append(" Types: ");
342
            //aBuffer.append(this.types.keySet());    
343
        } else { 
344
            aBuffer.append(" Types unitialized");
345
        }
346
        if(null != this.managedTypes) {
347
            aBuffer.append(", ");            
348
            aBuffer.append(this.managedTypes.size());
349
            aBuffer.append(" ManagedTypes: ");
350
            //aBuffer.append(this.managedTypes.keySet());    
351
        } else { 
352
            aBuffer.append(", ManagedTypes unitialized");
353
        }
354
        if(null != this.entities) {
355
            aBuffer.append(", ");            
356
            aBuffer.append(this.entities.size());
357
            aBuffer.append(" EntityTypes: ");
358
            //aBuffer.append(this.entities.keySet());    
359
        } else { 
360
            aBuffer.append(", EntityTypes unitialized");
361
        }
362
        if(null != this.mappedSuperclasses) {
363
            aBuffer.append(", ");            
364
            aBuffer.append(this.mappedSuperclasses.size());
365
            aBuffer.append(" MappedSuperclassTypes: ");
366
            //aBuffer.append(this.mappedSuperclasses);    
367
        } else { 
368
            aBuffer.append(", MappedSuperclassTypes unitialized");
369
        }
370
        if(null != this.embeddables) {
371
            aBuffer.append(", ");            
372
            aBuffer.append(this.embeddables.size());
373
            aBuffer.append(" EmbeddableTypes: ");
374
            //aBuffer.append(this.embeddables.keySet());    
375
        } else { 
376
            aBuffer.append(", EmbeddableTypes unitialized");
377
        }
378
        aBuffer.append("]");
379
        return aBuffer.toString();
299
    }
380
    }
300
301
}
381
}
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/PluralAttributeImpl.java (-4 / +25 lines)
Lines 22-28 Link Here
22
22
23
import org.eclipse.persistence.descriptors.ClassDescriptor;
23
import org.eclipse.persistence.descriptors.ClassDescriptor;
24
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
24
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
25
import org.eclipse.persistence.logging.AbstractSessionLog;
26
import org.eclipse.persistence.logging.SessionLog;
25
import org.eclipse.persistence.mappings.CollectionMapping;
27
import org.eclipse.persistence.mappings.CollectionMapping;
28
import org.eclipse.persistence.mappings.DirectCollectionMapping;
26
29
27
/**
30
/**
28
 * <p>
31
 * <p>
Lines 47-75 Link Here
47
    /** The type representing this collection type **/
50
    /** The type representing this collection type **/
48
    protected Type<V> elementType;
51
    protected Type<V> elementType;
49
    
52
    
53
50
    /**
54
    /**
51
     * INTERNAL:
55
     * INTERNAL:
56
     * Create an Attribute instance with a passed in validation flag (usually set to true only during Metamodel initialization)
52
     * @param managedType
57
     * @param managedType
53
     * @param mapping
58
     * @param mapping
59
     * @param validationEnabled
54
     */
60
     */
55
    protected PluralAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
61
    protected PluralAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
56
        // Note: Implementation is incomplete when the elementDescriptor on the containerPolicy is null
62
        // Note: 20090730 Implementation is incomplete when the elementDescriptor on the containerPolicy is null
57
        super(managedType, mapping);
63
        super(managedType, mapping);
58
59
        ClassDescriptor elementDesc = mapping.getContainerPolicy().getElementDescriptor();
64
        ClassDescriptor elementDesc = mapping.getContainerPolicy().getElementDescriptor();
60
65
66
        // Set the element type on this attribute
61
        if (elementDesc != null) {
67
        if (elementDesc != null) {
68
            // Mappings: OneToMany, 
62
            this.elementType = (Type<V>)getMetamodel().getType(elementDesc.getJavaClass());
69
            this.elementType = (Type<V>)getMetamodel().getType(elementDesc.getJavaClass());
63
        } else {
70
        } else {
64
            // TODO: BasicCollection (DirectCollectionMapping)
71
            // TODO: BasicCollection (DirectCollectionMapping)
65
            // See CollectionContainerPolicy
72
            // See CollectionContainerPolicy
66
            if(mapping.isDirectCollectionMapping() || mapping.isAbstractCompositeDirectCollectionMapping()) {// || mapping.isAbstractDirectMapping() ) {
73
            if(mapping.isDirectCollectionMapping() || mapping.isAbstractCompositeDirectCollectionMapping()) {// || mapping.isAbstractDirectMapping() ) {
67
                //CollectionContainerPolicy policy = (CollectionContainerPolicy) mapping.getContainerPolicy();
74
                //CollectionContainerPolicy policy = (CollectionContainerPolicy) mapping.getContainerPolicy();
68
                //this.elementType = getMetamodel().getType(policy.getElementDescriptor().getJavaClass());
75
                //this.elementType = getMetamodel().getType(policy.getElementDescriptor().getJavaClass());                
76
                Class attributeClass = null;
77
                if(mapping.isDirectCollectionMapping()) {
78
                    attributeClass = ((DirectCollectionMapping)mapping).getDirectField().getType();                    
79
                }
80
                if(null == attributeClass && validationEnabled) {
81
                    // TODO: refactor
82
                    attributeClass = Object.class;
83
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
84
                }
85
                this.elementType = (Type<V>)getMetamodel().getType(attributeClass);
69
            }
86
            }
70
            // TODO: Handle DirectMapContainerPolicy
87
            // TODO: Handle DirectMapContainerPolicy
71
            if(mapping.isMapKeyMapping()) {
88
            if(mapping.isMapKeyMapping()) {
72
                MapContainerPolicy policy = (MapContainerPolicy) mapping.getContainerPolicy();
89
                MapContainerPolicy policy = (MapContainerPolicy) mapping.getContainerPolicy();
90
                Class attributeClass = policy.getElementClass();
91
                if(null == attributeClass && validationEnabled) {
92
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
93
                }
73
                this.elementType = (Type<V>)getMetamodel().getType(policy.getElementClass());
94
                this.elementType = (Type<V>)getMetamodel().getType(policy.getElementClass());
74
            }
95
            }
75
        }
96
        }
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/SetAttributeImpl.java (-1 / +16 lines)
Lines 38-46 Link Here
38
 */ 
38
 */ 
39
public class SetAttributeImpl<X, V> extends PluralAttributeImpl<X, java.util.Set<V>, V> implements SetAttribute<X, V> {
39
public class SetAttributeImpl<X, V> extends PluralAttributeImpl<X, java.util.Set<V>, V> implements SetAttribute<X, V> {
40
40
41
    /**
42
     * INTERNAL:
43
     * @param managedType
44
     * @param mapping
45
     */
41
    protected SetAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
46
    protected SetAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
42
        super(managedType, mapping);
47
        super(managedType, mapping, false);
43
    }
48
    }
49
    
50
    /**
51
     * INTERNAL:
52
     * @param managedType
53
     * @param mapping
54
     * @param validationEnabled
55
     */
56
    protected SetAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
57
        super(managedType, mapping, validationEnabled);
58
    }
44
59
45
    /**
60
    /**
46
     * Return the collection type.
61
     * Return the collection type.
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/SingularAttributeImpl.java (-11 / +140 lines)
Lines 16-29 Link Here
16
 ******************************************************************************/
16
 ******************************************************************************/
17
package org.eclipse.persistence.internal.jpa.metamodel;
17
package org.eclipse.persistence.internal.jpa.metamodel;
18
18
19
import java.lang.reflect.Field;
20
19
import javax.persistence.metamodel.Bindable;
21
import javax.persistence.metamodel.Bindable;
20
import javax.persistence.metamodel.SingularAttribute;
22
import javax.persistence.metamodel.SingularAttribute;
21
import javax.persistence.metamodel.Type;
23
import javax.persistence.metamodel.Type;
22
24
25
import org.eclipse.persistence.eis.mappings.EISMapping;
23
import org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy;
26
import org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy;
27
import org.eclipse.persistence.logging.AbstractSessionLog;
28
import org.eclipse.persistence.logging.SessionLog;
29
import org.eclipse.persistence.mappings.AggregateMapping;
24
import org.eclipse.persistence.mappings.DatabaseMapping;
30
import org.eclipse.persistence.mappings.DatabaseMapping;
25
import org.eclipse.persistence.mappings.DirectToFieldMapping;
31
import org.eclipse.persistence.mappings.DirectToFieldMapping;
32
import org.eclipse.persistence.mappings.ManyToManyMapping;
33
import org.eclipse.persistence.mappings.OneToManyMapping;
26
import org.eclipse.persistence.mappings.OneToOneMapping;
34
import org.eclipse.persistence.mappings.OneToOneMapping;
35
import org.eclipse.persistence.mappings.VariableOneToOneMapping;
36
import org.eclipse.persistence.mappings.structures.ReferenceMapping;
27
37
28
/**
38
/**
29
 * <p>
39
 * <p>
Lines 42-70 Link Here
42
 * @param <T> The type of the represented attribute
52
 * @param <T> The type of the represented attribute
43
 * 
53
 * 
44
 */
54
 */
45
public class SingularAttributeImpl<X,T> extends AttributeImpl<X,T> implements SingularAttribute<X, T> {
55
public class SingularAttributeImpl<X, T> extends AttributeImpl<X, T> implements SingularAttribute<X, T> {
46
56
47
    /** The Type representing this Entity or Basic type **/
57
    /** The Type representing this Entity or Basic type **/
48
    protected Type<T> elementType;
58
    protected Type<T> elementType;
59
60
    /**
61
     * Create an instance of the Attribute
62
     * @param managedType
63
     * @param mapping
64
     */
65
    protected SingularAttributeImpl(ManagedTypeImpl<X> managedType, DatabaseMapping mapping) {
66
        this(managedType, mapping, false);
67
    }
49
    
68
    
50
    protected SingularAttributeImpl(ManagedTypeImpl<X> managedType, DatabaseMapping mapping) {
69
    /**
70
     * INTERNAL:
71
     * Create an Attribute instance with a passed in validation flag (usually set to true only during Metamodel initialization)
72
     * @param managedType
73
     * @param mapping
74
     * @param validationEnabled
75
     */
76
    protected SingularAttributeImpl(ManagedTypeImpl<X> managedType, DatabaseMapping mapping, boolean validationEnabled) {
51
        super(managedType, mapping);
77
        super(managedType, mapping);
52
        Class attributeClassification = mapping.getAttributeClassification();
78
        Class attributeClass = mapping.getAttributeClassification();
53
79
54
        if (null == attributeClassification) {
80
        // The attribute classification is null for non-collection mappings
81
        if (null == attributeClass) { // BasicType will != null --> else clause
55
            // EntityType
82
            // EntityType
56
            // We support @OneToOne but not EIS, Reference or VariableOneToOne
83
            // We support @OneToOne but not EIS, Reference or VariableOneToOne
57
            if(mapping.isOneToOneMapping()) {
84
            if(mapping.isOneToOneMapping()) {
58
                elementType = (Type<T>)getMetamodel().getType(
85
                attributeClass = ((OneToOneMapping)mapping).getReferenceClass();
59
                        ((OneToOneMapping)mapping).getReferenceClass());
86
                if(null == attributeClass && validationEnabled) {
87
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
88
                }
89
            } else if (mapping.isOneToManyMapping()) {
90
                // TODO: verify
91
                attributeClass = ((OneToManyMapping)mapping).getReferenceClass();
92
                if(null == attributeClass && validationEnabled) {
93
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
94
                }
95
            } else if (mapping.isManyToManyMapping()) {
96
                // TODO: verify
97
                attributeClass = ((ManyToManyMapping)mapping).getReferenceClass();
98
                if(null == attributeClass && validationEnabled) {
99
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
100
                }
101
            } else if (mapping.isAggregateObjectMapping()) { // IE: EmbeddedId
102
                attributeClass = ((AggregateMapping)mapping).getReferenceClass();
103
                if(null == attributeClass && validationEnabled) {
104
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);            
105
                }                
106
            } else if (mapping.isVariableOneToOneMapping()) { // interfaces are unsupported in the JPA 2.0 spec for the Metamodel API
107
                if(validationEnabled) {
108
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_mapping_type_is_unsupported", mapping, this);                    
109
                }
110
                // see JUnitCriteriaUnitTestSuite.testSelectPhoneNumberAreaCode() line: 246
111
                // VariableOneToOne mappings are unsupported - default to referenceClass  (Interface) anyway
112
                attributeClass = ((VariableOneToOneMapping)mapping).getReferenceClass();
113
                if(null == attributeClass && validationEnabled) {
114
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);            
115
                }                
116
                
117
            } else if (mapping.isEISMapping()) { // unsupported in the JPA 2.0 spec for the Metamodel API
118
                if(validationEnabled) {
119
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_mapping_type_is_unsupported", mapping, this);                    
120
                }
121
                // TODO: refactor
122
                // VariableOneToOne mappings are unsupported - default to Object:
123
                attributeClass = Object.class;
124
            } else if ( mapping.isReferenceMapping()) { // unsupported in the JPA 2.0 spec for the Metamodel API
125
                if(validationEnabled) {
126
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_mapping_type_is_unsupported", mapping, this);                    
127
                }
128
                // VariableOneToOne mappings are unsupported - default to referenceClass anyway
129
                attributeClass = ((ReferenceMapping)mapping).getReferenceClass();
130
                if(null == attributeClass && validationEnabled) {
131
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);            
132
                }                
133
            } else if (mapping.isDirectToFieldMapping()) { // Also handles the keys of an EmbeddedId
134
                attributeClass = mapping.getField().getType();
135
                if(null == attributeClass) {
136
                    // lookup the attribute on the containing class                    
137
                    Class containingClass = mapping.getDescriptor().getJavaClass();
138
                    Field aField = null;
139
                    try {
140
                        aField = containingClass.getDeclaredField(mapping.getAttributeName());
141
                        attributeClass = aField.getType();
142
                    } catch (NoSuchFieldException nsfe) {
143
                        // This exception will be warned about below
144
                        //nsfe.printStackTrace();
145
                    }                    
146
                }
147
                // all Direct mappings that don't have a type on their field
148
                if(null == attributeClass && validationEnabled) {
149
                    // TODO: refactor
150
                    attributeClass = Object.class;
151
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
152
                }
60
            } else {
153
            } else {
61
                // TODO: default to containing class
154
                // All unsupported mappings
62
                elementType = (Type<T>)getMetamodel().getType(managedType.getJavaType()); 
155
                if(null == attributeClass && validationEnabled) {
156
                    // TODO: refactor
157
                    attributeClass = Object.class;
158
                    AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);                    
159
                }
63
            }
160
            }
64
        } else {
65
            // BasicType
66
            elementType = (Type<T>)getMetamodel().getType(attributeClassification);
67
        }
161
        }
162
        elementType = (Type<T>)getMetamodel().getType(attributeClass);        
68
    }
163
    }
69
164
70
    /**
165
    /**
Lines 121-126 Link Here
121
    }
216
    }
122
    
217
    
123
    /**
218
    /**
219
     *  Return the Java type of the represented attribute.
220
     *  @return Java type
221
     */
222
    @Override
223
    public Class<T> getJavaType() {
224
        if(null == elementType) {
225
            Class aJavaType = getMapping().getAttributeClassification(); // returns null for OneToManyMapping
226
            if(null == aJavaType) {
227
                aJavaType = getMapping().getField().getType();
228
                if(null == aJavaType) {
229
                    // lookup the attribute on the containing class                    
230
                    Class containingClass = getMapping().getDescriptor().getJavaClass();
231
                    Field aField = null;
232
                    try {
233
                        aField = containingClass.getDeclaredField(getMapping().getAttributeName());
234
                        aJavaType = aField.getType();
235
                        return aJavaType;
236
                    } catch (NoSuchFieldException nsfe) {
237
                        // This exception will be warned about below
238
                        //nsfe.printStackTrace();
239
                        if(null == aJavaType) {
240
                            AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this);
241
                            return (Class<T>)Object.class;
242
                        }
243
                    }                    
244
                }
245
            }
246
            return aJavaType;
247
        } else {
248
            return this.elementType.getJavaType();
249
        }
250
    }
251
    
252
    /**
124
     * Return the type that represents the type of the attribute.
253
     * Return the type that represents the type of the attribute.
125
     * @return type of attribute
254
     * @return type of attribute
126
     */
255
     */
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/TypeImpl.java (+33 lines)
Lines 51-56 Link Here
51
51
52
    /**
52
    /**
53
     * INTERNAL:
53
     * INTERNAL:
54
     * Return whether this type is an Entity (true) or MappedSuperclass (false) or Embeddable (false)
55
     * @return
56
     */
57
    public abstract boolean isEntity();
58
    
59
    /**
60
     * INTERNAL:
54
     * Return whether this type is identifiable.
61
     * Return whether this type is identifiable.
55
     * This would be EntityType and MappedSuperclassType
62
     * This would be EntityType and MappedSuperclassType
56
     * @return
63
     * @return
Lines 64-67 Link Here
64
     * @return
71
     * @return
65
     */
72
     */
66
    public abstract boolean isManagedType();
73
    public abstract boolean isManagedType();
74
    
75
    /**
76
     * INTERNAL:
77
     * Return whether this type is an MappedSuperclass (true) or Entity (false) or Embeddable (false)
78
     * @return
79
     */
80
    public abstract boolean isMappedSuperclass();
81
82
    /**
83
     * INTERNAL:
84
     * Return the string representation of the receiver.
85
     */
86
    @Override
87
    public String toString() {
88
        StringBuffer aBuffer = new StringBuffer();
89
        aBuffer.append(this.getClass().getSimpleName());
90
        aBuffer.append("@");
91
        aBuffer.append(hashCode());
92
        aBuffer.append(" [ javaType: ");
93
        aBuffer.append(this.getJavaType());
94
        toStringHelper(aBuffer);
95
        aBuffer.append("]");
96
        return aBuffer.toString();
97
    }
98
99
    protected abstract void toStringHelper(StringBuffer aBuffer);
67
}
100
}

Return to bug 266912