|
Lines 31-36
Link Here
|
| 31 |
* - 266912: change mappedSuperclassDescriptors Set to a Map |
31 |
* - 266912: change mappedSuperclassDescriptors Set to a Map |
| 32 |
* keyed on MetadataClass - avoiding the use of a hashCode/equals |
32 |
* keyed on MetadataClass - avoiding the use of a hashCode/equals |
| 33 |
* override on RelationalDescriptor, but requiring a contains check prior to a put |
33 |
* override on RelationalDescriptor, but requiring a contains check prior to a put |
|
|
34 |
* 06/18/2009-2.0 Michael O'Brien |
| 35 |
* - 266912: change MappedSuperclass handling in stage2 to pre process accessors |
| 34 |
******************************************************************************/ |
36 |
******************************************************************************/ |
| 35 |
package org.eclipse.persistence.internal.jpa.metadata; |
37 |
package org.eclipse.persistence.internal.jpa.metadata; |
| 36 |
|
38 |
|
|
Lines 186-191
Link Here
|
| 186 |
// the correct owning descriptor. |
188 |
// the correct owning descriptor. |
| 187 |
private HashSet<EmbeddableAccessor> m_rootEmbeddableAccessors; |
189 |
private HashSet<EmbeddableAccessor> m_rootEmbeddableAccessors; |
| 188 |
|
190 |
|
|
|
191 |
// All mappedSuperclass accessors, identity is handled by keying on className |
| 192 |
private HashMap<String, MappedSuperclassAccessor> m_mappedSuperclassAccessors; |
| 193 |
|
| 189 |
/** |
194 |
/** |
| 190 |
* INTERNAL: |
195 |
* INTERNAL: |
| 191 |
* Create and return a new MetadataProject with puInfo as its PersistenceUnitInfo, |
196 |
* Create and return a new MetadataProject with puInfo as its PersistenceUnitInfo, |
|
Lines 228-233
Link Here
|
| 228 |
m_converters = new HashMap<String, AbstractConverterMetadata>(); |
233 |
m_converters = new HashMap<String, AbstractConverterMetadata>(); |
| 229 |
|
234 |
|
| 230 |
m_accessorsWithDerivedIDs = new HashSet<ClassAccessor>(); |
235 |
m_accessorsWithDerivedIDs = new HashSet<ClassAccessor>(); |
|
|
236 |
|
| 237 |
m_mappedSuperclassAccessors = new HashMap<String, MappedSuperclassAccessor>(); |
| 231 |
} |
238 |
} |
| 232 |
|
239 |
|
| 233 |
/** |
240 |
/** |
|
Lines 972-978
Link Here
|
| 972 |
// into Descriptors and Login |
979 |
// into Descriptors and Login |
| 973 |
boolean usesAuto = false; |
980 |
boolean usesAuto = false; |
| 974 |
for (MetadataClass entityClass : m_generatedValues.keySet()) { |
981 |
for (MetadataClass entityClass : m_generatedValues.keySet()) { |
| 975 |
MetadataDescriptor descriptor = m_allAccessors.get(entityClass.getName()).getDescriptor(); |
982 |
// 266912: skip setting sequences if our accessor is null for mappedSuperclasses |
|
|
983 |
ClassAccessor accessor = m_allAccessors.get(entityClass.getName()); |
| 984 |
// TODO: fully review this if check |
| 985 |
// If the accessor is not found then it should be in our processing map for MappedSuperclasses |
| 986 |
if(null == accessor) { |
| 987 |
accessor = this.m_mappedSuperclassAccessors.get(entityClass.getName()); |
| 988 |
} |
| 989 |
|
| 990 |
MetadataDescriptor descriptor = accessor.getDescriptor(); |
| 976 |
GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass); |
991 |
GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass); |
| 977 |
String generatorName = generatedValue.getGenerator(); |
992 |
String generatorName = generatedValue.getGenerator(); |
| 978 |
|
993 |
|
|
Lines 1022-1028
Link Here
|
| 1022 |
login.addSequence(sequence); |
1037 |
login.addSequence(sequence); |
| 1023 |
} else { |
1038 |
} else { |
| 1024 |
String seqName; |
1039 |
String seqName; |
| 1025 |
|
1040 |
|
| 1026 |
if (generatorName.equals("")) { |
1041 |
if (generatorName.equals("")) { |
| 1027 |
if (defaultAutoSequence != null) { |
1042 |
if (defaultAutoSequence != null) { |
| 1028 |
seqName = defaultAutoSequence.getName(); |
1043 |
seqName = defaultAutoSequence.getName(); |
|
Lines 1036-1042
Link Here
|
| 1036 |
descriptor.setSequenceNumberName(seqName); |
1051 |
descriptor.setSequenceNumberName(seqName); |
| 1037 |
} |
1052 |
} |
| 1038 |
} |
1053 |
} |
| 1039 |
|
1054 |
|
| 1040 |
if (usesAuto) { |
1055 |
if (usesAuto) { |
| 1041 |
if (defaultAutoSequence != null) { |
1056 |
if (defaultAutoSequence != null) { |
| 1042 |
login.setDefaultSequence(defaultAutoSequence); |
1057 |
login.setDefaultSequence(defaultAutoSequence); |
|
Lines 1093-1100
Link Here
|
| 1093 |
* @see processStage3 |
1108 |
* @see processStage3 |
| 1094 |
*/ |
1109 |
*/ |
| 1095 |
public void processStage2() { |
1110 |
public void processStage2() { |
| 1096 |
// Mapped superclasses and embeddables are processed through the entity |
1111 |
// 266912: process mappedSuperclasses without going to the database |
| 1097 |
// processing. |
1112 |
for(MappedSuperclassAccessor msAccessor : m_mappedSuperclassAccessors.values()) { |
|
|
1113 |
if(!msAccessor.isProcessed()) { |
| 1114 |
msAccessor.processMetamodelDescriptor(); |
| 1115 |
} |
| 1116 |
} |
| 1117 |
|
| 1098 |
for (EntityAccessor entity : getEntityAccessors()) { |
1118 |
for (EntityAccessor entity : getEntityAccessors()) { |
| 1099 |
// If the accessor hasn't been processed yet, then process it. An |
1119 |
// If the accessor hasn't been processed yet, then process it. An |
| 1100 |
// EntityAccessor may get fast tracked if it is an inheritance |
1120 |
// EntityAccessor may get fast tracked if it is an inheritance |
|
Lines 1123-1129
Link Here
|
| 1123 |
|
1143 |
|
| 1124 |
// 2 - Process all the direct collection accessors we found. This list |
1144 |
// 2 - Process all the direct collection accessors we found. This list |
| 1125 |
// does not include direct collections to an embeddable class. |
1145 |
// does not include direct collections to an embeddable class. |
| 1126 |
processDirectCollectionAccessors(); |
1146 |
processDirectCollectionAccessors(); |
| 1127 |
|
1147 |
|
| 1128 |
// 3 - Process the sequencing metadata now that every entity has a |
1148 |
// 3 - Process the sequencing metadata now that every entity has a |
| 1129 |
// validated primary key. |
1149 |
// validated primary key. |
|
Lines 1211-1235
Link Here
|
| 1211 |
|
1231 |
|
| 1212 |
/** |
1232 |
/** |
| 1213 |
* INTERNAL: |
1233 |
* INTERNAL: |
| 1214 |
* Add new descriptors for these mapped superclasses to the core project. |
1234 |
* The metamodel API requires that descriptors exist for |
| 1215 |
* The metadataProject handles interaction with the native project. |
1235 |
* mappedSuperclasses in order to obtain their mappings.<p> |
|
|
1236 |
* In order to accomplish this, this method that is called from EntityAccessor |
| 1237 |
* will ensure that the descriptors on all mappedSuperclass accessors |
| 1238 |
* are setup so that they can be specially processed later in |
| 1239 |
* MetadataProject.processStage2() - where the m_mappedSuperclassAccessors |
| 1240 |
* Set is required. |
| 1241 |
* <p> |
| 1242 |
* This method is referenced by EntityAccessor.addPotentialMappedSuperclass() |
| 1243 |
* </p> |
| 1244 |
* @param metadataClass - the |
| 1245 |
* @param accessor - The mappedSuperclass accessor for the field on the mappedSuperclass<p> |
| 1246 |
* @since EclipseLink 2.0 for the JPA 2.0 Reference Implementation |
| 1216 |
*/ |
1247 |
*/ |
| 1217 |
public void addMappedSuperclassToProject(MetadataClass metadataClass) { |
1248 |
public void addMappedSuperclassAccessor(MetadataClass metadataClass, MappedSuperclassAccessor accessor) { |
| 1218 |
// 266912: store the mapped superclass as a descriptor on the project |
1249 |
// If metadataClass is null, then get it from the location on the accessor |
| 1219 |
// for later use by the Metamodel API |
1250 |
String className = metadataClass.getName(); |
| 1220 |
// We pass through here more than once - we rely on the Set implementation to handle no duplicates |
1251 |
|
| 1221 |
RelationalDescriptor msDescriptor = new RelationalDescriptor(); |
1252 |
// check for an existing entry before proceeding - as a Map.put() will replace the existing accessor |
| 1222 |
msDescriptor.setAlias(metadataClass.getName()); |
1253 |
// TODO: handle equal classnames for different classLoaders in multiple containers |
| 1223 |
// Set the javaClassName only on the descriptor and use this as the key |
1254 |
if(null != className && !m_mappedSuperclassAccessors.containsKey(className)) { |
| 1224 |
// when the descriptor is part of a set |
1255 |
accessor.processAccessType(); |
| 1225 |
// The javaClass itself will be set on the descriptor later when we have the correct classLoader |
1256 |
// Generics Handler: Check if the referenceType is not set for Collection accessors |
| 1226 |
msDescriptor.setJavaClassName(metadataClass.getName()); |
1257 |
accessor.addAccessors(); |
| 1227 |
// Add the mapped superclass to the native project keyed by MetadataClass |
1258 |
m_mappedSuperclassAccessors.put(className, accessor); |
| 1228 |
m_session.getProject().addMappedSuperclass(metadataClass, msDescriptor); |
1259 |
RelationalDescriptor descriptor = (RelationalDescriptor)accessor.getDescriptor().getClassDescriptor(); |
| 1229 |
} |
1260 |
// Fake out a database table and primary key |
|
|
1261 |
// We require string names for table processing that does not actually goto the database. |
| 1262 |
// There will be no conflict with customer values |
| 1263 |
// The descriptor is assumed never to be null |
| 1264 |
if(null == descriptor.getTableName() && descriptor.getPrimaryKeyFieldNames().isEmpty()) { |
| 1265 |
descriptor.setTableName(MetadataConstants.MAPPED_SUPERCLASS_RESERVED_TABLE_NAME); |
| 1266 |
descriptor.setPrimaryKeyFieldName(MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME); |
| 1267 |
// TODO: handle multiple table PK fields using a FK |
| 1268 |
if(accessor.getIdClassName() != null) { |
| 1269 |
descriptor.addPrimaryKeyFieldName(MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME); |
| 1270 |
accessor.getDescriptor().addPKClassId(MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME, |
| 1271 |
accessor.getIdClassName()); |
| 1272 |
} |
| 1273 |
} |
| 1274 |
// The javaClassName is set, the javaClass itself will be set on the descriptor later when we have the correct classLoader |
| 1275 |
// We store our descriptor on the core project for later retrieval by MetamodelImpl |
| 1276 |
m_session.getProject().addMappedSuperclass(metadataClass, descriptor); |
| 1277 |
} // TODO: verify that the first accessor is sufficient and that we do not require replacement of merging |
| 1278 |
} |
| 1230 |
|
1279 |
|
| 1231 |
/** |
1280 |
/** |
| 1232 |
* INTERNAL: |
1281 |
* INTERNAL: |
|
|
1282 |
* Return the Set of MappedSuperclassAccessors |
| 1283 |
* @since EclipseLink 2.0 for the JPA 2.0 Reference Implementation |
| 1284 |
*/ |
| 1285 |
public HashMap<String, MappedSuperclassAccessor> getMappedSuperclassAccessors() { |
| 1286 |
return m_mappedSuperclassAccessors; |
| 1287 |
} |
| 1288 |
|
| 1289 |
/** |
| 1290 |
* INTERNAL: |
| 1233 |
* get the mapped superclasses stored on the core project. |
1291 |
* get the mapped superclasses stored on the core project. |
| 1234 |
* The metadataProject handles interaction with the native project. |
1292 |
* The metadataProject handles interaction with the native project. |
| 1235 |
* @param metadataClass - java class name key is extracted from the MetadataClass |
1293 |
* @param metadataClass - java class name key is extracted from the MetadataClass |
|
Lines 1245-1249
Link Here
|
| 1245 |
return relationalDescriptor; |
1303 |
return relationalDescriptor; |
| 1246 |
} |
1304 |
} |
| 1247 |
|
1305 |
|
| 1248 |
} |
1306 |
/** |
|
|
1307 |
* INTERNAL: |
| 1308 |
* Return whether the project contains a mappedSuperclass matching the metadataClass |
| 1309 |
* @param metadataClass |
| 1310 |
*/ |
| 1311 |
public boolean hasMappedSuperclassAccessor(MetadataClass metadataClass) { |
| 1312 |
return m_mappedSuperclasses.containsKey(metadataClass.getName()); |
| 1313 |
} |
| 1314 |
|
| 1315 |
} |
| 1249 |
|
1316 |
|