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 192311 Details for
Bug 331480
[Validation] Need validation for embeddable id class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
proposed bug fix patch
propossed_patch_331480_1.txt (text/plain), 26.02 KB, created by
Leslie Davis
on 2011-03-31 14:54:41 EDT
(
hide
)
Description:
proposed bug fix patch
Filename:
MIME Type:
Creator:
Leslie Davis
Created:
2011-03-31 14:54:41 EDT
Size:
26.02 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jpt.common.core >Index: src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java,v >retrieving revision 1.1 >diff -u -r1.1 JDTTools.java >--- src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java 22 Feb 2011 17:58:48 -0000 1.1 >+++ src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java 31 Mar 2011 18:43:47 -0000 >@@ -11,17 +11,22 @@ > > import java.io.FileNotFoundException; > import java.util.ArrayList; >+ >+import org.eclipse.jdt.core.Flags; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IParent; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.Signature; > import org.eclipse.jpt.common.core.JptCommonCorePlugin; > import org.eclipse.jpt.common.utility.Filter; > import org.eclipse.jpt.common.utility.internal.ArrayTools; > import org.eclipse.jpt.common.utility.internal.ClassName; > import org.eclipse.jpt.common.utility.internal.ReflectionTools; >+import org.eclipse.jpt.common.utility.internal.StringTools; > import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; > import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; > import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; >@@ -105,6 +110,53 @@ > } > > /** >+ * Return true if the given type named contains a method name as given with the given paramter types >+ */ >+ public static boolean typeNamedImplementsMethod(IJavaProject javaProject, String typeName, String methodName, String[] parameterTypeNames) { >+ try { >+ return typeImplementsMethod(javaProject, javaProject.findType(typeName), methodName, parameterTypeNames); >+ } catch (JavaModelException ex) { >+ JptCommonCorePlugin.log(ex); >+ return false; >+ } >+ } >+ >+ private static boolean typeImplementsMethod(IJavaProject javaProject, IType type, String methodName, String[] parameterTypeNames) { >+ if ((type == null) || methodName == null) { >+ return false; >+ } >+ >+ try { >+ IMethod[] methods = type.getMethods(); >+ for (IMethod method : methods) { >+ if (StringTools.stringsAreEqual(method.getElementName(), methodName)) { >+ if (parameterTypeNames.length == 0 && method.getNumberOfParameters() == 0) { >+ return true; >+ } else if (parameterTypeNames.length == method.getNumberOfParameters()) { >+ int index = 0; >+ String[] parameters = method.getParameterTypes(); >+ String resolvedParameterTypeName = parameters[0]; >+ if (!type.isResolved()) { >+ resolvedParameterTypeName = resolveType(type, Signature.getSignatureSimpleName(parameters[index])); >+ } >+ for (String parameterTypeName : parameterTypeNames) { >+ if (!StringTools.stringsAreEqual(resolvedParameterTypeName, parameterTypeName)) { >+ return false; >+ } >+ index++; >+ } >+ return true; >+ } >+ } >+ } >+ } catch (JavaModelException ex) { >+ JptCommonCorePlugin.log(ex); >+ return false; >+ } >+ return false; >+ } >+ >+ /** > * Return the names of the specified type's super interfaces. > * This is necessary because, for whatever reason, {@link IType#getSuperInterfaceNames()} > * returns unqualified names when the type is from Java source. >@@ -273,4 +325,33 @@ > java.sql.Time.class.getName(), > java.sql.Timestamp.class.getName(), > }; >+ >+ public static boolean classIsPublic(IJavaProject javaProject, String className) { >+ if (className != null) { >+ IType embeddableType = JDTTools.findType(javaProject, className); >+ try { >+ return Flags.isPublic(embeddableType.getFlags()); >+ } catch (JavaModelException ex) { >+ JptCommonCorePlugin.log(ex); >+ } >+ } >+ return false; >+ } >+ >+ public static boolean classHasPublicZeroArgConstructor(IJavaProject javaProject, String className) { >+ if (javaProject != null && className != null) { >+ IType type = findType(javaProject, className); >+ try { >+ for (IMethod method : type.getMethods()) { >+ if ((method.isConstructor()) && (method.getNumberOfParameters() == 0) >+ && (method.getFlags() == 1)) { >+ return true; >+ } >+ } >+ } catch (JavaModelException ex) { >+ JptCommonCorePlugin.log(ex); >+ } >+ } >+ return false; >+ } > } >#P org.eclipse.jpt.jpa.core >Index: property_files/jpa_validation.properties >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_validation.properties,v >retrieving revision 1.5 >diff -u -r1.5 jpa_validation.properties >--- property_files/jpa_validation.properties 3 Mar 2011 00:01:17 -0000 1.5 >+++ property_files/jpa_validation.properties 31 Mar 2011 18:43:50 -0000 >@@ -50,6 +50,7 @@ > TYPE_MAPPING_ID_CLASS_REQUIRED=This class has a composite primary key. It must use an ID class. > TYPE_MAPPING_ID_CLASS_AND_EMBEDDED_ID_BOTH_USED=This class must use either an ID class or an embedded ID to specify its composite primary key, not both. > TYPE_MAPPING_MULTIPLE_EMBEDDED_ID=This class uses multiple embedded ID mappings. Only one is allowed. >+TYPE_MAPPING_ID_AND_EMBEDDED_ID_BOTH_USED=This class must use either an ID or and embedded ID to specify its primary key, not both. > TYPE_MAPPING_ID_CLASS_WITH_MAPS_ID=The relationship ''{0}'' maps an ID, which is not allowed in conjunction with an ID class. > TYPE_MAPPING_MAPS_ID_ATTRIBUTE_TYPE_DOES_NOT_AGREE=The type of the ID mapped by the relationship ''{0}'' does not agree with the primary key class of the target entity. > TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH=There is no primary key attribute to match the ID class attribute {0} >@@ -88,6 +89,10 @@ > ID_MAPPING_UNRESOLVED_GENERATOR_NAME=Unresolved generator name \"{0}\" > ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_COLUMN_SPECIFIED=In {0}, a column is specified, but it is mapped by a relationship. IDs that are mapped by a relationship should not specify a column. > EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED=Embedded IDs that are mapped by a relationship should not specify any attribute overrides. >+EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE=Embedded id class should include method definitions for equals() and hashcode(). >+EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR=Embedded id class should be public, and include a zero argument constructor. >+EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE=Embedded id class should implement Serializable. >+EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS=Embedded id class should not contain relationship mappings. > ATTRIBUTE_OVERRIDE_MAPPED_BY_RELATIONSHIP_AND_SPECIFIED=Attributes (or subattributes of an attribute) that are mapped by a relationship should not be overridden. > TABLE_UNRESOLVED_CATALOG=Catalog \"{0}\" cannot be resolved for table \"{1}\" > TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for table \"{1}\" >Index: src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractEntityPrimaryKeyValidator.java >--- src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java 6 Feb 2011 02:07:24 -0000 1.1 >+++ src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java 31 Mar 2011 18:43:50 -0000 >@@ -73,6 +73,8 @@ > validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter); > // ... and only one embedded id > validateOneEmbeddedId(messages, reporter); >+ // ... and not both id and embedded id >+ validateOneOfEmbeddedOrIdIsUsed(messages, reporter); > > validateMapsIdMappings(messages, reporter); > >Index: src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractMappedSuperclassPrimaryKeyValidator.java >--- src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java 6 Feb 2011 02:07:24 -0000 1.1 >+++ src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java 31 Mar 2011 18:43:50 -0000 >@@ -44,6 +44,8 @@ > validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter); > // ... and only one embedded id > validateOneEmbeddedId(messages, reporter); >+ // ... and not both id and embedded id >+ validateOneOfEmbeddedOrIdIsUsed(messages, reporter); > > if (specifiesIdClass()) { > validateIdClass(idClassReference().getIdClass(), messages, reporter); >Index: src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractPrimaryKeyValidator.java >--- src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java 6 Feb 2011 02:07:24 -0000 1.1 >+++ src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java 31 Mar 2011 18:43:50 -0000 >@@ -13,6 +13,7 @@ > import java.util.Collection; > import java.util.Iterator; > import java.util.List; >+ > import org.eclipse.jpt.common.utility.internal.ClassName; > import org.eclipse.jpt.common.utility.internal.CollectionTools; > import org.eclipse.jpt.common.utility.internal.HashBag; >@@ -119,6 +120,19 @@ > } > } > >+ //only embedded or id, both may not be used >+ protected void validateOneOfEmbeddedOrIdIsUsed(List<IMessage> messages, IReporter reporter) { >+ if (definesEmbeddedIdMapping(typeMapping) && definesIdMapping(typeMapping)) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.TYPE_MAPPING_ID_AND_EMBEDDED_ID_BOTH_USED, >+ EMPTY_STRING_ARRAY, >+ typeMapping(), >+ textRangeResolver().getTypeMappingTextRange())); >+ } >+ } >+ > // only one embedded id may be used > protected void validateOneEmbeddedId(List<IMessage> messages, IReporter reporter) { > if (CollectionTools.size(getEmbeddedIdMappings(typeMapping())) > 1) { >@@ -462,6 +476,14 @@ > return ! CollectionTools.isEmpty(getEmbeddedIdMappings(typeMapping)); > } > >+ /** >+ * Return whether an id is defined for this class, whether that be locally >+ * or on an ancestor >+ */ >+ protected boolean definesIdMapping(TypeMapping typeMapping) { >+ return ! CollectionTools.isEmpty(getIdMappings(typeMapping)); >+ } >+ > protected EmbeddedIdMapping getEmbeddedIdMapping(TypeMapping typeMapping) { > Iterable<EmbeddedIdMapping> embeddedIdMappings = getEmbeddedIdMappings(typeMapping); > if (CollectionTools.size(embeddedIdMappings) == 1) { >Index: src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java,v >retrieving revision 1.1 >diff -u -r1.1 GenericJavaEmbeddedIdMapping.java >--- src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java 6 Feb 2011 02:07:16 -0000 1.1 >+++ src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedIdMapping.java 31 Mar 2011 18:43:50 -0000 >@@ -9,10 +9,14 @@ > ******************************************************************************/ > package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; > >+import java.io.Serializable; > import java.util.Iterator; > import java.util.List; > import java.util.Set; >+ >+import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jpt.common.core.internal.utility.JDTTools; > import org.eclipse.jpt.common.utility.internal.CollectionTools; > import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator; > import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; >@@ -109,7 +113,90 @@ > @Override > public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { > super.validate(messages, reporter, astRoot); >- >+ validateMappedByRelationshipAndAttributeOverridesSpecified(messages, reporter, astRoot); >+ validateTargeEmbeddableImplementsEqualsAndHashcode(messages, reporter, astRoot); >+ validateTargetEmbeddableIsPublicWithZeroArgConstructor(messages, reporter, astRoot); >+ validateTargetEmbeddableImplementsSerializable(messages, reporter, astRoot); >+ validateNoRelationshipMappingsOnTargetEmbeddable(messages, reporter, astRoot); >+ } >+ >+ protected void validateNoRelationshipMappingsOnTargetEmbeddable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { >+ if (this.getTargetEmbeddable() != null) { >+ TypeMapping targetEmbeddableTypeMapping = this.getTargetEmbeddable().getPersistentType().getMapping(); >+ if (targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext()) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange(astRoot) >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateTargetEmbeddableImplementsSerializable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.typeNamedImplementsInterfaceNamed(javaProject, targetEmbeddableClassName, Serializable.class.getName())) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange(astRoot) >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateTargetEmbeddableIsPublicWithZeroArgConstructor(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.classIsPublic(javaProject, targetEmbeddableClassName) >+ || !JDTTools.classHasPublicZeroArgConstructor(javaProject, targetEmbeddableClassName)) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange(astRoot) >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateTargeEmbeddableImplementsEqualsAndHashcode(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "equals", new String[] {Object.class.getName()}) >+ || !JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "hashCode", EMPTY_STRING_ARRAY)) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange(astRoot) >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateMappedByRelationshipAndAttributeOverridesSpecified(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { > // [JPA 2.0] if the embedded id is mapped by a relationship, then any specified > // attribute overrides are in error > // (in JPA 1.0, this will obviously never be reached) >@@ -124,7 +211,7 @@ > this.attributeOverrideContainer.getValidationTextRange(astRoot) > ) > ); >- } >+ } > } > > // ********** attribute override container owner ********* >Index: src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java,v >retrieving revision 1.1 >diff -u -r1.1 GenericOrmEmbeddedIdMapping.java >--- src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java 6 Feb 2011 02:07:13 -0000 1.1 >+++ src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmEmbeddedIdMapping.java 31 Mar 2011 18:43:50 -0000 >@@ -9,9 +9,13 @@ > ******************************************************************************/ > package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm; > >+import java.io.Serializable; > import java.util.Iterator; > import java.util.List; > import java.util.Set; >+ >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jpt.common.core.internal.utility.JDTTools; > import org.eclipse.jpt.common.utility.internal.CollectionTools; > import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator; > import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; >@@ -121,7 +125,90 @@ > @Override > public void validate(List<IMessage> messages, IReporter reporter) { > super.validate(messages, reporter); >+ validateMappedByRelationshipAndAttributeOverridesSpecified(messages, reporter); >+ validateTargeEmbeddableImplementsEqualsAndHashcode(messages, reporter); >+ validateTargetEmbeddableIsPublicWithZeroArgConstructor(messages, reporter); >+ validateTargetEmbeddableImplementsSerializable(messages, reporter); >+ validateNoRelationshipMappingsOnTargetEmbeddable(messages, reporter); >+ } >+ >+ protected void validateNoRelationshipMappingsOnTargetEmbeddable(List<IMessage> messages, IReporter reporter) { >+ if (this.getTargetEmbeddable() != null) { >+ TypeMapping targetEmbeddableTypeMapping = this.getTargetEmbeddable().getPersistentType().getMapping(); >+ if (targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() >+ || targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext()) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange() >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateTargetEmbeddableImplementsSerializable(List<IMessage> messages, IReporter reporter) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.typeNamedImplementsInterfaceNamed(javaProject, targetEmbeddableClassName, Serializable.class.getName())) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange() >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateTargetEmbeddableIsPublicWithZeroArgConstructor(List<IMessage> messages, IReporter reporter) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.classIsPublic(javaProject, targetEmbeddableClassName) >+ || !JDTTools.classHasPublicZeroArgConstructor(javaProject, targetEmbeddableClassName)) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange() >+ ) >+ ); >+ } >+ } >+ } > >+ protected void validateTargeEmbeddableImplementsEqualsAndHashcode(List<IMessage> messages, IReporter reporter) { >+ if (this.getTargetEmbeddable() != null) { >+ String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); >+ IJavaProject javaProject = getJpaProject().getJavaProject(); >+ if (!JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "equals", new String[] {Object.class.getName()}) >+ || !JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "hashCode", EMPTY_STRING_ARRAY)) { >+ messages.add( >+ DefaultJpaValidationMessages.buildMessage( >+ IMessage.HIGH_SEVERITY, >+ JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE, >+ EMPTY_STRING_ARRAY, >+ this, >+ this.getValidationTextRange() >+ ) >+ ); >+ } >+ } >+ } >+ >+ protected void validateMappedByRelationshipAndAttributeOverridesSpecified(List<IMessage> messages, IReporter reporter) { > // [JPA 2.0] if the embedded id is mapped by a relationship, then any specified > // attribute overrides are in error > // (in JPA 1.0, this will obviously never be reached) >@@ -138,8 +225,6 @@ > ); > } > } >- >- > // ********** attribute override container owner ********* > > protected class AttributeOverrideContainerOwner >Index: src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java >=================================================================== >RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java,v >retrieving revision 1.4 >diff -u -r1.4 JpaValidationMessages.java >--- src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java 3 Mar 2011 00:01:17 -0000 1.4 >+++ src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java 31 Mar 2011 18:43:51 -0000 >@@ -56,6 +56,7 @@ > public static final String TYPE_MAPPING_ID_CLASS_REQUIRED = "TYPE_MAPPING_ID_CLASS_REQUIRED"; > public static final String TYPE_MAPPING_ID_CLASS_AND_EMBEDDED_ID_BOTH_USED = "TYPE_MAPPING_ID_CLASS_AND_EMBEDDED_ID_BOTH_USED"; > public static final String TYPE_MAPPING_MULTIPLE_EMBEDDED_ID = "TYPE_MAPPING_MULTIPLE_EMBEDDED_ID"; >+ public static final String TYPE_MAPPING_ID_AND_EMBEDDED_ID_BOTH_USED = "TYPE_MAPPING_ID_AND_EMBEDDED_ID_BOTH_USED"; > public static final String TYPE_MAPPING_ID_CLASS_WITH_MAPS_ID = "TYPE_MAPPING_ID_CLASS_WITH_MAPS_ID"; > public static final String TYPE_MAPPING_MAPS_ID_ATTRIBUTE_TYPE_DOES_NOT_AGREE = "TYPE_MAPPING_MAPS_ID_ATTRIBUTE_TYPE_DOES_NOT_AGREE"; > public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH"; >@@ -94,6 +95,10 @@ > public static final String ID_MAPPING_UNRESOLVED_GENERATOR_NAME = "ID_MAPPING_UNRESOLVED_GENERATOR_NAME"; > public static final String ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_COLUMN_SPECIFIED = "ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_COLUMN_SPECIFIED"; > public static final String EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED = "EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED"; >+ public static final String EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE = "EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE"; >+ public static final String EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR="EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR"; >+ public static final String EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE="EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE"; >+ public static final String EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS="EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS"; > public static final String ATTRIBUTE_OVERRIDE_MAPPED_BY_RELATIONSHIP_AND_SPECIFIED = "ATTRIBUTE_OVERRIDE_MAPPED_BY_RELATIONSHIP_AND_SPECIFIED"; > public static final String ATTRIBUTE_OVERRIDE_INVALID_NAME = "ATTRIBUTE_OVERRIDE_INVALID_NAME"; > public static final String VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME = "VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_INVALID_NAME";
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 331480
:
192311
|
203372
|
211005