diff options
author | kmoore | 2012-01-05 20:38:23 +0000 |
---|---|---|
committer | kmoore | 2012-01-05 20:38:23 +0000 |
commit | e9d9f7a5fb46b9904f2bade8bb964685a0607b3b (patch) | |
tree | 6eb959935dabdd692344775aea21a5490178d8e8 /jpa/plugins/org.eclipse.jpt.jpa.core/src | |
parent | f084e6d5c6e20a08394679e05e9f44bd9c4dc508 (diff) | |
download | webtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.tar.gz webtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.tar.xz webtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.zip |
Bug 236087 - validation for IdClass - patch from Nan
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src')
9 files changed, 356 insertions, 38 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java index 5da06a674b..5ff858dcac 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 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. @@ -171,6 +171,18 @@ public interface EntityMappings JavaResourceAbstractType resolveJavaResourceType(String className); /** + * Return the Java resource type for the specified class name and kind + * found in the JPA project. First look for one with the specified + * name (since it might be fully qualified) and kind. If not found, + * prepend the default package name and try again. + * + * Return null if invalid or absent or if the kind does not match. + * + * @see #getPackage() + */ + JavaResourceAbstractType resolveJavaResourceType(String className, JavaResourceAbstractType.Kind kind); + + /** * Return the persistent type for the specified class name * found in the persistence unit. First look for one with the specified * name (since it might be fully qualified). If not found, prepend the diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java index bc62f0ae23..7d6150061a 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. + * Copyright (c) 2011, 2012 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 @@ -157,6 +157,14 @@ public abstract class AbstractAccessor return this.member.isTransient(); } + public boolean isProtected() { + return this.member.isProtected(); + } + + public boolean isPublicOrProtected() { + return isPublic() || isProtected(); + } + public boolean isFor(String memberName, int occurrence) { return this.member.isFor(memberName, occurrence); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaIdClassReference.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaIdClassReference.java index 2e00357467..ae12ff6f56 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaIdClassReference.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaIdClassReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. + * Copyright (c) 2010, 2012 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. @@ -11,8 +11,9 @@ package org.eclipse.jpt.jpa.core.internal.context.java; import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; +import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; +import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; @@ -199,6 +200,7 @@ public class GenericJavaIdClassReference protected JavaResourceType getIdClassJavaResourceType() { return (JavaResourceType) this.getJpaProject().getJavaResourceType(this.fullyQualifiedIdClassName, Kind.TYPE); } + protected JavaPersistentType buildIdClass(JavaResourceType resourceClass) { return this.getJpaFactory().buildJavaPersistentType(this, resourceClass); } @@ -251,17 +253,56 @@ public class GenericJavaIdClassReference protected void validateIdClass(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { if (this.isSpecified()) { JavaResourceType jrt = this.getIdClassJavaResourceType(); - if ((jrt != null) && (jrt.isAnnotatedWith(getJpaProject().getTypeMappingAnnotations()))) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_VALID, - new String[] {jrt.getName()}, - this, - this.getValidationTextRange(astRoot) - ) - ); - } + if (jrt != null) { + + if (!jrt.isPublic()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_PUBLIC, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange(astRoot) + ) + ); + } + + if (!JDTTools.typeIsSubType(this.getJpaProject().getJavaProject(), jrt.getQualifiedName(), JDTTools.SERIALIZABLE_CLASS_NAME)) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_IMPLEMENT_SERIALIZABLE, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange(astRoot) + ) + ); + } + + if (!jrt.hasEqualsMethod()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_EQUALS_METHOD, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange(astRoot) + ) + ); + } + + if (!jrt.hasHashCodeMethod()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_HASHCODE_METHOD, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange(astRoot) + ) + ); + } + } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java index 9713857022..8184ae5fa5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Oracle. All rights reserved. + * Copyright (c) 2006, 2012 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. @@ -480,6 +480,14 @@ public abstract class AbstractEntityMappings return (JavaResourceAbstractType) this.resolveType(RESOURCE_TYPE_LOOKUP_ADAPTER, className); } + public JavaResourceAbstractType resolveJavaResourceType(String className, JavaResourceAbstractType.Kind kind) { + JavaResourceAbstractType resourceType = this.resolveJavaResourceType(className); + if (resourceType == null || resourceType.getKind() != kind) { + return null; + } + return resourceType; + } + public IType resolveJdtType(String className) { return (IType) this.resolveType(JDT_TYPE_LOOKUP_ADAPTER, className); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java index 2dd804a825..5edfb02562 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. + * Copyright (c) 2010, 2012 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. @@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.context.orm; import java.util.List; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; +import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; @@ -330,17 +331,56 @@ public class GenericOrmIdClassReference protected void validateIdClass(List<IMessage> messages, IReporter reporter) { if (this.isSpecified()) { - JavaResourceAbstractType jrt = getEntityMappings().resolveJavaResourceType(this.getIdClassName()); - if ((jrt != null) && (jrt.isAnnotatedWith(this.getJpaProject().getTypeMappingAnnotations()))) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_VALID, - EMPTY_STRING_ARRAY, - this, - this.getValidationTextRange() - ) - ); + JavaResourceType jrt = this.getIdClassJavaResourceType(); + if (jrt != null) { + + if (!jrt.isPublic()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_PUBLIC, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange() + ) + ); + } + + if (!JDTTools.typeIsSubType(this.getJpaProject().getJavaProject(), jrt.getQualifiedName(), JDTTools.SERIALIZABLE_CLASS_NAME)) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NOT_IMPLEMENT_SERIALIZABLE, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange() + ) + ); + } + + if (!jrt.hasEqualsMethod()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_EQUALS_METHOD, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange() + ) + ); + } + + if (!jrt.hasHashCodeMethod()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_HASHCODE_METHOD, + new String[] {jrt.getQualifiedName()}, + this, + this.getValidationTextRange() + ) + ); + } } else if (StringTools.stringIsEmpty(this.getIdClassName())) { messages.add( DefaultJpaValidationMessages.buildMessage( @@ -365,6 +405,10 @@ public class GenericOrmIdClassReference } } + protected JavaResourceType getIdClassJavaResourceType() { + return (JavaResourceType) getEntityMappings().resolveJavaResourceType(this.getIdClassName(), Kind.TYPE); + } + protected boolean idClassExists() { return getEntityMappings().resolveJdtType(getIdClassName()) != null; } 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 20333cca33..11f6b92c47 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. + * Copyright (c) 2010, 2012 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. @@ -11,6 +11,8 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import java.util.Collection; import java.util.List; +import org.eclipse.jpt.common.core.resource.java.JavaResourceField; +import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.common.utility.internal.ClassName; import org.eclipse.jpt.common.utility.internal.CollectionTools; import org.eclipse.jpt.common.utility.internal.HashBag; @@ -19,7 +21,9 @@ import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper; +import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; import org.eclipse.jpt.jpa.core.MappingKeys; +import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; import org.eclipse.jpt.jpa.core.context.Entity; @@ -31,6 +35,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.internal.context.JptValidator; import org.eclipse.jpt.jpa.core.internal.context.PrimaryKeyTextRangeResolver; +import org.eclipse.jpt.jpa.core.internal.context.java.PropertyAccessor; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.jpa2.context.SingleRelationshipMapping2_0; @@ -40,9 +45,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractPrimaryKeyValidator implements JptValidator { - private TypeMapping typeMapping; + private final TypeMapping typeMapping; - private PrimaryKeyTextRangeResolver textRangeResolver; + private final PrimaryKeyTextRangeResolver textRangeResolver; public static final String[] EMPTY_STRING_ARRAY = StringTools.EMPTY_STRING_ARRAY; @@ -168,9 +173,8 @@ public abstract class AbstractPrimaryKeyValidator validateIdClass_derivedIdMappingMatchingIdClass(idClass, messages, reporter); return; } - for (JavaPersistentAttribute idClassAttribute : - new SubIterableWrapper<ReadOnlyPersistentAttribute, JavaPersistentAttribute>( - idClass.getAllAttributes())) { + + for (JavaPersistentAttribute idClassAttribute : this.getAllIdClassAttributes(idClass)) { boolean foundMatch = false; for (AttributeMapping attributeMapping : getAttributeMappings(typeMapping())) { if (idClassAttribute.getName().equals(attributeMapping.getName())) { @@ -211,8 +215,75 @@ public abstract class AbstractPrimaryKeyValidator textRangeResolver().getIdClassTextRange())); } } + + // This is for validating if a type mapping has extra id attributes that do not match + // an attribute on the id class, which is a supplement of the validation right above + for (AttributeMapping attributeMapping : getPrimaryKeyMappings(typeMapping())) { + AccessType type = attributeMapping.getPersistentAttribute().getOwningPersistentType().getAccess(); + if (type == AccessType.FIELD) { + checkMissingAttribute(idClass, attributeMapping, messages, reporter); + } else if (type == AccessType.PROPERTY) { + // EclipseLink does not care about the existence status of property methods, + // but the matching field in the id class still needs to exist + if (!CollectionTools.contains(getIdClassFieldNames(idClass), attributeMapping.getName())) { + messages.add(DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST, + new String[] {attributeMapping.getName()}, + typeMapping(), + textRangeResolver().getIdClassTextRange())); + } else { + // Validation for missing property methods is only for generic platform + checkMissingAttributeWithPropertyAccess(idClass, attributeMapping, messages, reporter); + } + } + } + + // This is for validating cases when id class has property-based access + if (typeMapping().getPersistentType().getAccess() == AccessType.PROPERTY) { + validateIdClassAttributesWithPropertyAccess(idClass, messages, reporter); + } + + validateIdClassConstructor(idClass, messages, reporter); + } + + protected void checkMissingAttribute(JavaPersistentType idClass, + AttributeMapping attributeMapping, List<IMessage> messages, IReporter reporter) { + if (!CollectionTools.contains(getIdClassAttributeNames(idClass), attributeMapping.getName())) { + messages.add(DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST, + new String[] {attributeMapping.getName()}, + typeMapping(), + textRangeResolver().getIdClassTextRange()) + ); + } + } + + protected abstract void validateIdClassAttributesWithPropertyAccess( + JavaPersistentType idClass, List<IMessage> messages, + IReporter reporter); + + protected void validateIdClassConstructor(JavaPersistentType idClass, + List<IMessage> messages, IReporter reporter) { + if (!idClass.getJavaResourceType().hasNoArgConstructor()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_NO_ARG_CONSTRUCTOR, + new String[] {idClass.getName()}, + typeMapping(), + textRangeResolver().getIdClassTextRange()) + ); + } } + protected void checkMissingAttributeWithPropertyAccess(JavaPersistentType idClass, + AttributeMapping attributeMapping, + List<IMessage> messages, IReporter reporter) { + // do nothing + } + protected void validateIdClass_derivedIdMappingMatchingIdClass( JavaPersistentType idClass, List<IMessage> messages, IReporter reporter) { @@ -258,6 +329,63 @@ public abstract class AbstractPrimaryKeyValidator textRangeResolver().getIdClassTextRange())); } + protected void validateIdClassPropertyMethods( + JavaPersistentType idClass, List<IMessage> messages, IReporter reporter) { + + for (JavaPersistentAttribute attribute : getAllIdClassAttributes(idClass)) { + PropertyAccessor accessor = (PropertyAccessor)attribute.getAccessor(); + + // validate getter method + JavaResourceMethod getter = accessor.getResourceGetter(); + if (getter != null) { + validatePropertyMethod(idClass, getter.getMethodName(), messages, reporter); + } + + // validate setter method + JavaResourceMethod setter = accessor.getResourceSetter(); + if (setter != null) { + validatePropertyMethod(idClass, setter.getMethodName(), messages, reporter); + } + } + } + + private void validatePropertyMethod(JavaPersistentType idClass, + String methodName, List<IMessage> messages, IReporter reporter) { + + JavaResourceMethod method = idClass.getJavaResourceType().getMethod(methodName); + + if (!method.isPublicOrProtected()) { + messages.add(DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_PROPERTY_METHOD_NOT_PUBLIC, + new String[] {idClass.getJavaResourceType().getQualifiedName(), methodName}, + typeMapping(), + textRangeResolver().getIdClassTextRange() + )); + } + } + + protected Iterable<String> getIdClassAttributeNames(JavaPersistentType idClass) { + return new TransformationIterable<JavaPersistentAttribute, String>(getAllIdClassAttributes(idClass)) { + @Override + protected String transform(JavaPersistentAttribute attribute) { + return attribute.getName(); + } + }; + } + + protected Iterable<JavaPersistentAttribute> getAllIdClassAttributes(JavaPersistentType idClass) { + return new SubIterableWrapper<ReadOnlyPersistentAttribute, JavaPersistentAttribute>(idClass.getAllAttributes()); + } + + protected Iterable<String> getIdClassFieldNames(JavaPersistentType idClass) { + return new TransformationIterable<JavaResourceField, String>(idClass.getJavaResourceType().getFields()) { + @Override + protected String transform(JavaResourceField attribute) { + return attribute.getName(); + } + }; + } // **************** convenience methods ******************************************************** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java index 8ce6e54411..058f7b010f 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericEntityPrimaryKeyValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. + * Copyright (c) 2010, 2012 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 @@ -10,8 +10,15 @@ *******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; +import java.util.List; +import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.Entity; +import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.internal.context.PrimaryKeyTextRangeResolver; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.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 AbstractEntityPrimaryKeyValidator @@ -31,4 +38,32 @@ public class GenericEntityPrimaryKeyValidator return super.idClassIsRequired(); } + @Override + protected void validateIdClassConstructor(JavaPersistentType idClass, + List<IMessage> messages, IReporter reporter) { + if (!idClass.getJavaResourceType().hasPublicNoArgConstructor()) { + messages.add(DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_PUBLIC_NO_ARG_CONSTRUCTOR, + new String[] {idClass.getName()}, + typeMapping(), + textRangeResolver().getIdClassTextRange())); + } + } + + @Override + protected void checkMissingAttributeWithPropertyAccess(JavaPersistentType idClass, AttributeMapping attributeMapping, + List<IMessage> messages, IReporter reporter) { + // Missing attribute is reported if missing getter or/and setter + // property method(s) in Id class with property access + checkMissingAttribute(idClass, attributeMapping, messages, reporter); + } + + @Override + protected void validateIdClassAttributesWithPropertyAccess( + JavaPersistentType idClass, List<IMessage> messages, + IReporter reporter) { + validateIdClassPropertyMethods(idClass, messages, reporter); + } + }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java index b500925d93..c431490852 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericMappedSuperclassPrimaryKeyValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. + * Copyright (c) 2010, 2012 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 @@ -10,8 +10,15 @@ *******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; +import java.util.List; +import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.MappedSuperclass; +import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.internal.context.PrimaryKeyTextRangeResolver; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class GenericMappedSuperclassPrimaryKeyValidator extends AbstractMappedSuperclassPrimaryKeyValidator { @@ -30,4 +37,32 @@ public class GenericMappedSuperclassPrimaryKeyValidator extends } return super.idClassIsRequired(); } + + @Override + protected void validateIdClassConstructor(JavaPersistentType idClass, + List<IMessage> messages, IReporter reporter) { + if (!idClass.getJavaResourceType().hasPublicNoArgConstructor()) { + messages.add(DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.TYPE_MAPPING_ID_CLASS_MISSING_PUBLIC_NO_ARG_CONSTRUCTOR, + new String[] {idClass.getName()}, + typeMapping(), + textRangeResolver().getIdClassTextRange())); + } + } + + @Override + protected void checkMissingAttributeWithPropertyAccess(JavaPersistentType idClass, AttributeMapping attributeMapping, + List<IMessage> messages, IReporter reporter) { + // Missing attribute is reported if missing getter or/and setter + // property method(s) in Id class with property access + checkMissingAttribute(idClass, attributeMapping, messages, reporter); + } + + @Override + protected void validateIdClassAttributesWithPropertyAccess( + JavaPersistentType idClass, List<IMessage> messages, + IReporter reporter) { + validateIdClassPropertyMethods(idClass, messages, reporter); + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java index 630812ed07..ad84fcaee9 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 Oracle. All rights reserved. + * Copyright (c) 2005, 2012 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. @@ -65,14 +65,21 @@ public interface JpaValidationMessages { public static final String TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR = "TYPE_MAPPING_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR"; public static final String TYPE_MAPPING_FINAL_CLASS = "TYPE_MAPPING_FINAL_CLASS"; 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_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_DOES_NOT_EXIST"; public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_DUPLICATE_MATCH = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_DUPLICATE_MATCH"; public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_NO_MATCH = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_MAPPING_NO_MATCH"; public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NO_MATCH"; public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NOT_PRIMARY_KEY = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_NOT_PRIMARY_KEY"; public static final String TYPE_MAPPING_ID_CLASS_ATTRIBUTE_TYPE_DOES_NOT_AGREE = "TYPE_MAPPING_ID_CLASS_ATTRIBUTE_TYPE_DOES_NOT_AGREE"; + public static final String TYPE_MAPPING_ID_CLASS_MISSING_EQUALS_METHOD = "TYPE_MAPPING_ID_CLASS_MISSING_EQUALS_METHOD"; + public static final String TYPE_MAPPING_ID_CLASS_MISSING_HASHCODE_METHOD = "TYPE_MAPPING_ID_CLASS_MISSING_HASHCODE_METHOD"; + public static final String TYPE_MAPPING_ID_CLASS_MISSING_NO_ARG_CONSTRUCTOR = "TYPE_MAPPING_ID_CLASS_MISSING_NO_ARG_CONSTRUCTOR"; + public static final String TYPE_MAPPING_ID_CLASS_MISSING_PUBLIC_NO_ARG_CONSTRUCTOR = "TYPE_MAPPING_ID_CLASS_MISSING_PUBLIC_NO_ARG_CONSTRUCTOR"; public static final String TYPE_MAPPING_ID_CLASS_NAME_EMPTY = "TYPE_MAPPING_ID_CLASS_NAME_EMPTY"; public static final String TYPE_MAPPING_ID_CLASS_NOT_EXIST = "TYPE_MAPPING_ID_CLASS_NOT_EXIST"; - public static final String TYPE_MAPPING_ID_CLASS_NOT_VALID = "TYPE_MAPPING_ID_CLASS_NOT_VALID"; + public static final String TYPE_MAPPING_ID_CLASS_NOT_IMPLEMENT_SERIALIZABLE = "TYPE_MAPPING_ID_CLASS_NOT_IMPLEMENT_SERIALIZABLE"; + public static final String TYPE_MAPPING_ID_CLASS_NOT_PUBLIC = "TYPE_MAPPING_ID_CLASS_NOT_PUBLIC"; + public static final String TYPE_MAPPING_ID_CLASS_PROPERTY_METHOD_NOT_PUBLIC = "TYPE_MAPPING_ID_CLASS_PROPERTY_METHOD_NOT_PUBLIC"; public static final String TYPE_MAPPING_ID_CLASS_REDEFINED = "TYPE_MAPPING_ID_CLASS_REDEFINED"; public static final String TYPE_MAPPING_ID_CLASS_REQUIRED = "TYPE_MAPPING_ID_CLASS_REQUIRED"; public static final String TYPE_MAPPING_ID_CLASS_WITH_MAPS_ID = "TYPE_MAPPING_ID_CLASS_WITH_MAPS_ID"; |