Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorNan Li2013-08-13 16:06:14 +0000
committerNan Li2013-08-13 16:06:14 +0000
commitc24e00173a036a08024b4df9ce2b2aba0fe85771 (patch)
tree6b5ca60de9614dc80ce9ab49cb3513b2a3918845 /jpa
parent3d4dc7d4c665fab511fa2b18769f8881453fced5 (diff)
downloadwebtools.dali-c24e00173a036a08024b4df9ce2b2aba0fe85771.tar.gz
webtools.dali-c24e00173a036a08024b4df9ce2b2aba0fe85771.tar.xz
webtools.dali-c24e00173a036a08024b4df9ce2b2aba0fe85771.zip
347842 - [EclipseLink][Validation] No id class validation when id class
defined on mapped superclass
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkEntityPrimaryKeyValidator.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java2
5 files changed, 66 insertions, 25 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java
index 8d27c6252e..46c41d04f6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java
@@ -10,10 +10,10 @@
package org.eclipse.jpt.jpa.core.internal.jpa1.context;
import java.util.List;
-
+import org.eclipse.jpt.common.core.internal.utility.ValidationMessageTools;
+import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Entity;
-import org.eclipse.jpt.common.core.internal.utility.ValidationMessageTools;
import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -69,17 +69,17 @@ public abstract class AbstractEntityPrimaryKeyValidator extends
validateMapsIdMappings(messages, reporter);
- if (specifiesIdClass()) {
+ if (declaresIdClassInHierarchy()) {
validateIdClass(idClassReference().getIdClass(), messages, reporter);
}
}
protected void validateNonRootEntityDoesNotSpecifyIdClass(List<IMessage> messages, IReporter reporter) {
- if (idClassReference().isSpecified()) {
+ if (declaresIdClassLocally()) {
messages.add(
ValidationMessageTools.buildValidationMessage(
entity().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.ENTITY_NON_ROOT_ID_CLASS_SPECIFIED
)
);
@@ -97,4 +97,9 @@ public abstract class AbstractEntityPrimaryKeyValidator extends
);
}
}
+
+ @Override
+ protected TextRange getIdClassRefValidationTextRange() {
+ return declaresIdClassLocally() ? super.getIdClassRefValidationTextRange() : typeMapping().getValidationTextRange();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java
index 74fd1c7b24..1db787e56d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java
@@ -39,7 +39,7 @@ public abstract class AbstractMappedSuperclassPrimaryKeyValidator
// ... and not both id and embedded id
validateOneOfEmbeddedOrIdIsUsed(messages, reporter);
- if (specifiesIdClass()) {
+ if (declaresIdClassInHierarchy()) {
validateIdClass(idClassReference().getIdClass(), messages, reporter);
}
return true;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java
index 9fcec8c2a5..98c02fcd73 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java
@@ -56,9 +56,9 @@ public abstract class AbstractPrimaryKeyValidator
return this.typeMapping;
}
+ // Return the id class ref that is to be validated
protected IdClassReference idClassReference() {
return typeMapping().getIdClassReference();
-
}
protected TextRange getAttributeMappingTextRange(AttributeMapping attributeMapping) {
@@ -77,7 +77,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_PK_REDEFINED_ID_CLASS
)
);
@@ -97,7 +97,7 @@ public abstract class AbstractPrimaryKeyValidator
// if a primary key defining class has multiple primary keys, it must use an id class
protected void validateIdClassIsUsedIfNecessary(List<IMessage> messages, IReporter reporter) {
- if (! specifiesIdClass() && idClassIsRequired()) {
+ if (! declaresIdClassInHierarchy() && idClassIsRequired()) {
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
@@ -110,7 +110,7 @@ public abstract class AbstractPrimaryKeyValidator
// only one composite primary key strategy may be used
protected void validateOneOfIdClassOrEmbeddedIdIsUsed(List<IMessage> messages, IReporter reporter) {
- if (idClassReference().isSpecified()
+ if (declaresIdClassLocally()
&& IterableTools.size(typeMapping().getAllAttributeMappings(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)) > 0) {
messages.add(
ValidationMessageTools.buildValidationMessage(
@@ -202,7 +202,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NOT_PRIMARY_KEY,
idClassAttribute.getName()
)
@@ -218,7 +218,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_TYPE_DOES_NOT_AGREE,
idClassAttribute.getName(),
idClassAttributeTypeName
@@ -232,7 +232,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH,
idClassAttribute.getName()
)
@@ -253,7 +253,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST,
attributeMapping.getName()
)
@@ -273,13 +273,17 @@ public abstract class AbstractPrimaryKeyValidator
validateIdClassConstructor(idClass, messages, reporter);
}
+ protected TextRange getIdClassRefValidationTextRange() {
+ return idClassReference().getValidationTextRange();
+ }
+
protected void checkMissingAttribute(JavaPersistentType idClass,
AttributeMapping attributeMapping, List<IMessage> messages, IReporter reporter) {
if (!IterableTools.contains(getIdClassAttributeNames(idClass), attributeMapping.getName())) {
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST,
attributeMapping.getName()
)
@@ -297,7 +301,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_NO_ARG_CONSTRUCTOR,
idClass.getName()
)
@@ -342,7 +346,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_NO_MATCH,
attributeMapping.getName()
)
@@ -353,7 +357,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_DUPLICATE_MATCH,
attributeMapping.getName()
)
@@ -389,7 +393,7 @@ public abstract class AbstractPrimaryKeyValidator
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_PROPERTY_METHOD_NOT_PUBLIC,
idClass.getJavaResourceType().getTypeBinding().getQualifiedName(),
methodName
@@ -508,7 +512,18 @@ public abstract class AbstractPrimaryKeyValidator
// **************** id class **********************************************
- protected boolean specifiesIdClass() {
+ /**
+ * Return whether an id class is specified on the class locally
+ */
+ protected boolean declaresIdClassLocally() {
+ return typeMapping().getIdClassReference().isSpecified();
+ }
+
+ /**
+ * Return whether an id class is specified in the class hierarchy
+ * either on current class or on the super class
+ */
+ protected boolean declaresIdClassInHierarchy() {
return idClassReference().isSpecified();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkEntityPrimaryKeyValidator.java
index 2ca8b04b9c..31ee722856 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkEntityPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkEntityPrimaryKeyValidator.java
@@ -9,8 +9,11 @@
******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.context;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.jpt.common.core.internal.utility.ValidationMessageTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.jpa.core.context.IdClassReference;
import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.AbstractEntityPrimaryKeyValidator;
@@ -40,11 +43,11 @@ public class EclipseLinkEntityPrimaryKeyValidator
// However, the id class may only be defined on one class in the hierarchy.
@Override
protected void validatePrimaryKeyIsNotRedefined(List<IMessage> messages, IReporter reporter) {
- if (idClassReference().isSpecified() && definesIdClassOnAncestor(typeMapping())) {
+ if (declaresIdClassLocally() && definesIdClassOnAncestor(typeMapping())) {
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),
- idClassReference().getValidationTextRange(),
+ getIdClassRefValidationTextRange(),
JptJpaCoreValidationMessages.TYPE_MAPPING_ID_CLASS_REDEFINED
)
);
@@ -58,9 +61,10 @@ public class EclipseLinkEntityPrimaryKeyValidator
|| ((EclipseLinkTypeMapping) typeMapping).usesPrimaryKeyTenantDiscriminatorColumns();
}
+ // in EclipseLink, an id class is regarded as specified when it is defined on the class locally or on the super class
@Override
- protected boolean specifiesIdClass() {
- return super.specifiesIdClass() || definesIdClass(typeMapping());
+ protected boolean declaresIdClassInHierarchy() {
+ return super.declaresIdClassInHierarchy() || definesIdClass(typeMapping());
}
@@ -70,4 +74,21 @@ public class EclipseLinkEntityPrimaryKeyValidator
IReporter reporter) {
//do nothing - Eclipselink does not care about the existence status of property methods
}
+
+ @Override
+ protected IdClassReference idClassReference() {
+ return IterableTools.size(getIdClassReferencesOnInheritanceHierarchy(typeMapping())) >= 1 ?
+ IterableTools.first(getIdClassReferencesOnInheritanceHierarchy(typeMapping())) : super.idClassReference(); // multiple id class case is already handled somewhere else
+ }
+
+
+ private Iterable<IdClassReference> getIdClassReferencesOnInheritanceHierarchy(IdTypeMapping typeMapping) {
+ ArrayList<IdClassReference> refs = new ArrayList<IdClassReference>();
+ for (IdTypeMapping each : typeMapping.getInheritanceHierarchy()) {
+ if (each.getIdClassReference().isSpecified()) {
+ refs.add(each.getIdClassReference());
+ }
+ }
+ return refs;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
index 371882b950..325f6254c7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
@@ -40,7 +40,7 @@ public class EclipseLinkMappedSuperclassPrimaryKeyValidator
// However, the id class may only be defined on one class in the hierarchy.
@Override
protected void validatePrimaryKeyIsNotRedefined(List<IMessage> messages, IReporter reporter) {
- if (idClassReference().isSpecified() && definesIdClassOnAncestor(typeMapping())) {
+ if (declaresIdClassLocally() && definesIdClassOnAncestor(typeMapping())) {
messages.add(
ValidationMessageTools.buildValidationMessage(
typeMapping().getResource(),

Back to the top