Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhauge2011-02-01 18:03:07 +0000
committernhauge2011-02-01 18:03:07 +0000
commit9d29fd79758f9535499059f76d2ffd8b122dc316 (patch)
tree2bfa3ea070ee3915da03b787e20cf6867129feb3
parentfd7e3ccac5c10412920f9d08e792aaa8e911efb2 (diff)
downloadwebtools.dali-9d29fd79758f9535499059f76d2ffd8b122dc316.tar.gz
webtools.dali-9d29fd79758f9535499059f76d2ffd8b122dc316.tar.xz
webtools.dali-9d29fd79758f9535499059f76d2ffd8b122dc316.zip
334134 - fix to prevent invalid validation message for inherited PK's in Generic platform.
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java106
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java88
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityPrimaryKeyValidator.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java4
6 files changed, 184 insertions, 115 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java
new file mode 100644
index 0000000000..48e1a0fa02
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle.
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.core.internal.jpa1.context;
+
+import java.util.List;
+
+import org.eclipse.jpt.core.context.AttributeMapping;
+import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.IdClassReference;
+import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
+import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+
+public abstract class AbstractEntityPrimaryKeyValidator extends
+ AbstractPrimaryKeyValidator {
+
+ public AbstractEntityPrimaryKeyValidator(Entity entity,
+ PrimaryKeyTextRangeResolver textRangeResolver) {
+ super(entity, textRangeResolver);
+ }
+
+ protected Entity entity() {
+ return (Entity) this.typeMapping();
+ }
+
+ @Override
+ protected IdClassReference idClassReference() {
+ return entity().getIdClassReference();
+ }
+
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ // if an entity is non-root, it is not allowed to define primary keys
+ if (! entity().isRoot()) {
+ validatePrimaryKeyForNonRoot(messages, reporter);
+ }
+ else {
+ validatePrimaryKeyForRoot(messages, reporter);
+ }
+ }
+
+ protected void validatePrimaryKeyForNonRoot(List<IMessage> messages, IReporter reporter) {
+ validateNonRootEntityDoesNotSpecifyIdClass(messages, reporter);
+ validateNonRootEntityDoesNotSpecifyPrimaryKeyAttributes(messages, reporter);
+ }
+
+ protected void validatePrimaryKeyForRoot(List<IMessage> messages, IReporter reporter) {
+ validatePrimaryKeyIsNotRedefined(messages, reporter);
+ validateIdClassIsUsedIfNecessary(messages, reporter);
+
+ // if the primary key is not defined on an ancestor, it must be defined here
+ if (! definesPrimaryKey(typeMapping())) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.ENTITY_NO_PK,
+ new String[0],
+ entity(),
+ textRangeResolver().getTypeMappingTextRange()));
+ }
+
+ // if primary key is composite, it may either use an id class or embedded id, not both
+ validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter);
+ // ... and only one embedded id
+ validateOneEmbeddedId(messages, reporter);
+
+ validateMapsIdMappings(messages, reporter);
+
+ if (specifiesIdClass()) {
+ validateIdClass(idClassReference().getIdClass(), messages, reporter);
+ }
+ }
+
+ protected void validateNonRootEntityDoesNotSpecifyIdClass(List<IMessage> messages, IReporter reporter) {
+ if (idClassReference().isSpecified()) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.ENTITY_NON_ROOT_ID_CLASS_SPECIFIED,
+ new String[0],
+ entity(),
+ textRangeResolver().getIdClassTextRange()));
+ }
+ }
+
+ protected void validateNonRootEntityDoesNotSpecifyPrimaryKeyAttributes(List<IMessage> messages, IReporter reporter) {
+ for (AttributeMapping each : getPrimaryKeyMappingsDefinedLocally(typeMapping())) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED,
+ new String[0],
+ each,
+ textRangeResolver().getAttributeMappingTextRange(each.getName())));
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java
new file mode 100644
index 0000000000..364cedfd27
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle.
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.core.internal.jpa1.context;
+
+import java.util.List;
+import org.eclipse.jpt.core.context.IdClassReference;
+import org.eclipse.jpt.core.context.MappedSuperclass;
+import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+
+public abstract class AbstractMappedSuperclassPrimaryKeyValidator
+ extends AbstractPrimaryKeyValidator
+{
+ public AbstractMappedSuperclassPrimaryKeyValidator(
+ MappedSuperclass mappedSuperclass, PrimaryKeyTextRangeResolver textRangeResolver) {
+
+ super(mappedSuperclass, textRangeResolver);
+ }
+
+
+ protected MappedSuperclass mappedSuperclass() {
+ return (MappedSuperclass) this.typeMapping();
+ }
+
+ @Override
+ protected IdClassReference idClassReference() {
+ return mappedSuperclass().getIdClassReference();
+ }
+
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ validatePrimaryKeyIsNotRedefined(messages, reporter);
+ validateIdClassIsUsedIfNecessary(messages, reporter);
+
+ // if primary key is composite, it may either use an id class or embedded id, not both
+ validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter);
+ // ... and only one embedded id
+ validateOneEmbeddedId(messages, reporter);
+
+ if (specifiesIdClass()) {
+ validateIdClass(idClassReference().getIdClass(), messages, reporter);
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java
index 82eb610503..2ef9b73cb2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java
@@ -10,96 +10,26 @@
*******************************************************************************/
package org.eclipse.jpt.core.internal.jpa1.context;
-import java.util.List;
-import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Entity;
-import org.eclipse.jpt.core.context.IdClassReference;
import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
-import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
-import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class GenericEntityPrimaryKeyValidator
- extends AbstractPrimaryKeyValidator
+ extends AbstractEntityPrimaryKeyValidator
{
public GenericEntityPrimaryKeyValidator(Entity entity, PrimaryKeyTextRangeResolver textRangeResolver) {
super(entity, textRangeResolver);
}
-
- protected Entity entity() {
- return (Entity) this.typeMapping();
- }
-
@Override
- protected IdClassReference idClassReference() {
- return entity().getIdClassReference();
- }
-
- public void validate(List<IMessage> messages, IReporter reporter) {
- // if an entity is non-root, it is not allowed to define primary keys
- if (! entity().isRoot()) {
- validatePrimaryKeyForNonRoot(messages, reporter);
- }
- else {
- validatePrimaryKeyForRoot(messages, reporter);
- }
- }
-
- protected void validatePrimaryKeyForNonRoot(List<IMessage> messages, IReporter reporter) {
- validateNonRootEntityDoesNotSpecifyIdClass(messages, reporter);
- validateNonRootEntityDoesNotSpecifyPrimaryKeyAttributes(messages, reporter);
- }
-
- protected void validatePrimaryKeyForRoot(List<IMessage> messages, IReporter reporter) {
- validatePrimaryKeyIsNotRedefined(messages, reporter);
- validateIdClassIsUsedIfNecessary(messages, reporter);
-
- // if the primary key is not defined on an ancestor, it must be defined here
- if (! definesPrimaryKey(typeMapping())) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.ENTITY_NO_PK,
- new String[0],
- entity(),
- textRangeResolver().getTypeMappingTextRange()));
- }
-
- // if primary key is composite, it may either use an id class or embedded id, not both
- validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter);
- // ... and only one embedded id
- validateOneEmbeddedId(messages, reporter);
-
- validateMapsIdMappings(messages, reporter);
-
- if (specifiesIdClass()) {
- validateIdClass(idClassReference().getIdClass(), messages, reporter);
+ protected boolean idClassIsRequired() {
+ //Short circuit check for idClassIsRequired if any part of the primary key is defined
+ //in a superclass for Generic types. Other validation will exist and needs to be
+ //addressed first
+ if(definesPrimaryKeyOnAncestor(typeMapping())){
+ return false;
}
+ return super.idClassIsRequired();
}
- protected void validateNonRootEntityDoesNotSpecifyIdClass(List<IMessage> messages, IReporter reporter) {
- if (idClassReference().isSpecified()) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.ENTITY_NON_ROOT_ID_CLASS_SPECIFIED,
- new String[0],
- entity(),
- textRangeResolver().getIdClassTextRange()));
- }
- }
-
- protected void validateNonRootEntityDoesNotSpecifyPrimaryKeyAttributes(List<IMessage> messages, IReporter reporter) {
- for (AttributeMapping each : getPrimaryKeyMappingsDefinedLocally(typeMapping())) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED,
- new String[0],
- each,
- textRangeResolver().getAttributeMappingTextRange(each.getName())));
- }
- }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java
index 55fe5150c5..b9b47ad7bf 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java
@@ -10,43 +10,24 @@
*******************************************************************************/
package org.eclipse.jpt.core.internal.jpa1.context;
-import java.util.List;
-import org.eclipse.jpt.core.context.IdClassReference;
import org.eclipse.jpt.core.context.MappedSuperclass;
import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-public class GenericMappedSuperclassPrimaryKeyValidator
- extends AbstractPrimaryKeyValidator
-{
- public GenericMappedSuperclassPrimaryKeyValidator(
- MappedSuperclass mappedSuperclass, PrimaryKeyTextRangeResolver textRangeResolver) {
+public class GenericMappedSuperclassPrimaryKeyValidator extends
+ AbstractMappedSuperclassPrimaryKeyValidator {
+
+ public GenericMappedSuperclassPrimaryKeyValidator(MappedSuperclass mappedSuperclass, PrimaryKeyTextRangeResolver textRangeResolver) {
+ super(mappedSuperclass, textRangeResolver);
+ }
- super(mappedSuperclass, textRangeResolver);
- }
-
-
- protected MappedSuperclass mappedSuperclass() {
- return (MappedSuperclass) this.typeMapping();
- }
-
@Override
- protected IdClassReference idClassReference() {
- return mappedSuperclass().getIdClassReference();
- }
-
- public void validate(List<IMessage> messages, IReporter reporter) {
- validatePrimaryKeyIsNotRedefined(messages, reporter);
- validateIdClassIsUsedIfNecessary(messages, reporter);
-
- // if primary key is composite, it may either use an id class or embedded id, not both
- validateOneOfIdClassOrEmbeddedIdIsUsed(messages, reporter);
- // ... and only one embedded id
- validateOneEmbeddedId(messages, reporter);
-
- if (specifiesIdClass()) {
- validateIdClass(idClassReference().getIdClass(), messages, reporter);
+ protected boolean idClassIsRequired() {
+ //Short circuit check for idClassIsRequired if any part of the primary key is defined
+ //in a superclass for Generic types. Other validation will exist and needs to be
+ //addressed first
+ if(definesPrimaryKeyOnAncestor(typeMapping())){
+ return false;
}
+ return super.idClassIsRequired();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityPrimaryKeyValidator.java
index b12d908a0f..f6a6a2b348 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityPrimaryKeyValidator.java
@@ -13,7 +13,7 @@ package org.eclipse.jpt.eclipselink.core.internal.v1_1.context;
import java.util.List;
import org.eclipse.jpt.core.context.TypeMapping;
import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
-import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator;
+import org.eclipse.jpt.core.internal.jpa1.context.AbstractEntityPrimaryKeyValidator;
import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkEntity;
@@ -22,7 +22,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class EclipseLinkEntityPrimaryKeyValidator
- extends GenericEntityPrimaryKeyValidator
+ extends AbstractEntityPrimaryKeyValidator
{
public EclipseLinkEntityPrimaryKeyValidator(
EclipseLinkEntity entity, PrimaryKeyTextRangeResolver textRangeResolver) {
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
index c194a10992..4eddd9a673 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkMappedSuperclassPrimaryKeyValidator.java
@@ -14,7 +14,7 @@ import java.util.List;
import org.eclipse.jpt.core.context.TypeMapping;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver;
-import org.eclipse.jpt.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator;
+import org.eclipse.jpt.core.internal.jpa1.context.AbstractMappedSuperclassPrimaryKeyValidator;
import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkMappedSuperclass;
@@ -23,7 +23,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class EclipseLinkMappedSuperclassPrimaryKeyValidator
- extends GenericMappedSuperclassPrimaryKeyValidator
+ extends AbstractMappedSuperclassPrimaryKeyValidator
{
public EclipseLinkMappedSuperclassPrimaryKeyValidator(
EclipseLinkMappedSuperclass mappedSuperclass, PrimaryKeyTextRangeResolver textRangeResolver) {

Back to the top