Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 148130 Details for
Bug 266912
JPA 2.0 MetaModel API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
This Bugzilla instance is deprecated, and most Eclipse projects now use
GitHub
or
Eclipse GitLab
. Please see the
deprecation plan
for details.
[patch]
Preliminary (before code-review and cleanup) snapshot of complete IdentifiableTypeImpl for Design Issues 70 to 77 and 56 (null and Object.class IAE relaxation)
preliminary_identifiableType_complete_di_70_to_77_and_56.patch (text/plain), 32.44 KB, created by
Michael OBrien
on 2009-09-25 11:27:45 EDT
(
hide
)
Description:
Preliminary (before code-review and cleanup) snapshot of complete IdentifiableTypeImpl for Design Issues 70 to 77 and 56 (null and Object.class IAE relaxation)
Filename:
MIME Type:
Creator:
Michael OBrien
Created:
2009-09-25 11:27:45 EDT
Size:
32.44 KB
patch
obsolete
>Index: foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java >=================================================================== >--- foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java (revision 5198) >+++ foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/localization/i18n/ExceptionLocalizationResource.java (working copy) >@@ -155,9 +155,13 @@ > { "jaxb_helper_invalid_target_for_jaxbcontext", "The provided target Class [{0}] must be one of EclipseLink JAXBContext or EclipseLink XMLContext." }, > { "jaxb_helper_invalid_target_for_unmarshaller", "The provided target Class [{0}] must be one of EclipseLink JAXBUnmarshaller or EclipseLink XMLUnmarshaller." }, > { "jaxb_helper_invalid_target_for_marshaller", "The provided target Class [{0}] must be one of EclipseLink JAXBMarshaller or EclipseLink XMLMarshaller." }, >- { "jaxb_helper_invalid_target_for_binder", "The provided target Class [{0}] must be one of EclipseLink JAXBBinder or EclipseLink XMLBinder." } >+ { "jaxb_helper_invalid_target_for_binder", "The provided target Class [{0}] must be one of EclipseLink JAXBBinder or EclipseLink XMLBinder." }, >+ { "metamodel_identifiable_type_has_no_idclass_attribute", "No @IdClass attributes exist on the IdentifiableType [{0}]. There still may be one or more @Id or an @EmbeddedId on type." }, >+ { "metamodel_identifiable_no_version_attribute_present", "No @Version attribute exists on the identifiable type [{0}]." }, >+ { "metamodel_identifiable_no_id_attribute_present", "No @Id attribute exists on the identifiable type [{0}]." }, >+ { "metamodel_identifiable_id_attribute_is_incorrect_idclass", "The expected single @Id attribute for the identifiable type [{0}] is part of an unexpected @IdClass." } > }; >- >+ > /** > * Return the lookup table. > */ >Index: foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/sessions/Project.java >=================================================================== >--- foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/sessions/Project.java (revision 5198) >+++ foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/sessions/Project.java (working copy) >@@ -18,7 +18,9 @@ > * - 266912: change mappedSuperclassDescriptors Set to a Map > * keyed on MetadataClass - avoiding the use of a hashCode/equals > * override on RelationalDescriptor, but requiring a contains check prior to a put >- * >+ * 09/23/2009-2.0 Michael O'Brien >+ * - 266912: Add metamodelIdClassMap to store IdClass types for exclusive >+ * use by the IdentifiableTypeImpl class in the JPA 2.0 Metamodel API > ******************************************************************************/ > package org.eclipse.persistence.sessions; > >@@ -97,11 +99,20 @@ > * without creating a compile time dependency on JPA. > * The descriptor values of this map must not be replaced by a put() so that the > * mappings on the initial descriptor are not overwritten.<p> >+ * These descriptors are only to be used by Metamodel generation. > * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation > */ > protected Map<Object, RelationalDescriptor> mappedSuperclassDescriptors; >- >+ > /** >+ * Store the IdClass Id attributes for exclusive use by the Metamodel API >+ * Keyed on the fully qualified accessible object owner class name. >+ * Value is a List of the fully qualified id class name or id attribute name. >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation >+ */ >+ protected Map<String, List<String>> metamodelIdClassMap; >+ >+ /** > * PUBLIC: > * Create a new project. > */ >@@ -116,6 +127,7 @@ > this.jpqlParseCache = new ConcurrentFixedCache(200); > this.queries = new ArrayList<DatabaseQuery>(); > this.mappedSuperclassDescriptors = new HashMap<Object, RelationalDescriptor>(2); >+ this.metamodelIdClassMap = new HashMap<String, List<String>>(); > } > > /** >@@ -990,9 +1002,10 @@ > * INTERNAL: > * Return whether there any mappings that are mapped superclasses. > * @return >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation > */ > public boolean hasMappedSuperclasses() { >- return (null != this.mappedSuperclassDescriptors && this.mappedSuperclassDescriptors.size() > 0); >+ return (null != this.mappedSuperclassDescriptors && !this.mappedSuperclassDescriptors.isEmpty()); > } > > /** >@@ -1000,6 +1013,7 @@ > * 266912: Add a descriptor to the Map of mappedSuperclass descriptors > * @param key (Metadata class) > * @param value (RelationalDescriptor) >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation > */ > public void addMappedSuperclass(Object key, RelationalDescriptor value) { > // Lazy initialization of the mappedSuperclassDescriptors field. >@@ -1018,6 +1032,7 @@ > * Descriptor from the Map of mappedSuperclass descriptors > * @param key - theMetadata class > * @return >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation > */ > public RelationalDescriptor getMappedSuperclass(Object key) { > // TODO: this implementation may have side effects when we have the same class >@@ -1031,11 +1046,11 @@ > return this.mappedSuperclassDescriptors.get(key); > } > >- > /** > * INTERNAL: > * Return the Map of RelationalDescriptor objects representing mapped superclass parents >- * keyed by className of the metadata class >+ * keyed by className of the metadata class. >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation > * @return Map > */ > public Map<Object, RelationalDescriptor> getMappedSuperclassDescriptors() { >@@ -1046,6 +1061,35 @@ > return this.mappedSuperclassDescriptors; > } > >+ /** >+ * INTERNAL: >+ * Add an IdClass entry to the map of ids for a particular owner >+ * This function is used exclusively by the Metamodel API. >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation >+ * @param idMap >+ * @param ownerName >+ * @param name >+ */ >+ public void addMetamodelIdClassMapEntry(String ownerName, String name) { >+ // Add a possible composite key to the owner - this function will handle duplicates by overwriting the entry >+ if(this.metamodelIdClassMap.containsKey(ownerName)) { >+ // If we have a key entry then the list will always exist >+ this.metamodelIdClassMap.get(ownerName).add(name); >+ } else { >+ List<String> ownerList = new ArrayList<String>(); >+ ownerList.add(name); >+ this.metamodelIdClassMap.put(ownerName, ownerList); >+ } >+ } > >+ /** >+ * INTERNAL: >+ * Return the Map of IdClass attribute lists keyed on owner class name. >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation >+ * @return >+ */ >+ public Map<String, List<String>> getMetamodelIdClassMap() { >+ return metamodelIdClassMap; >+ } > } > >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/ClassAccessor.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/ClassAccessor.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/ClassAccessor.java (working copy) >@@ -185,8 +185,8 @@ > // Add any converters on this mapping accessor. > accessor.addConverters(); > >- // Add any embeddedid references to the list of id 'used' classes. >- // That is @IdClass and @EmbeddedId reference classes. >+ // Add any embeddedid references to the list of >+ // (@IdClass and @EmbeddedId reference classes) id 'used' classes. > if (accessor.isEmbeddedId()) { > getProject().addIdClass(accessor.getReferenceClassName()); > } >@@ -232,7 +232,7 @@ > * Add the accessors from this class accessors java class to the descriptor > * tied to this class accessor. This method is called for every class > * accessor and is also called from parent class accessors to each of its >- * subclasses of a TABLE_PER_CLASS inhertiance strategy. >+ * subclasses of a TABLE_PER_CLASS inheritance strategy. > */ > public void addAccessors() { > if (m_attributes != null) { >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/classes/MappedSuperclassAccessor.java (working copy) >@@ -30,6 +30,8 @@ > * 06/25/2009-2.0 Michael O'Brien > * - 266912: change MappedSuperclass handling in stage2 to pre process accessors > * in support of the custom descriptors holding mappings required by the Metamodel >+ * 09/24//2009-2.0 Michael O'Brien >+ * - 266912: In initIdClass() store IdClass names for use by the Metamodel API > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metadata.accessors.classes; > >@@ -340,6 +342,9 @@ > // Add the id class to the known list of id classes for this project. > if (m_idClass != null && ! m_idClass.equals(void.class)) { > getProject().addIdClass(m_idClass.getName()); >+ // 266912: We store the IdClass (not an EmbeddableId) for use by the Metamodel API >+ getProject().getProject().addMetamodelIdClassMapEntry( >+ this.getAccessibleObject().getName(), m_idClass.getName()); > } > } > >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataProject.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataProject.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/MetadataProject.java (working copy) >@@ -106,6 +106,7 @@ > import org.eclipse.persistence.sequencing.NativeSequence; > > import org.eclipse.persistence.sessions.DatasourceLogin; >+import org.eclipse.persistence.sessions.Project; > > /** > * INTERNAL: >@@ -391,6 +392,7 @@ > > /** > * INTERNAL: >+ * Add EmbeddedId and IdClass ids to the project > */ > public void addIdClass(String idClassName) { > m_idClasses.add(idClassName); >@@ -835,6 +837,16 @@ > > /** > * INTERNAL: >+ * Return the core API Project associated with this MetadataProject. >+ * @return >+ * @since EclipseLink 1.2 for the JPA 2.0 Reference Implementation >+ */ >+ public Project getProject() { >+ return m_session.getProject(); >+ } >+ >+ /** >+ * INTERNAL: > * Add a root level embeddable accessor. Nested embeddables will be > * pre-processed from their roots down. > * @see processStage1() >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/IdentifiableTypeImpl.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/IdentifiableTypeImpl.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/IdentifiableTypeImpl.java (working copy) >@@ -11,13 +11,17 @@ > * Oracle - initial API and implementation from Oracle TopLink > * 05/26/2009-2.0 mobrien - 266912: Add implementation of IdentifiableType > * as EntityType inherits here instead of ManagedType as of rev# 4265 >+ * 09/23/2009-2.0 mobrien - 266912: Implement hasSingleIdAttribute() and >+ * all other 6 remaining methods for Id and Version support. >+ * DI 70 - 77 and 56 >+ * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_74:_20090909:_Implement_IdentifiableType.hasSingleIdAttribute.28.29 > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metamodel; > >+import java.util.HashSet; > import java.util.List; > import java.util.Set; > >-import javax.persistence.PersistenceException; > import javax.persistence.metamodel.Attribute; > import javax.persistence.metamodel.IdentifiableType; > import javax.persistence.metamodel.SingularAttribute; >@@ -53,15 +57,45 @@ > */ > protected IdentifiableType<? super X> superType; > >+ /** >+ * The collection of SingularAttributes that are Id attributes. >+ */ >+ protected Set<SingularAttribute<? super X, ?>> idAttributes; >+ >+ /** >+ * The SingularAttribute if it exists that is a version attribute >+ */ >+ protected SingularAttribute<? super X, ?> versionAttribute; >+ > protected IdentifiableTypeImpl(MetamodelImpl metamodel, RelationalDescriptor descriptor) { >- super(metamodel, descriptor); >+ super(metamodel, descriptor); > /* The superType field cannot be set until all ManagedType instances > * have been instantiated for this metamodel. >+ * This is required so that any references between attributes can be resolved. > * This occurs later in MetamodelImpl.initialize() >+ * The idAttributes field is computed at the end of MetamodelImpl.initialize() >+ * The versionAttribute is lazy loaded. > */ > } > > /** >+ * INTERNAL: >+ * The idAttributes collection is computed at the end of MetamodelImpl.initialize() >+ */ >+ protected void initializeIdAttributes() { >+ // initialize the set of id attributes directly from the mapping >+ idAttributes = new HashSet<SingularAttribute<? super X, ?>>(); >+ for(Attribute attribute : this.getAttributes()) { >+ if(!((AttributeImpl)attribute).isPlural()) { >+ if(((SingularAttribute)attribute).isId()) { >+ //idAttributes.put(((CMP3Policy)this.descriptor.getCMPPolicy()).getPKClass().getName(), >+ idAttributes.add((SingularAttribute)attribute); >+ } >+ } >+ } >+ } >+ >+ /** > * Return the attribute that corresponds to the id attribute > * declared by the entity or mapped superclass. > * @param type the type of the represented declared id attribute >@@ -71,8 +105,19 @@ > * the identifiable type has an id class > */ > public <Y> SingularAttribute<X, Y> getDeclaredId(Class<Y> type) { >- // return the Id only if it is declared on this entity >- throw new PersistenceException("Not Yet Implemented"); >+ /** >+ * We throw an IAE in 3 cases >+ * 1) If the type is different from the javaType of the attribute >+ * 2) If the id is not declared on (this) type >+ * 3) If the id is not part of an IdClass (it is an EmbeddedId or just an Id) >+ * 4) If the id does not exist on the hierarchy - never happens >+ */ >+ // No need to check if an id exists - on an IdentifiableType - there is always at least one >+ // This call will throw an IAE for 1) and 3) >+ SingularAttribute<? super X, Y> anId = this.getId(type); >+ // return the id only if it is declared on this IdentifableType >+ // We know that the attribute exists - so the an IAE will be thrown for 2) for us >+ return (SingularAttribute<X, Y>)getDeclaredAttribute(anId.getName()); > } > > /** >@@ -85,18 +130,40 @@ > * type is not declared in the identifiable type > */ > public <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type) { >- throw new PersistenceException("Not Yet Implemented"); >+ /** >+ * We throw an IAE in 3 cases >+ * 1) If the type is different from the javaType of the attribute >+ * 2) If the version is not declared on (this) type >+ * 3) If the version does not exist on the hierarchy >+ */ >+ // This call will throw an IAE for 1) and 3) >+ SingularAttribute<? super X, Y> aVersion = this.getVersion(type); >+ // return the version only if it is declared on this IdentifableType >+ // We know that the attribute exists - so the an IAE will be thrown for 2) for us >+ return (SingularAttribute<X, Y>)getDeclaredAttribute(aVersion.getName()); > } > > /** >- * Return the attributes corresponding to the id class of the >- * identifiable type. >- * @return id attributes >- * @throws IllegalArgumentException if the identifiable type >- * does not have an id class >+ * Return the attributes corresponding to the id class of the >+ * identifiable type. >+ * @return id attributes >+ * @throws IllegalArgumentException if the identifiable type >+ * does not have an id class > */ > public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() { >- throw new PersistenceException("Not Yet Implemented"); >+ // Get the list of IdClass attributes previously stored on the core project during metadata processing >+ List<String> idClassNamesList = getMetamodel().getProject().getMetamodelIdClassMap() >+ .get(getJavaType().getCanonicalName()); >+ // Check for IdClass existence - either check is sufficient >+ if(!this.hasSingleIdAttribute() && (null != idClassNamesList)) { >+ // All Id attributes are part of an IdClass >+ return this.idAttributes; >+ } else { >+ // No IdClass attributes found - the IdentifiableType may still have a single @Id or an @EmbeddedId in this case >+ throw new IllegalArgumentException(ExceptionLocalization.buildMessage( >+ "metamodel_identifiable_type_has_no_idclass_attribute", >+ new Object[] {this})); >+ } > } > > /** >@@ -109,16 +176,28 @@ > * the identifiable type has an id class > */ > public <Y> SingularAttribute<? super X, Y> getId(Class<Y> type) { >- throw new PersistenceException("Not Yet Implemented"); >-/* SingularAttribute<? super X, Y> anAttribute = null; >- Class<Y> realType = null; >- //boolean isId = this.accessor.isId(); >- if(type != realType) { >+ // We assume that there is at most a single EmbeddedId >+ SingularAttribute<? super X, Y> idAttribute = null; >+ if(!hasSingleIdAttribute()) { >+ // Id is part of an IdClass > throw new IllegalArgumentException(ExceptionLocalization.buildMessage( >- "metamodel_identifiable_id_attribute_type_incorrect", >- new Object[] { anAttribute, this, type, realType})); >+ "metamodel_identifiable_id_attribute_is_incorrect_idclass", >+ new Object[] { this })); >+ } else { >+ // verify single id attribute type >+ for(SingularAttribute<? super X, ?> anAttribute : idAttributes) { >+ // Verify type is correct - relax restriction on null and Object.class (from same classLoader) >+ if(null == type || Object.class == type || >+ ((type != null) && (type.getCanonicalName().equals(anAttribute.getJavaType().getCanonicalName())))) { >+ idAttribute = (SingularAttribute<? super X, Y>) anAttribute; >+ } else { >+ throw new IllegalArgumentException(ExceptionLocalization.buildMessage( >+ "metamodel_identifiable_id_attribute_type_incorrect", >+ new Object[] { anAttribute, this, type, anAttribute.getJavaType() })); >+ } >+ } > } >- return anAttribute;*/ >+ return idAttribute; > } > > /** >@@ -127,9 +206,7 @@ > */ > public Type<?> getIdType() { > // NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor >- // descriptor.getPrimaryKeyPolicy().getIdClass(); > CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy(); >- > if (null == cmpPolicy) { > // Composite key support (IE: @EmbeddedId) > List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings(); >@@ -143,8 +220,7 @@ > Attribute anAttribute = this.getAttribute(attributeName); > if(anAttribute != null) { > return this.getMetamodel().getType(anAttribute.getJavaType()); >- } >- >+ } > } > } > } >@@ -192,16 +268,40 @@ > * given type is not present in the identifiable type > */ > public <Y> SingularAttribute<? super X, Y> getVersion(Class<Y> type) { >- throw new PersistenceException("Not Yet Implemented"); >-/* SingularAttribute<? super X, Y> anAttribute = null; >- Class<Y> realType = null; >- if(type != realType) { >+ // Lazy load the version attribute if it exists >+ if(null == getVersion()) { >+ // No version exists - throw IAE > throw new IllegalArgumentException(ExceptionLocalization.buildMessage( >- "metamodel_identifiable_version_attribute_type_incorrect", >- new Object[] { anAttribute, this, type, realType})); >+ "metamodel_identifiable_no_version_attribute_present", >+ new Object[] { this })); >+ } else { >+ // Verify the type (Note: ClassLoaders do not have to be the same) >+ // Relax restriction on null and Object.class (from same classLoader) >+ if(null == type || Object.class == type || >+ ((type != null) && (type.getCanonicalName().equals(versionAttribute.getJavaType().getCanonicalName())))) { >+ return (SingularAttribute<? super X, Y>)versionAttribute; >+ } else { >+ throw new IllegalArgumentException(ExceptionLocalization.buildMessage( >+ "metamodel_identifiable_version_attribute_type_incorrect", >+ new Object[] { versionAttribute, this, type, versionAttribute.getJavaType()})); >+ } > } >- return anAttribute;*/ > } >+ >+ /** >+ * INTERNAL: >+ * Return the version attribute on this type. >+ * If no version attribute exists - return null. >+ * @param <Y> >+ * @return >+ */ >+ private <Y> SingularAttribute<? super X, ?> getVersion() { >+ if(hasVersionAttribute()) { >+ return (SingularAttribute<? super X, ?>)versionAttribute; >+ } else { >+ return null; >+ } >+ } > > /** > * Whether or not the identifiable type has an id attribute. >@@ -211,17 +311,46 @@ > * type has a single id attribute > */ > public boolean hasSingleIdAttribute() { >- // Note: this function will return false both if an IdClass is present and if no type of Id is present >-/* List<DatabaseField> pkFields = this.getDescriptor().getPrimaryKeyFields(); >+ // The following section will return false for any multiple EmbeddableId as well as multiple Ids as part of an IdClass >+ // Note: there will always be at least 1 Id for an IdentifiableType >+ //return this.idAttributes.size() < 2; >+ >+ /** >+ * Since we are in IdentifiableType which involves only Entities and MappedSuperclasses, >+ * we are safe to assume that there will always be an Id of some sort - we are not in >+ * Basic, Embeddable or transient types. >+ * Check the core API project for any IdClass matching this IdentifiableType >+ * after we check directly on the descriptor for an Id. >+ * References: SubQueryImpl.select() >+ */ >+ >+ // Note: this function will return false only if an IdClass is present >+ List<DatabaseField> pkFields = this.getDescriptor().getPrimaryKeyFields(); > // return false for no Id field types > if(pkFields.isEmpty()) { > return false; > } else { >- // Optional: Verify the mapping on the first field >- ((CMP3Policy)this.getDescriptor().getCMPPolicy()).getPKClass(); >+ // Optional: Verify the mapping on the each field and whether it is an IdClass >+ Class pkClass = null; >+ if(this.getDescriptor().hasCMPPolicy()) { >+ pkClass = ((CMP3Policy)this.getDescriptor().getCMPPolicy()).getPKClass(); >+ if(null == pkClass) { >+ return false; >+ } >+ } else { >+ // MappedSuperclass descriptors do not have a CMP policy >+ return pkFields.size() < 2; >+ } >+ List<String> idClasses = getMetamodel().getProject().getMetamodelIdClassMap().get(getJavaType().getCanonicalName()); >+ if(null != idClasses) { >+ for(String idClass : idClasses) { >+ if(idClass.equalsIgnoreCase(pkClass.getName())) { >+ return false; >+ } >+ } >+ } > } >- return true;*/ >- throw new PersistenceException("Not Yet Implemented"); >+ return true; > } > > /** >@@ -230,7 +359,18 @@ > * type has a version attribute > */ > public boolean hasVersionAttribute() { >- throw new PersistenceException("Not Yet Implemented"); >+ // The versionAttribute is lazy loaded >+ if(null != versionAttribute) { >+ return true; >+ } else { >+ for(Attribute attribute : this.getAttributes()) { >+ if(!((AttributeImpl)attribute).isPlural() && ((SingularAttribute)attribute).isVersion()) { >+ versionAttribute = (SingularAttribute)attribute; >+ return true; >+ } >+ } >+ } >+ return false; > } > > /** >@@ -240,7 +380,7 @@ > * @return > */ > @Override >- public boolean isIdentifiableType() { >+ protected boolean isIdentifiableType() { > return true; > } > >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java (working copy) >@@ -19,6 +19,10 @@ > * 07/10/2009-2.0 mobrien - Adjust BasicType processing to handle non-Entity Java types > * - 266912: As part of Attribute.getType() and specifically SingularAttribute.getBindableJavaType > * set the appropriate elementType based on the mapping type. >+ * 09/23/2009-2.0 mobrien - 266912: Implement hasSingleIdAttribute() and >+ * all other 6 remaining methods for Id and Version support. >+ * DI 70 - 77 and 56 >+ * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_74:_20090909:_Implement_IdentifiableType.hasSingleIdAttribute.28.29 > ******************************************************************************/ > package org.eclipse.persistence.internal.jpa.metamodel; > >@@ -45,6 +49,7 @@ > import org.eclipse.persistence.internal.localization.ExceptionLocalization; > import org.eclipse.persistence.jpa.JpaHelper; > import org.eclipse.persistence.sessions.DatabaseSession; >+import org.eclipse.persistence.sessions.Project; > > /** > * <p> >@@ -131,8 +136,6 @@ > "metamodel_class_incorrect_type_instance", > new Object[] { clazz, "EntityType", aType})); > } >- >- > } > > /** >@@ -183,10 +186,19 @@ > > /** > * INTERNAL: >+ * Return the core API Project associated with the DatabaseSession >+ * that is associated with this Metamodel >+ * @return >+ */ >+ protected Project getProject() { >+ return this.getSession().getProject(); >+ } >+ /** >+ * INTERNAL: > * Return the DatabaseSession associated with this Metamodel > * @return > */ >- public DatabaseSession getSession() { >+ protected DatabaseSession getSession() { > return this.session; > } > >@@ -236,7 +248,7 @@ > * @param qualifiedClassNameKeyString > * @return > */ >- public boolean hasMappedSuperclass(String qualifiedClassNameKeyString) { >+ protected boolean hasMappedSuperclass(String qualifiedClassNameKeyString) { > /** > * This function is used before the metamodel has populated its Set of mappedSuperclasses - > * therefore we go directly to the descriptor source. >@@ -350,6 +362,13 @@ > for(ManagedTypeImpl<?> managedType : new ArrayList<ManagedTypeImpl<?>>(managedTypes.values())) { > managedType.initialize(); > } >+ >+ // 3 - process all the Id attributes on each IdentifiableType >+ for(ManagedTypeImpl<?> potentialIdentifiableType : managedTypes.values()) { >+ if(potentialIdentifiableType.isIdentifiableType()) { >+ ((IdentifiableTypeImpl<?>)potentialIdentifiableType).initializeIdAttributes(); >+ } >+ } > } > > /** >Index: jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/SingularAttributeImpl.java >=================================================================== >--- jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/SingularAttributeImpl.java (revision 5198) >+++ jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/SingularAttributeImpl.java (working copy) >@@ -53,7 +53,7 @@ > > /** The Type representing this Entity or Basic type **/ > protected Type<T> elementType; >- >+ > /** > * Create an instance of the Attribute > * @param managedType >@@ -120,7 +120,7 @@ > attributeClass = MetamodelImpl.DEFAULT_ELEMENT_TYPE_FOR_UNSUPPORTED_MAPPINGS; > AbstractSessionLog.getLog().log(SessionLog.FINEST, "metamodel_attribute_class_type_is_null", this); > } >- elementType = (Type<T>)getMetamodel().getType(attributeClass); >+ elementType = (Type<T>)getMetamodel().getType(attributeClass); > } > > /** >@@ -141,7 +141,17 @@ > * @return boolean indicating whether or not attribute is an id > */ > public boolean isId() { >- return getDescriptor().getObjectBuilder().getPrimaryKeyMappings().contains(getMapping()); >+ if(this.getManagedTypeImpl().isMappedSuperclass()) { >+ // The field on the mapping is the same field in the pkFields list on the descriptor >+ if(this.getDescriptor().getPrimaryKeyFields().contains(this.getMapping().getField())) { >+ return true; >+ } else { >+ return false; >+ } >+ } else { >+ //return getDescriptor().getObjectBuilder().getPrimaryKeyMappings().contains(getMapping()); >+ return getMapping().isPrimaryKeyMapping(); >+ } > } > > /** >@@ -153,6 +163,7 @@ > return getMapping().isOptional(); > } > >+ > /** > * INTERNAL: > * Return whether the attribute is plural or singular
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 266912
:
128191
|
128197
|
128198
|
128381
|
130103
|
130984
|
130985
|
131824
|
131835
|
135222
|
135336
|
135338
|
135339
|
137539
|
137542
|
137557
|
138191
|
138289
|
139023
|
139029
|
139030
|
139033
|
139042
|
139046
|
139534
|
139943
|
139984
|
139999
|
140059
|
140117
|
140145
|
140256
|
140258
|
140259
|
140393
|
140424
|
140506
|
140775
|
140868
|
140872
|
140970
|
140973
|
141134
|
141135
|
141245
|
141313
|
141316
|
141476
|
141554
|
141875
|
142158
|
142324
|
142896
|
143085
|
143175
|
143342
|
143400
|
143722
|
143862
|
143957
|
144276
|
144279
|
144401
|
144734
|
145056
|
145189
|
146402
|
146403
|
146503
|
146962
|
147112
|
147335
|
147465
|
147606
|
148077
| 148130 |
148354
|
148633
|
148658
|
149174
|
149472
|
149534
|
149681
|
149683
|
149933
|
150163
|
150861
|
150893
|
151264
|
151497
|
151667
|
151724
|
151885