|
Lines 31-36
Link Here
|
| 31 |
* 08/08/2009-2.0 mobrien - 266912: implement Collection and List separation during attribute initialization |
31 |
* 08/08/2009-2.0 mobrien - 266912: implement Collection and List separation during attribute initialization |
| 32 |
* - see design issue #58 |
32 |
* - see design issue #58 |
| 33 |
* http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List |
33 |
* http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List |
|
|
34 |
* 08/17/2009-2.0 mobrien - 284877: The base case for the recursive function |
| 35 |
* managedTypeImpl.hasDeclaredAttribute() does not handle use case 1.4 (root-level managedType) |
| 36 |
* when the caller of the function does not do it's own inheritedType check. |
| 37 |
* - see design issue #52 |
| 38 |
* http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI:52_Refactor:_20090817 |
| 34 |
******************************************************************************/ |
39 |
******************************************************************************/ |
| 35 |
package org.eclipse.persistence.internal.jpa.metamodel; |
40 |
package org.eclipse.persistence.internal.jpa.metamodel; |
| 36 |
|
41 |
|
|
Lines 220-233
Link Here
|
| 220 |
// get the attribute parameterized by <Owning type, return Type> - throw an IAE if not found (no need to check hierarchy) |
225 |
// get the attribute parameterized by <Owning type, return Type> - throw an IAE if not found (no need to check hierarchy) |
| 221 |
// Handles UC1 and UC2 |
226 |
// Handles UC1 and UC2 |
| 222 |
Attribute<X, ?> anAttribute = getAttribute(name); |
227 |
Attribute<X, ?> anAttribute = getAttribute(name); |
| 223 |
// Check the hierarchy for a declaration in the superclass(s) - keep moving up only when the attribute is not found |
228 |
// If an Attribute is found then check the hierarchy for a declaration in the superclass(s) |
| 224 |
ManagedTypeImpl aManagedSuperType = getManagedSuperType(); |
229 |
// Keep moving up only when the attribute is not found |
|
|
230 |
ManagedTypeImpl aManagedSuperType = getManagedSuperType(); |
| 225 |
if(null == aManagedSuperType) { |
231 |
if(null == aManagedSuperType) { |
| 226 |
return anAttribute; |
232 |
return anAttribute; |
| 227 |
} else { |
233 |
} else { |
| 228 |
// keep checking the hierarchy but skip this level |
234 |
// keep checking the hierarchy but skip this level |
| 229 |
if(aManagedSuperType.hasDeclaredAttribute(name)) { |
235 |
if(aManagedSuperType.hasNoDeclaredAttributeInSuperType(name)) { |
| 230 |
// Handles UC4 and UC5 |
236 |
// Handles UC4 and UC5 - throw an IAE if the class is declared above |
| 231 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage( |
237 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage( |
| 232 |
"metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass", |
238 |
"metamodel_managed_type_declared_attribute_not_present_but_is_on_superclass", |
| 233 |
new Object[] { name, this })); |
239 |
new Object[] { name, this })); |
|
Lines 277-286
Link Here
|
| 277 |
Set<Attribute<X, ?>> allAttributes = new HashSet<Attribute<X, ?>>(this.members.values());; |
283 |
Set<Attribute<X, ?>> allAttributes = new HashSet<Attribute<X, ?>>(this.members.values());; |
| 278 |
// Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException |
284 |
// Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException |
| 279 |
Set<Attribute<X, ?>> declaredAttributes = new HashSet<Attribute<X, ?>>(); |
285 |
Set<Attribute<X, ?>> declaredAttributes = new HashSet<Attribute<X, ?>>(); |
| 280 |
for(Iterator<Attribute<X, ?>> anIterator = allAttributes.iterator(); anIterator.hasNext();) { |
286 |
for(Attribute<X, ?> anAttribute : allAttributes) { |
| 281 |
Attribute<? super X, ?> anAttribute = anIterator.next(); |
|
|
| 282 |
// Check the inheritance hierarchy for higher declarations |
287 |
// Check the inheritance hierarchy for higher declarations |
| 283 |
if(this.hasDeclaredAttribute(anAttribute.getName())) { |
288 |
if(this.hasNoDeclaredAttributeInSuperType(anAttribute.getName())) { |
| 284 |
declaredAttributes.add((Attribute<X, ?>)anAttribute); |
289 |
declaredAttributes.add((Attribute<X, ?>)anAttribute); |
| 285 |
} |
290 |
} |
| 286 |
} |
291 |
} |
|
Lines 342-349
Link Here
|
| 342 |
// Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException |
347 |
// Is it better to add to a new Set or remove from an existing Set without a concurrentModificationException |
| 343 |
Set<PluralAttribute<X, ?, ?>> declaredAttributes = new HashSet<PluralAttribute<X, ?, ?>>(); |
348 |
Set<PluralAttribute<X, ?, ?>> declaredAttributes = new HashSet<PluralAttribute<X, ?, ?>>(); |
| 344 |
// The set is a copy of the underlying metamodel attribute set - we will remove all SingularAttribute(s) |
349 |
// The set is a copy of the underlying metamodel attribute set - we will remove all SingularAttribute(s) |
| 345 |
for(Iterator<PluralAttribute<? super X, ?, ?>> anIterator = pluralAttributes.iterator(); anIterator.hasNext();) { |
350 |
for(PluralAttribute<? super X, ?, ?> anAttribute :pluralAttributes) { |
| 346 |
PluralAttribute<? super X, ?, ?> anAttribute = anIterator.next(); |
|
|
| 347 |
if(((TypeImpl)anAttribute.getElementType()).isManagedType()) { |
351 |
if(((TypeImpl)anAttribute.getElementType()).isManagedType()) { |
| 348 |
// check for declarations in the hierarchy and don't add if declared above |
352 |
// check for declarations in the hierarchy and don't add if declared above |
| 349 |
//if(!((ManagedTypeImpl)anAttribute.getElementType()).hasDeclaredAttribute(anAttribute.getName())) { |
353 |
//if(!((ManagedTypeImpl)anAttribute.getElementType()).hasDeclaredAttribute(anAttribute.getName())) { |
|
Lines 353-359
Link Here
|
| 353 |
declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute); |
357 |
declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute); |
| 354 |
} else { |
358 |
} else { |
| 355 |
// add only if we reach the root without finding another declaration |
359 |
// add only if we reach the root without finding another declaration |
| 356 |
if(!potentialSuperType.hasDeclaredAttribute(anAttribute.getName())) { |
360 |
if(!potentialSuperType.hasNoDeclaredAttributeInSuperType(anAttribute.getName())) { |
| 357 |
declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute); |
361 |
declaredAttributes.add((PluralAttribute<X, ?, ?>)anAttribute); |
| 358 |
} |
362 |
} |
| 359 |
} |
363 |
} |
|
Lines 362-367
Link Here
|
| 362 |
return declaredAttributes; |
366 |
return declaredAttributes; |
| 363 |
} |
367 |
} |
| 364 |
|
368 |
|
|
|
369 |
|
| 365 |
/** |
370 |
/** |
| 366 |
* INTERNAL: |
371 |
* INTERNAL: |
| 367 |
* Return an instance of a ManagedType based on the RelationalDescriptor parameter |
372 |
* Return an instance of a ManagedType based on the RelationalDescriptor parameter |
|
Lines 372-388
Link Here
|
| 372 |
public static ManagedTypeImpl<?> create(MetamodelImpl metamodel, RelationalDescriptor descriptor) { |
377 |
public static ManagedTypeImpl<?> create(MetamodelImpl metamodel, RelationalDescriptor descriptor) { |
| 373 |
// Get the ManagedType property on the descriptor if it exists |
378 |
// Get the ManagedType property on the descriptor if it exists |
| 374 |
ManagedTypeImpl<?> managedType = (ManagedTypeImpl<?>) descriptor.getProperty(ManagedTypeImpl.class.getName()); |
379 |
ManagedTypeImpl<?> managedType = (ManagedTypeImpl<?>) descriptor.getProperty(ManagedTypeImpl.class.getName()); |
| 375 |
|
|
|
| 376 |
// Create an Entity, Embeddable or MappedSuperclass |
380 |
// Create an Entity, Embeddable or MappedSuperclass |
| 377 |
if (null == managedType) { |
381 |
if (null == managedType) { |
| 378 |
// The descriptor can be one of NORMAL, INTERFACE (not supported), AGGREGATE or AGGREGATE_COLLECTION |
382 |
// The descriptor can be one of NORMAL, INTERFACE (not supported), AGGREGATE or AGGREGATE_COLLECTION |
| 379 |
// TODO: handle MappedSuperclass |
|
|
| 380 |
if (descriptor.isAggregateDescriptor()) { |
383 |
if (descriptor.isAggregateDescriptor()) { |
|
|
384 |
// EMBEDDABLE |
| 381 |
managedType = new EmbeddableTypeImpl(metamodel, descriptor); |
385 |
managedType = new EmbeddableTypeImpl(metamodel, descriptor); |
| 382 |
//} else if (descriptor.isAggregateCollectionDescriptor()) { |
386 |
//} else if (descriptor.isAggregateCollectionDescriptor()) { |
| 383 |
// managedType = new EntityTypeImpl(metamodel, descriptor); |
387 |
// managedType = new EntityTypeImpl(metamodel, descriptor); |
| 384 |
} else { |
388 |
} else { |
| 385 |
managedType = new EntityTypeImpl(metamodel, descriptor); |
389 |
// Determine if the descriptor is a mappedSuperclass |
|
|
390 |
// 20090817: comment out work for DI 39 |
| 391 |
/* if(metamodel.hasMappedSuperclassDescriptorKeyedByClassName(descriptor.getJavaClassName())) { |
| 392 |
// MAPPEDSUPERCLASS |
| 393 |
// defer to subclass |
| 394 |
managedType = MappedSuperclassTypeImpl.create(metamodel, descriptor); |
| 395 |
} else {*/ |
| 396 |
// ENTITY |
| 397 |
managedType = new EntityTypeImpl(metamodel, descriptor); |
| 398 |
// } |
| 386 |
} |
399 |
} |
| 387 |
} |
400 |
} |
| 388 |
|
401 |
|
|
Lines 852-862
Link Here
|
| 852 |
*/ |
865 |
*/ |
| 853 |
public Set<SingularAttribute<? super X, ?>> getSingularAttributes() { |
866 |
public Set<SingularAttribute<? super X, ?>> getSingularAttributes() { |
| 854 |
// Iterate the members set for attributes of type SingularAttribute |
867 |
// Iterate the members set for attributes of type SingularAttribute |
| 855 |
//Set<SingularAttribute<? super X, ?>> singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>(); |
|
|
| 856 |
Set singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>(); |
868 |
Set singularAttributeSet = new HashSet<SingularAttribute<? super X, ?>>(); |
| 857 |
for(Iterator<Attribute<X, ?>> anIterator = this.members.values().iterator(); anIterator.hasNext();) { |
869 |
for(Attribute<X, ?> anAttribute : this.members.values()) { |
| 858 |
AttributeImpl<? super X, ?> anAttribute = (AttributeImpl<? super X, ?>)anIterator.next(); |
870 |
if(!((AttributeImpl<? super X, ?>)anAttribute).isPlural()) { |
| 859 |
if(!anAttribute.isPlural()) { |
|
|
| 860 |
singularAttributeSet.add(anAttribute); |
871 |
singularAttributeSet.add(anAttribute); |
| 861 |
} |
872 |
} |
| 862 |
} |
873 |
} |
|
Lines 874-881
Link Here
|
| 874 |
* false if no attribute is found in the superTree, or |
885 |
* false if no attribute is found in the superTree, or |
| 875 |
* false if the attribute is found declared higher up in the inheritance superTree |
886 |
* false if the attribute is found declared higher up in the inheritance superTree |
| 876 |
*/ |
887 |
*/ |
| 877 |
private boolean hasDeclaredAttribute(String attributeName) { |
888 |
private boolean hasNoDeclaredAttributeInSuperType(String attributeName) { |
| 878 |
return hasDeclaredAttribute(attributeName, this.getMembers().get(attributeName)); |
889 |
return hasNoDeclaredAttributeInSuperType(attributeName, this.getMembers().get(attributeName)); |
| 879 |
} |
890 |
} |
| 880 |
|
891 |
|
| 881 |
/** |
892 |
/** |
|
Lines 889-895
Link Here
|
| 889 |
* false if no attribute is found in the superTree, or |
900 |
* false if no attribute is found in the superTree, or |
| 890 |
* false if the attribute is found declared higher up in the inheritance superTree |
901 |
* false if the attribute is found declared higher up in the inheritance superTree |
| 891 |
*/ |
902 |
*/ |
| 892 |
private boolean hasDeclaredAttribute(String attributeName, Attribute firstLevelAttribute) { |
903 |
private boolean hasNoDeclaredAttributeInSuperType(String attributeName, Attribute firstLevelAttribute) { |
| 893 |
/* |
904 |
/* |
| 894 |
* Issues: We need to take into account whether the superType is an Entity or MappedSuperclass |
905 |
* Issues: We need to take into account whether the superType is an Entity or MappedSuperclass |
| 895 |
* - If superType is entity then inheriting entities will not have copies of the inherited mappings |
906 |
* - If superType is entity then inheriting entities will not have copies of the inherited mappings |
|
Lines 935-941
Link Here
|
| 935 |
return true; |
946 |
return true; |
| 936 |
} else { |
947 |
} else { |
| 937 |
// UC 1.3 (part of the else condition (anAttribute != null)) is handled by the return false in null != aSuperTypeAttribute |
948 |
// UC 1.3 (part of the else condition (anAttribute != null)) is handled by the return false in null != aSuperTypeAttribute |
| 938 |
return false; |
949 |
// UC 1.4 (when caller is firstLevel) superType does not contain the attribute - check that the current attribute and the first differ |
|
|
950 |
if(null != anAttribute && anAttribute == firstLevelAttribute) { |
| 951 |
return true; |
| 952 |
} else { |
| 953 |
return false; |
| 954 |
} |
| 939 |
} |
955 |
} |
| 940 |
} else { |
956 |
} else { |
| 941 |
// Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType |
957 |
// Recursive Case: check hierarchy only if the immediate superclass is a MappedSuperclassType |
|
Lines 946-955
Link Here
|
| 946 |
// return false immediately if a superType exists above the first level |
962 |
// return false immediately if a superType exists above the first level |
| 947 |
return false; |
963 |
return false; |
| 948 |
} else { |
964 |
} else { |
| 949 |
// UC1.4 The immediate mappedSuperclass may not have the attribute if another one up the chain of rmappedSuperclasses declares it |
965 |
// UC1.4 (when caller is firstLevel.supertype) - the immediate mappedSuperclass may not have the attribute if another one up the chain of rmappedSuperclasses declares it |
| 950 |
if(null == aSuperTypeAttribute) { |
966 |
if(null == aSuperTypeAttribute) { |
| 951 |
// UC 1.5: keep searching a possible chain of mappedSuperclasses |
967 |
// UC 1.5: keep searching a possible chain of mappedSuperclasses |
| 952 |
return aSuperType.hasDeclaredAttribute(attributeName, firstLevelAttribute); |
968 |
return aSuperType.hasNoDeclaredAttributeInSuperType(attributeName, firstLevelAttribute); |
| 953 |
} else { |
969 |
} else { |
| 954 |
// superType does not contain the attribute - check that the current attribute and the first differ |
970 |
// superType does not contain the attribute - check that the current attribute and the first differ |
| 955 |
if(anAttribute != firstLevelAttribute) { |
971 |
if(anAttribute != firstLevelAttribute) { |
|
Lines 1006-1015
Link Here
|
| 1006 |
* We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass. |
1022 |
* We therefore need to treat Collection here as a peer of the other "collections" while also treating it as a non-instantiated superclass. |
| 1007 |
*/ |
1023 |
*/ |
| 1008 |
this.members = new HashMap<String, Attribute<X, ?>>(); |
1024 |
this.members = new HashMap<String, Attribute<X, ?>>(); |
| 1009 |
|
|
|
| 1010 |
// Get and process all mappings on the relationalDescriptor |
1025 |
// Get and process all mappings on the relationalDescriptor |
| 1011 |
for (Iterator<DatabaseMapping> i = getDescriptor().getMappings().iterator(); i.hasNext();) { |
1026 |
for (DatabaseMapping mapping : getDescriptor().getMappings()) { |
| 1012 |
DatabaseMapping mapping = (DatabaseMapping) i.next(); |
|
|
| 1013 |
AttributeImpl<X, ?> member = null; |
1027 |
AttributeImpl<X, ?> member = null; |
| 1014 |
|
1028 |
|
| 1015 |
/** |
1029 |
/** |