|
Lines 11-16
Link Here
|
| 11 |
* Oracle - initial API and implementation from Oracle TopLink |
11 |
* Oracle - initial API and implementation from Oracle TopLink |
| 12 |
* 07/16/2009-2.0 Guy Pelletier |
12 |
* 07/16/2009-2.0 Guy Pelletier |
| 13 |
* - 277039: JPA 2.0 Cache Usage Settings |
13 |
* - 277039: JPA 2.0 Cache Usage Settings |
|
|
14 |
* 11/19/2009-2.0 Michael O'Brien |
| 15 |
* - 288972: skip initialization of inherited Id mappings declared on |
| 16 |
* MappedSuperclass RelationalDescriptors that were introduced as |
| 17 |
* partially initialized descriptors for 266912 in support of the JPA 2.0 implementation. |
| 14 |
******************************************************************************/ |
18 |
******************************************************************************/ |
| 15 |
package org.eclipse.persistence.internal.descriptors; |
19 |
package org.eclipse.persistence.internal.descriptors; |
| 16 |
|
20 |
|
|
Lines 2281-2286
Link Here
|
| 2281 |
getCloningMappings().clear(); |
2285 |
getCloningMappings().clear(); |
| 2282 |
getEagerMappings().clear(); |
2286 |
getEagerMappings().clear(); |
| 2283 |
getRelationshipMappings().clear(); |
2287 |
getRelationshipMappings().clear(); |
|
|
2288 |
// 288972: relax validation rules for descriptors representing MappedSuperclasses |
| 2289 |
boolean containsMappedSuperclassDeclaredIdMappings = false; |
| 2284 |
|
2290 |
|
| 2285 |
for (Enumeration mappings = this.descriptor.getMappings().elements(); |
2291 |
for (Enumeration mappings = this.descriptor.getMappings().elements(); |
| 2286 |
mappings.hasMoreElements();) { |
2292 |
mappings.hasMoreElements();) { |
|
Lines 2312-2362
Link Here
|
| 2312 |
} |
2318 |
} |
| 2313 |
|
2319 |
|
| 2314 |
// Add field to mapping association |
2320 |
// Add field to mapping association |
| 2315 |
for (DatabaseField field : mapping.getFields()) { |
2321 |
// 288972: skip initialization of id mappings declared above on mappedSuperclasses - as the fields are not initialized on the descriptor by design |
| 2316 |
|
2322 |
if(!getDescriptor().shouldSkipInitializationForMappedSuperclassIdMapping(mapping, session)) { |
| 2317 |
if (mapping.isReadOnly()) { |
2323 |
for (DatabaseField field : mapping.getFields()) { |
| 2318 |
List readOnlyMappings = getReadOnlyMappingsByField().get(field); |
2324 |
if (mapping.isReadOnly()) { |
|
|
2325 |
List readOnlyMappings = getReadOnlyMappingsByField().get(field); |
| 2319 |
|
2326 |
|
| 2320 |
if (readOnlyMappings == null) { |
2327 |
if (readOnlyMappings == null) { |
| 2321 |
readOnlyMappings = new ArrayList(); |
2328 |
readOnlyMappings = new ArrayList(); |
| 2322 |
getReadOnlyMappingsByField().put(field, readOnlyMappings); |
2329 |
getReadOnlyMappingsByField().put(field, readOnlyMappings); |
| 2323 |
} |
2330 |
} |
| 2324 |
|
2331 |
|
| 2325 |
readOnlyMappings.add(mapping); |
2332 |
readOnlyMappings.add(mapping); |
| 2326 |
} else { |
2333 |
} else { |
| 2327 |
if (mapping.isAggregateObjectMapping()) { |
2334 |
if (mapping.isAggregateObjectMapping()) { |
| 2328 |
// For Embeddable class, we need to test read-only |
2335 |
// For Embeddable class, we need to test read-only |
| 2329 |
// status of individual fields in the embeddable. |
2336 |
// status of individual fields in the embeddable. |
| 2330 |
ObjectBuilder aggregateObjectBuilder = ((AggregateObjectMapping)mapping).getReferenceDescriptor().getObjectBuilder(); |
2337 |
ObjectBuilder aggregateObjectBuilder = ((AggregateObjectMapping)mapping).getReferenceDescriptor().getObjectBuilder(); |
| 2331 |
|
2338 |
|
| 2332 |
// Look in the non-read-only fields mapping |
2339 |
// Look in the non-read-only fields mapping |
| 2333 |
DatabaseMapping aggregatedFieldMapping = aggregateObjectBuilder.getMappingForField(field); |
2340 |
DatabaseMapping aggregatedFieldMapping = aggregateObjectBuilder.getMappingForField(field); |
| 2334 |
|
2341 |
|
| 2335 |
if (aggregatedFieldMapping == null) { // mapping must be read-only |
2342 |
if (aggregatedFieldMapping == null) { // mapping must be read-only |
| 2336 |
List readOnlyMappings = getReadOnlyMappingsByField().get(field); |
2343 |
List readOnlyMappings = getReadOnlyMappingsByField().get(field); |
| 2337 |
|
2344 |
|
| 2338 |
if (readOnlyMappings == null) { |
2345 |
if (readOnlyMappings == null) { |
| 2339 |
readOnlyMappings = new ArrayList(); |
2346 |
readOnlyMappings = new ArrayList(); |
| 2340 |
getReadOnlyMappingsByField().put(field, readOnlyMappings); |
2347 |
getReadOnlyMappingsByField().put(field, readOnlyMappings); |
|
|
2348 |
} |
| 2349 |
|
| 2350 |
readOnlyMappings.add(mapping); |
| 2351 |
} else { |
| 2352 |
getMappingsByField().put(field, mapping); |
| 2341 |
} |
2353 |
} |
| 2342 |
|
2354 |
} else { // Not an embeddable mapping |
| 2343 |
readOnlyMappings.add(mapping); |
2355 |
if (getMappingsByField().containsKey(field) || mapping.getDescriptor().getAdditionalWritableMapKeyFields().contains(field)) { |
| 2344 |
} else { |
2356 |
session.getIntegrityChecker().handleError(DescriptorException.multipleWriteMappingsForField(field.toString(), mapping)); |
| 2345 |
getMappingsByField().put(field, mapping); |
2357 |
} else { |
|
|
2358 |
getMappingsByField().put(field, mapping); |
| 2359 |
} |
| 2346 |
} |
2360 |
} |
| 2347 |
} else { // Not an embeddable mapping |
|
|
| 2348 |
if (getMappingsByField().containsKey(field) || mapping.getDescriptor().getAdditionalWritableMapKeyFields().contains(field)) { |
| 2349 |
session.getIntegrityChecker().handleError(DescriptorException.multipleWriteMappingsForField(field.toString(), mapping)); |
| 2350 |
} else { |
| 2351 |
getMappingsByField().put(field, mapping); |
| 2352 |
} |
| 2353 |
} |
2361 |
} |
| 2354 |
} |
2362 |
} |
|
|
2363 |
} else { |
| 2364 |
containsMappedSuperclassDeclaredIdMappings = true; |
| 2355 |
} |
2365 |
} |
| 2356 |
} |
2366 |
} |
| 2357 |
this.isSimple = getRelationshipMappings().isEmpty(); |
2367 |
this.isSimple = getRelationshipMappings().isEmpty(); |
| 2358 |
|
2368 |
|
| 2359 |
initializePrimaryKey(session); |
2369 |
initializePrimaryKey(session, containsMappedSuperclassDeclaredIdMappings); |
| 2360 |
initializeJoinedAttributes(); |
2370 |
initializeJoinedAttributes(); |
| 2361 |
|
2371 |
|
| 2362 |
if (this.descriptor.usesSequenceNumbers()) { |
2372 |
if (this.descriptor.usesSequenceNumbers()) { |
|
Lines 2434-2441
Link Here
|
| 2434 |
|
2444 |
|
| 2435 |
/** |
2445 |
/** |
| 2436 |
* Cache primary key and non primary key mappings. |
2446 |
* Cache primary key and non primary key mappings. |
|
|
2447 |
* @param session |
| 2448 |
* @throws DescriptorException |
| 2437 |
*/ |
2449 |
*/ |
| 2438 |
public void initializePrimaryKey(AbstractSession session) throws DescriptorException { |
2450 |
public void initializePrimaryKey(AbstractSession session) throws DescriptorException { |
|
|
2451 |
initializePrimaryKey(session, false); |
| 2452 |
} |
| 2453 |
|
| 2454 |
/** |
| 2455 |
* INTERNAL: |
| 2456 |
* Cache primary key and non primary key mappings. |
| 2457 |
* @param session |
| 2458 |
* @param containsMappedSuperclassDeclaredIdMappings |
| 2459 |
* @throws DescriptorException |
| 2460 |
*/ |
| 2461 |
public void initializePrimaryKey(AbstractSession session, boolean containsMappedSuperclassDeclaredIdMappings) throws DescriptorException { |
| 2439 |
List primaryKeyFields = this.descriptor.getPrimaryKeyFields(); |
2462 |
List primaryKeyFields = this.descriptor.getPrimaryKeyFields(); |
| 2440 |
if(primaryKeyFields.isEmpty() && getDescriptor().isAggregateCollectionDescriptor()) { |
2463 |
if(primaryKeyFields.isEmpty() && getDescriptor().isAggregateCollectionDescriptor()) { |
| 2441 |
// populate primaryKeys with all mapped fields found in the main table. |
2464 |
// populate primaryKeys with all mapped fields found in the main table. |
|
Lines 2479-2509
Link Here
|
| 2479 |
if(this.descriptor.isDescriptorTypeAggregate()) { |
2502 |
if(this.descriptor.isDescriptorTypeAggregate()) { |
| 2480 |
this.mayHaveNullInPrimaryKey = true; |
2503 |
this.mayHaveNullInPrimaryKey = true; |
| 2481 |
} else { |
2504 |
} else { |
| 2482 |
throw DescriptorException.noMappingForPrimaryKey(primaryKeyField, this.descriptor); |
2505 |
// 288972: skip initialization of id mappings on mappedSuperclasses - as the fields are not initialized on the descriptor |
|
|
2506 |
if(!containsMappedSuperclassDeclaredIdMappings) { |
| 2507 |
throw DescriptorException.noMappingForPrimaryKey(primaryKeyField, this.descriptor); |
| 2508 |
} |
| 2483 |
} |
2509 |
} |
| 2484 |
} |
2510 |
} |
|
|
2511 |
if(!containsMappedSuperclassDeclaredIdMappings) { |
| 2512 |
getPrimaryKeyMappings().add(mapping); |
| 2513 |
if (mapping != null) { |
| 2514 |
mapping.setIsPrimaryKeyMapping(true); |
| 2515 |
} |
| 2485 |
|
2516 |
|
| 2486 |
getPrimaryKeyMappings().add(mapping); |
2517 |
// Use the same mapping to map the additional table primary key fields. |
| 2487 |
if (mapping != null) { |
2518 |
// This is required if someone tries to map to one of these fields. |
| 2488 |
mapping.setIsPrimaryKeyMapping(true); |
2519 |
if (this.descriptor.hasMultipleTables() && (mapping != null)) { |
| 2489 |
} |
2520 |
for (Map keyMapping : this.descriptor.getAdditionalTablePrimaryKeyFields().values()) { |
|
|
2521 |
DatabaseField secondaryField = (DatabaseField) keyMapping.get(primaryKeyField); |
| 2490 |
|
2522 |
|
| 2491 |
// Use the same mapping to map the additional table primary key fields. |
2523 |
// This can be null in the custom multiple join case |
| 2492 |
// This is required if someone tries to map to one of these fields. |
2524 |
if (secondaryField != null) { |
| 2493 |
if (this.descriptor.hasMultipleTables() && (mapping != null)) { |
2525 |
getMappingsByField().put(secondaryField, mapping); |
| 2494 |
for (Map keyMapping : this.descriptor.getAdditionalTablePrimaryKeyFields().values()) { |
|
|
| 2495 |
DatabaseField secondaryField = (DatabaseField) keyMapping.get(primaryKeyField); |
| 2496 |
|
2526 |
|
| 2497 |
// This can be null in the custom multiple join case |
2527 |
if (mapping.isAggregateObjectMapping()) { |
| 2498 |
if (secondaryField != null) { |
2528 |
// GF#1153,1391 |
| 2499 |
getMappingsByField().put(secondaryField, mapping); |
2529 |
// If AggregateObjectMapping contain primary keys and the descriptor has multiple tables |
| 2500 |
|
2530 |
// AggregateObjectMapping should know the the primary key join columns (secondaryField here) |
| 2501 |
if (mapping.isAggregateObjectMapping()) { |
2531 |
// to handle some cases properly |
| 2502 |
// GF#1153,1391 |
2532 |
((AggregateObjectMapping) mapping).addPrimaryKeyJoinField(primaryKeyField, secondaryField); |
| 2503 |
// If AggregateObjectMapping contain primary keys and the descriptor has multiple tables |
2533 |
} |
| 2504 |
// AggregateObjectMapping should know the the primary key join columns (secondaryField here) |
|
|
| 2505 |
// to handle some cases properly |
| 2506 |
((AggregateObjectMapping) mapping).addPrimaryKeyJoinField(primaryKeyField, secondaryField); |
| 2507 |
} |
2534 |
} |
| 2508 |
} |
2535 |
} |
| 2509 |
} |
2536 |
} |