diff options
Diffstat (limited to 'jpa/plugins')
20 files changed, 359 insertions, 14 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties index fe1597cfb4..9ee7de3dec 100644 --- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties +++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties @@ -32,6 +32,8 @@ ENTITY_NO_ID=Entity \"{0}\" has no Id or EmbeddedId PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME=Unspecified name PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME=Attribute \"{0}\" in class \"{1}\" cannot be resolved PERSISTENT_ATTRIBUTE_INVALID_MAPPING=Attribute \"{0}\" has invalid mapping type in this context +MAPPING_UNRESOLVED_MAPPED_BY=Cannot resolve attribute named \"{0}\" +MAPPING_INVALID_MAPPED_BY=Attribute named \"{0}\" has invalid mapping for this relationship TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for table \"{1}\" TABLE_UNRESOLVED_NAME=Table \"{0}\" cannot be resolved SECONDARY_TABLE_UNRESOLVED_SCHEMA=Schema \"{0}\" cannot be resolved for secondary table \"{1}\" diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IPersistentType.java index 324f0c79b6..80193bee1a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/IPersistentType.java @@ -95,7 +95,19 @@ public interface IPersistentType extends IJpaContentNode * @return */ Iterator<IPersistentAttribute> allAttributes(); + + /** + * Return the attribute named <code>attributeName</code> if + * it exists locally on this type + */ + IPersistentAttribute attributeNamed(String attributeName); + /** + * Resolve and return the attribute named <code>attributeName</code> if it + * is distinct and exists within the context of this type + */ + IPersistentAttribute resolveAttribute(String attributeName); + Iterator<IPersistentType> inheritanceHierarchy(); /** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java index 0c99d1cac4..822aba10ff 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/JavaPersistentType.java @@ -72,6 +72,7 @@ import org.eclipse.jpt.utility.internal.Filter; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; import org.eclipse.jpt.utility.internal.iterators.ChainIterator; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; +import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; @@ -735,14 +736,42 @@ public class JavaPersistentType extends JavaEObject implements IPersistentType } }; } - + + protected Iterator<JavaPersistentAttribute> attributesNamed(final String attributeName) { + return new FilteringIterator<JavaPersistentAttribute>(getAttributes().iterator()) { + @Override + protected boolean accept(Object o) { + return attributeName.equals(((JavaPersistentAttribute) o).getName()); + } + }; + } + public JavaPersistentAttribute attributeNamed(String attributeName) { - for (JavaPersistentAttribute attribute : this.getAttributes()) { - if (attributeName.equals(attribute.getName())) { + Iterator<JavaPersistentAttribute> attributes = attributesNamed(attributeName); + if (attributes.hasNext()) { + return attributes.next(); + } + else { + return null; + } + } + + public IPersistentAttribute resolveAttribute(String attributeName) { + Iterator<JavaPersistentAttribute> attributes = attributesNamed(attributeName); + if (attributes.hasNext()) { + JavaPersistentAttribute attribute = attributes.next(); + + if (attributes.hasNext()) { + // more than one + return null; + } else { return attribute; } + } else if (parentPersistentType() != null) { + return parentPersistentType().resolveAttribute(attributeName); + } else { + return null; } - return null; } public boolean containsOffset(int offset) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java index 4537661960..a0402572d3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaAttributeMapping.java @@ -21,6 +21,7 @@ import org.eclipse.jpt.core.internal.content.java.JavaPersistentAttribute; import org.eclipse.jpt.core.internal.jdtutility.AnnotationAdapter; import org.eclipse.jpt.core.internal.jdtutility.Attribute; import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter; +import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationElementAdapter; import org.eclipse.jpt.core.internal.jdtutility.MemberAnnotationAdapter; import org.eclipse.jpt.core.internal.mappings.INamedColumn; import org.eclipse.jpt.core.internal.platform.DefaultsContext; @@ -105,6 +106,10 @@ public abstract class JavaAttributeMapping extends JavaEObject ITextRange textRange = attribute.annotationTextRange(this.declarationAnnotationAdapter()); return (textRange == null) ? this.getPersistentAttribute().getTextRange() : textRange; } + + protected ITextRange elementTextRange(DeclarationAnnotationElementAdapter elementAdapter) { + return this.elementTextRange(this.attribute.annotationElementTextRange(elementAdapter)); + } protected IType jdtType() { return this.typeMapping().getPersistentType().findJdtType(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaManyToMany.java index 3483503985..fcf147192b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaManyToMany.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaManyToMany.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal.content.java.mappings; import org.eclipse.emf.ecore.EClass; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.jdtutility.Attribute; import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter; @@ -83,4 +84,12 @@ public class JavaManyToMany extends JavaMultiRelationshipMapping protected DeclarationAnnotationElementAdapter mappedByAdapter() { return MAPPED_BY_ADAPTER; } + + + // ********** INonOwningMapping implementation ********** + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java index f9e00a64df..b84f0cc9bd 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaMultiRelationshipMapping.java @@ -243,6 +243,10 @@ public abstract class JavaMultiRelationshipMapping if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaMappingsPackage.JAVA_MULTI_RELATIONSHIP_MAPPING__MAPPED_BY, oldMappedBy, mappedBy)); } + + public ITextRange getMappedByTextRange() { + return this.elementTextRange(this.mappedByAdapter()); + } /** * Returns the value of the '<em><b>Fetch</b></em>' attribute. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToMany.java index 93ed980c66..b965b23c87 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToMany.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToMany.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal.content.java.mappings; import org.eclipse.emf.ecore.EClass; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.jdtutility.Attribute; import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter; @@ -83,4 +84,12 @@ public class JavaOneToMany extends JavaMultiRelationshipMapping protected DeclarationAnnotationElementAdapter mappedByAdapter() { return MAPPED_BY_ADAPTER; } + + + // ********** INonOwningMapping implementation ********** + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToOne.java index b0f5db62f4..9a310d89c4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToOne.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaOneToOne.java @@ -13,7 +13,9 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.ITextRange; import org.eclipse.jpt.core.internal.jdtutility.AnnotationElementAdapter; import org.eclipse.jpt.core.internal.jdtutility.Attribute; import org.eclipse.jpt.core.internal.jdtutility.DeclarationAnnotationAdapter; @@ -154,6 +156,15 @@ public class JavaOneToOne extends JavaSingleRelationshipMapping if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, JpaJavaMappingsPackage.JAVA_ONE_TO_ONE__MAPPED_BY, oldMappedBy, mappedBy)); } + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); + } + + public ITextRange getMappedByTextRange() { + return this.elementTextRange(MAPPED_BY_ADAPTER); + } /** * <!-- begin-user-doc --> diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlManyToMany.java index f4044c072b..46673ae251 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlManyToMany.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlManyToMany.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal.content.orm; import org.eclipse.emf.ecore.EClass; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.mappings.IManyToMany; @@ -58,4 +59,12 @@ public class XmlManyToMany extends XmlMultiRelationshipMappingInternal public int xmlSequence() { return 6; } + + + // ********** INonOwningMapping implementation ********** + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java index 502caf0250..aeaa60f6a2 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlMultiRelationshipMappingInternal.java @@ -15,12 +15,15 @@ import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.jpt.core.internal.ITextRange; import org.eclipse.jpt.core.internal.ITypeMapping; +import org.eclipse.jpt.core.internal.content.orm.resource.OrmXmlMapper; +import org.eclipse.jpt.core.internal.emfutility.DOMUtilities; import org.eclipse.jpt.core.internal.mappings.DefaultLazyFetchType; import org.eclipse.jpt.core.internal.mappings.IJoinTable; import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; import org.eclipse.jpt.core.internal.mappings.INonOwningMapping; import org.eclipse.jpt.core.internal.mappings.IOrderBy; import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; /** * <!-- begin-user-doc --> @@ -179,6 +182,14 @@ public abstract class XmlMultiRelationshipMappingInternal if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, OrmPackage.XML_MULTI_RELATIONSHIP_MAPPING_INTERNAL__MAPPED_BY, oldMappedBy, mappedBy)); } + + public ITextRange getMappedByTextRange() { + if (node == null) { + return typeMapping().getTextRange(); + } + IDOMNode mappedByNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.MAPPED_BY); + return (mappedByNode == null) ? getTextRange() : buildTextRange(mappedByNode); + } /** * Returns the value of the '<em><b>Fetch</b></em>' attribute. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToMany.java index 16fbdde2ac..0bb34cc234 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToMany.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToMany.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal.content.orm; import org.eclipse.emf.ecore.EClass; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.mappings.IOneToMany; @@ -56,4 +57,12 @@ public class XmlOneToMany extends XmlMultiRelationshipMappingInternal public int xmlSequence() { return 4; } + + + // ********** INonOwningMapping implementation ********** + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToOne.java index 3440896fd1..77e6aaffe4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToOne.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlOneToOne.java @@ -12,10 +12,15 @@ package org.eclipse.jpt.core.internal.content.orm; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.ITextRange; +import org.eclipse.jpt.core.internal.content.orm.resource.OrmXmlMapper; +import org.eclipse.jpt.core.internal.emfutility.DOMUtilities; import org.eclipse.jpt.core.internal.mappings.INonOwningMapping; import org.eclipse.jpt.core.internal.mappings.IOneToOne; import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; /** * <!-- begin-user-doc --> @@ -106,6 +111,19 @@ public class XmlOneToOne extends XmlSingleRelationshipMapping if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, OrmPackage.XML_ONE_TO_ONE__MAPPED_BY, oldMappedBy, mappedBy)); } + + public boolean mappedByIsValid(IAttributeMapping mappedByMapping) { + String mappedByKey = mappedByMapping.getKey(); + return (mappedByKey == IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); + } + + public ITextRange getMappedByTextRange() { + if (node == null) { + return typeMapping().getTextRange(); + } + IDOMNode mappedByNode = (IDOMNode) DOMUtilities.getChildAttributeNode(node, OrmXmlMapper.MAPPED_BY); + return (mappedByNode == null) ? getTextRange() : buildTextRange(mappedByNode); + } /** * <!-- begin-user-doc --> diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java index d3806ecd4c..920d3876c5 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlPersistentType.java @@ -44,6 +44,7 @@ import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jpt.utility.internal.iterators.ChainIterator; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; +import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; @@ -876,13 +877,41 @@ public class XmlPersistentType extends XmlEObject implements IPersistentType } } + protected Iterator<XmlPersistentAttribute> attributesNamed(final String attributeName) { + return new FilteringIterator<XmlPersistentAttribute>(getPersistentAttributes().iterator()) { + @Override + protected boolean accept(Object o) { + return attributeName.equals(((XmlPersistentAttribute) o).getName()); + } + }; + } + public XmlPersistentAttribute attributeNamed(String attributeName) { - for (XmlPersistentAttribute attribute : getPersistentAttributes()) { - if (attributeName.equals(attribute.getName())) { + Iterator<XmlPersistentAttribute> attributes = attributesNamed(attributeName); + if (attributes.hasNext()) { + return attributes.next(); + } + else { + return null; + } + } + + public IPersistentAttribute resolveAttribute(String attributeName) { + Iterator<XmlPersistentAttribute> attributes = attributesNamed(attributeName); + if (attributes.hasNext()) { + XmlPersistentAttribute attribute = attributes.next(); + + if (attributes.hasNext()) { + // more than one + return null; + } else { return attribute; } + } else if (parentPersistentType() != null) { + return parentPersistentType().resolveAttribute(attributeName); + } else { + return null; } - return null; } @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java index 678ce4b0a4..ad19528608 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/INonOwningMapping.java @@ -10,6 +10,8 @@ package org.eclipse.jpt.core.internal.mappings; import java.util.Iterator; +import org.eclipse.jpt.core.internal.IAttributeMapping; +import org.eclipse.jpt.core.internal.ITextRange; /** * <!-- begin-user-doc --> @@ -56,4 +58,8 @@ public interface INonOwningMapping extends IRelationshipMapping void setMappedBy(String value); Iterator<String> possibleMappedByAttributeNames(); -} // INonOwningMapping + + boolean mappedByIsValid(IAttributeMapping mappedByMapping); + + ITextRange getMappedByTextRange(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IRelationshipMapping.java index 218c12c16a..65244a504b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IRelationshipMapping.java @@ -131,4 +131,4 @@ public interface IRelationshipMapping extends IAttributeMapping * @return */ IEntity getEntity(); -} // IRelationshipMapping +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java index 70e356a8b5..d82fe7c4f1 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaMultiRelationshipMappingContext.java @@ -10,11 +10,11 @@ package org.eclipse.jpt.core.internal.platform; import java.util.Iterator; import java.util.List; +import org.eclipse.jpt.core.internal.IPersistentAttribute; import org.eclipse.jpt.core.internal.content.java.mappings.JavaMultiRelationshipMapping; import org.eclipse.jpt.core.internal.mappings.IEntity; import org.eclipse.jpt.core.internal.mappings.IJoinColumn; import org.eclipse.jpt.core.internal.mappings.IJoinTable; -import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; import org.eclipse.jpt.core.internal.mappings.ITable; import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; @@ -64,14 +64,19 @@ public abstract class JavaMultiRelationshipMappingContext extends JavaRelationsh } - protected IMultiRelationshipMapping getMapping() { - return (IMultiRelationshipMapping) super.getMapping(); + protected JavaMultiRelationshipMapping getMapping() { + return (JavaMultiRelationshipMapping) super.getMapping(); } public void addToMessages(List<IMessage> messages) { super.addToMessages(messages); - addJoinTableMessages(messages); + if (getMapping().getMappedBy() != null) { + addMappedByMessages(messages); + } + else { + addJoinTableMessages(messages); + } } protected void addJoinTableMessages(List<IMessage> messages) { @@ -154,4 +159,38 @@ public abstract class JavaMultiRelationshipMappingContext extends JavaRelationsh } } } + + protected void addMappedByMessages(List<IMessage> messages) { + JavaMultiRelationshipMapping mapping = getMapping(); + String mappedBy = mapping.getMappedBy(); + IEntity targetEntity = mapping.getResolvedTargetEntity(); + + if (targetEntity == null) { + // already have validation messages for that + return; + } + + IPersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); + + if (attribute == null) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + return; + } + + if (! mapping.mappedByIsValid(attribute.getMapping())) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_INVALID_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + } + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java index 3adb478bff..e28173474e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaOneToOneContext.java @@ -9,7 +9,11 @@ package org.eclipse.jpt.core.internal.platform; import java.util.List; +import org.eclipse.jpt.core.internal.IPersistentAttribute; import org.eclipse.jpt.core.internal.content.java.mappings.JavaOneToOne; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; public class JavaOneToOneContext extends JavaSingleRelationshipMappingContext @@ -18,7 +22,49 @@ public class JavaOneToOneContext extends JavaSingleRelationshipMappingContext super(parentContext, javaOneToOne); } + protected JavaOneToOne getMapping() { + return (JavaOneToOne) super.getMapping(); + } + public void addToMessages(List<IMessage> messages) { super.addToMessages(messages); + + if (getMapping().getMappedBy() != null) { + addMappedByMessages(messages); + } + } + + protected void addMappedByMessages(List<IMessage> messages) { + JavaOneToOne mapping = getMapping(); + String mappedBy = mapping.getMappedBy(); + IEntity targetEntity = mapping.getResolvedTargetEntity(); + + if (targetEntity == null) { + // already have validation messages for that + return; + } + + IPersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); + + if (attribute == null) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + return; + } + + if (! mapping.mappedByIsValid(attribute.getMapping())) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_INVALID_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + } } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java index b1f48120f7..3a7fc8e748 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlMultiRelationshipMappingContext.java @@ -9,9 +9,13 @@ package org.eclipse.jpt.core.internal.platform; import java.util.List; +import org.eclipse.jpt.core.internal.IPersistentAttribute; +import org.eclipse.jpt.core.internal.content.orm.XmlMultiRelationshipMapping; import org.eclipse.jpt.core.internal.content.orm.XmlMultiRelationshipMappingInternal; import org.eclipse.jpt.core.internal.mappings.IEntity; import org.eclipse.jpt.core.internal.mappings.ITable; +import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; public abstract class XmlMultiRelationshipMappingContext @@ -61,7 +65,10 @@ public abstract class XmlMultiRelationshipMappingContext public void addToMessages(List<IMessage> messages) { super.addToMessages(messages); - if (entityOwned()) { + if (multiRelationshipMapping().getMappedBy() != null) { + addMappedByMessages(messages); + } + else if (entityOwned()) { addJoinTableMessages(messages); } } @@ -69,4 +76,38 @@ public abstract class XmlMultiRelationshipMappingContext protected void addJoinTableMessages(List<IMessage> messages) { joinTableContext.addToMessages(messages); } + + protected void addMappedByMessages(List<IMessage> messages) { + XmlMultiRelationshipMapping mapping = multiRelationshipMapping(); + String mappedBy = mapping.getMappedBy(); + IEntity targetEntity = mapping.getResolvedTargetEntity(); + + if (targetEntity == null) { + // already have validation messages for that + return; + } + + IPersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); + + if (attribute == null) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + return; + } + + if (! mapping.mappedByIsValid(attribute.getMapping())) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_INVALID_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + } + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java index 693325376d..ae8bb69bd0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlOneToOneContext.java @@ -9,7 +9,13 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.platform; +import java.util.List; +import org.eclipse.jpt.core.internal.IPersistentAttribute; import org.eclipse.jpt.core.internal.content.orm.XmlOneToOne; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; public class XmlOneToOneContext extends XmlSingleRelationshipMappingContext @@ -17,4 +23,50 @@ public class XmlOneToOneContext public XmlOneToOneContext(IContext parentContext, XmlOneToOne mapping) { super(parentContext, mapping); } + + protected XmlOneToOne getMapping() { + return (XmlOneToOne) super.attributeMapping(); + } + + public void addToMessages(List<IMessage> messages) { + super.addToMessages(messages); + + if (getMapping().getMappedBy() != null) { + addMappedByMessages(messages); + } + } + + protected void addMappedByMessages(List<IMessage> messages) { + XmlOneToOne mapping = getMapping(); + String mappedBy = mapping.getMappedBy(); + IEntity targetEntity = mapping.getResolvedTargetEntity(); + + if (targetEntity == null) { + // already have validation messages for that + return; + } + + IPersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); + + if (attribute == null) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + return; + } + + if (! mapping.mappedByIsValid(attribute.getMapping())) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.MAPPING_INVALID_MAPPED_BY, + new String[] {mappedBy}, + mapping, mapping.getMappedByTextRange()) + ); + } + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java index 9b6dd5bbc4..b42ab33678 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java @@ -60,6 +60,10 @@ public interface IJpaValidationMessages public static final String PERSISTENT_ATTRIBUTE_INVALID_MAPPING = "PERSISTENT_ATTRIBUTE_INVALID_MAPPING"; + public static final String MAPPING_UNRESOLVED_MAPPED_BY = "MAPPING_UNRESOLVED_MAPPED_BY"; + + public static final String MAPPING_INVALID_MAPPED_BY = "MAPPING_INVALID_MAPPED_BY"; + public static final String TABLE_UNRESOLVED_SCHEMA = "TABLE_UNRESOLVED_SCHEMA"; public static final String TABLE_UNRESOLVED_NAME = "TABLE_UNRESOLVED_NAME"; |