diff options
author | bvosburgh | 2009-11-11 14:48:30 +0000 |
---|---|---|
committer | bvosburgh | 2009-11-11 14:48:30 +0000 |
commit | d4494415bd024e203e40735f624f5a6ea8f9b949 (patch) | |
tree | 004dd10b846a005a22589429c8ca4ad055c39479 | |
parent | 3ce3bcddf4846b4ed6916a79db86a07935dcbae6 (diff) | |
download | webtools.dali-d4494415bd024e203e40735f624f5a6ea8f9b949.tar.gz webtools.dali-d4494415bd024e203e40735f624f5a6ea8f9b949.tar.xz webtools.dali-d4494415bd024e203e40735f624f5a6ea8f9b949.zip |
[293723] fix metamodel generation problem with Map attributes
10 files changed, 95 insertions, 62 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MultiRelationshipMapping.java index 3c54dd3f53..d30e9e22ab 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MultiRelationshipMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -64,4 +64,5 @@ public interface MultiRelationshipMapping Iterator<String> candidateMapKeyNames(); + String getMetamodelFieldMapKeyTypeName(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java index 2fcfd29763..8524e57ead 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java @@ -15,11 +15,14 @@ import org.eclipse.jpt.core.context.ColumnMapping; import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.core.context.JoinColumn; import org.eclipse.jpt.core.context.JoinTable; +import org.eclipse.jpt.core.context.MultiRelationshipMapping; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.RelationshipMapping; import org.eclipse.jpt.core.context.RelationshipReference; import org.eclipse.jpt.core.context.TypeMapping; +import org.eclipse.jpt.core.jpa2.context.AttributeMapping2_0; +import org.eclipse.jpt.core.jpa2.context.MetamodelField; import org.eclipse.jpt.db.Table; /** @@ -208,4 +211,35 @@ public class MappingTools { } } + public static String getMetamodelFieldMapKeyTypeName(MultiRelationshipMapping mapping) { + Entity targetEntity = mapping.getResolvedTargetEntity(); + if (targetEntity == null) { + return MetamodelField.DEFAULT_TYPE_NAME; + } + String mapKey = mapping.getMapKey(); + if (mapKey == null) { + return MetamodelField.DEFAULT_TYPE_NAME; + } + PersistentAttribute mapKeyAttribute = targetEntity.getPersistentType().resolveAttribute(mapKey); + if (mapKeyAttribute == null) { + return MetamodelField.DEFAULT_TYPE_NAME; + } + AttributeMapping2_0 mapKeyMapping = (AttributeMapping2_0) mapKeyAttribute.getMapping(); + if (mapKeyMapping == null) { + return MetamodelField.DEFAULT_TYPE_NAME; + } + return mapKeyMapping.getMetamodelTypeName(); + } + + + // ********** constructor ********** + + /** + * Suppress default constructor, ensuring non-instantiability. + */ + private MappingTools() { + super(); + throw new UnsupportedOperationException(); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java index fa2f23bb60..9d2348efe7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java @@ -240,6 +240,11 @@ public abstract class AbstractJavaAttributeMapping<T extends Annotation> return typeArgumentNames; } + /** + * by default, we add only the mapping's attribute type name; + * but collection relationship mappings will also need to add the key type + * name if the "collection" is of type java.util.Map + */ protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { typeArgumentNames.add(this.getMetamodelTypeName()); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java index 0e4a97766c..b32ba33c35 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java @@ -14,11 +14,9 @@ import java.util.Iterator; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.java.JavaMultiRelationshipMapping; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.AttributeMapping2_0; -import org.eclipse.jpt.core.jpa2.context.MetamodelField; +import org.eclipse.jpt.core.internal.context.MappingTools; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; @@ -478,28 +476,14 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi } protected void addMetamodelFieldMapKeyTypeArgumentNameTo(ArrayList<String> typeArgumentNames) { - String mapKey = this.getMapKey(); - if (mapKey != null) { - typeArgumentNames.add(this.getMetamodelTypeNameForAttributeNamed(mapKey)); + String keyTypeName = ((JavaPersistentAttribute2_0) this.getPersistentAttribute()).getMetamodelContainerFieldMapKeyTypeName(); + if (keyTypeName != null) { + typeArgumentNames.add(keyTypeName); } } - /** - * pre-condition: attribute name is non-null - */ - protected String getMetamodelTypeNameForAttributeNamed(String attributeName) { - if (this.resolvedTargetEntity == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - PersistentAttribute pa = this.resolvedTargetEntity.getPersistentType().resolveAttribute(attributeName); - if (pa == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - AttributeMapping2_0 am = (AttributeMapping2_0) pa.getMapping(); - if (am == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - return am.getMetamodelTypeName(); + public String getMetamodelFieldMapKeyTypeName() { + return MappingTools.getMetamodelFieldMapKeyTypeName(this); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java index 56f4b3e4f4..6e70385954 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java @@ -18,6 +18,7 @@ import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.Embeddable; +import org.eclipse.jpt.core.context.MultiRelationshipMapping; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; @@ -33,6 +34,7 @@ import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.Filter; import org.eclipse.jpt.utility.internal.ArrayTools; import org.eclipse.jpt.utility.internal.ClassTools; +import org.eclipse.jpt.utility.internal.Tools; import org.eclipse.jpt.utility.internal.iterables.ArrayIterable; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -444,30 +446,21 @@ public abstract class AbstractJavaPersistentAttribute // to the new mapping; this can't be done in the same was as XmlAttributeMapping // since we don't know all the possible mapping types public void setSpecifiedMappingKey(String key) { - if (key == this.getSpecifiedMappingKey()) { + if (Tools.valuesAreEqual(key, this.getSpecifiedMappingKey())) { return; } - JavaAttributeMapping oldMapping = this.specifiedMapping; + JavaAttributeMapping old = this.specifiedMapping; JavaAttributeMapping newMapping = this.buildMappingFromMappingKey(key); this.specifiedMapping = newMapping; - String newAnnotation; - String[] newSupportingAnnotationNames; - if (newMapping != null) { - newAnnotation = newMapping.getAnnotationName(); - newSupportingAnnotationNames = - ArrayTools.array(newMapping.supportingAnnotationNames(), new String[0]); - } - else { - newAnnotation = null; - newSupportingAnnotationNames = - ArrayTools.array(this.defaultMapping.supportingAnnotationNames(), new String[0]); - } - this.resourcePersistentAttribute.setPrimaryAnnotation( - newAnnotation, newSupportingAnnotationNames); - this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); + String newAnnotation = (newMapping == null) ? null : newMapping.getAnnotationName(); + JavaAttributeMapping mapping = (newMapping == null) ? this.defaultMapping : newMapping; + String[] newSupportingAnnotationNames = ArrayTools.array(mapping.supportingAnnotationNames(), EMPTY_STRING_ARRAY); + this.resourcePersistentAttribute.setPrimaryAnnotation(newAnnotation, newSupportingAnnotationNames); + this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, old, newMapping); } + protected static final String[] EMPTY_STRING_ARRAY = new String[0]; /** * return the annotation name of the currently specified mapping or null @@ -611,6 +604,7 @@ public abstract class AbstractJavaPersistentAttribute boolean isContainer(); String getMultiReferenceEntityTypeName(JavaResourcePersistentAttribute resourcePersistentAttribute); String getMetamodelContainerFieldTypeName(); + String getMetamodelContainerFieldMapKeyTypeName(MultiRelationshipMapping mapping); final class Null implements JpaContainer { public static final JpaContainer INSTANCE = new Null(); @@ -633,6 +627,9 @@ public abstract class AbstractJavaPersistentAttribute public String getMetamodelContainerFieldTypeName() { return JPA2_0.COLLECTION_ATTRIBUTE; } + public String getMetamodelContainerFieldMapKeyTypeName(MultiRelationshipMapping mapping) { + return null; + } @Override public String toString() { return "JpaContainer.Null"; //$NON-NLS-1$ @@ -689,6 +686,9 @@ public abstract class AbstractJavaPersistentAttribute null; } + public String getMetamodelContainerFieldMapKeyTypeName(MultiRelationshipMapping mapping) { + return null; + } } /** @@ -705,6 +705,9 @@ public abstract class AbstractJavaPersistentAttribute null; } + public String getMetamodelContainerFieldMapKeyTypeName(MultiRelationshipMapping mapping) { + return mapping.getMetamodelFieldMapKeyTypeName(); + } } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java index e2e13ff04e..0d448fa488 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java @@ -313,6 +313,11 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> return typeArgumentNames; } + /** + * by default, we add only the mapping's attribute type name; + * but collection relationship mappings will also need to add the key type + * name if the "collection" is of type java.util.Map + */ protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { typeArgumentNames.add(this.getMetamodelTypeName()); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java index 0fa7173ab2..e97434f4b8 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java @@ -14,11 +14,9 @@ import java.util.Iterator; import org.eclipse.jpt.core.context.FetchType; import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.AttributeMapping2_0; -import org.eclipse.jpt.core.jpa2.context.MetamodelField; +import org.eclipse.jpt.core.internal.context.MappingTools; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.resource.orm.AbstractXmlMultiRelationshipMapping; import org.eclipse.jpt.core.resource.orm.MapKey; @@ -376,28 +374,14 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends AbstractXmlM } protected void addMetamodelFieldMapKeyTypeArgumentNameTo(ArrayList<String> typeArgumentNames) { - String mapKey = this.getMapKey(); - if (mapKey != null) { - typeArgumentNames.add(this.getMetamodelTypeNameForAttributeNamed(mapKey)); + String keyTypeName = ((JavaPersistentAttribute2_0) this.getJavaPersistentAttribute()).getMetamodelContainerFieldMapKeyTypeName(); + if (keyTypeName != null) { + typeArgumentNames.add(keyTypeName); } } - /** - * pre-condition: attribute name is non-null - */ - protected String getMetamodelTypeNameForAttributeNamed(String attributeName) { - if (this.resolvedTargetEntity == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - PersistentAttribute pa = this.resolvedTargetEntity.getPersistentType().resolveAttribute(attributeName); - if (pa == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - AttributeMapping2_0 am = (AttributeMapping2_0) pa.getMapping(); - if (am == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - return am.getMetamodelTypeName(); + public String getMetamodelFieldMapKeyTypeName() { + return MappingTools.getMetamodelFieldMapKeyTypeName(this); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java index 11bde159f9..b390a08fbc 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal.jpa2.context.java; import org.eclipse.jpt.core.context.AccessType; +import org.eclipse.jpt.core.context.MultiRelationshipMapping; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; import org.eclipse.jpt.core.jpa2.context.MetamodelField; @@ -75,6 +76,10 @@ public class GenericJavaPersistentAttribute2_0 return this.getJpaContainer(this.resourcePersistentAttribute.getTypeName()).getMetamodelContainerFieldTypeName(); } + public String getMetamodelContainerFieldMapKeyTypeName() { + return this.getJpaContainer(this.resourcePersistentAttribute.getTypeName()).getMetamodelContainerFieldMapKeyTypeName((MultiRelationshipMapping) this.getMapping()); + } + public String getMetamodelTypeName() { String typeName = this.resourcePersistentAttribute.getTypeName(); if (typeName == null) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaPersistentAttribute2_0.java index bd51818278..6e50f76aeb 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaPersistentAttribute2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaPersistentAttribute2_0.java @@ -30,6 +30,13 @@ public interface JavaPersistentAttribute2_0 String getMetamodelContainerFieldTypeName(); /** + * Return the name of the container map key type to be used in the + * metamodel field declaration corresponding to the attribute's mapping. + * Return null if the attribute's type is not {@link java.util.Map}. + */ + String getMetamodelContainerFieldMapKeyTypeName(); + + /** * Return the attribute's type name for the metamodel. */ String getMetamodelTypeName(); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java index d7e7466c0b..69c9c118c7 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.core.internal.context.java; import org.eclipse.jpt.core.context.AccessType; +import org.eclipse.jpt.core.context.MultiRelationshipMapping; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; import org.eclipse.jpt.core.jpa2.context.MetamodelField; @@ -76,6 +77,10 @@ public class JavaEclipseLinkPersistentAttribute return this.getJpaContainer(this.resourcePersistentAttribute.getTypeName()).getMetamodelContainerFieldTypeName(); } + public String getMetamodelContainerFieldMapKeyTypeName() { + return this.getJpaContainer(this.resourcePersistentAttribute.getTypeName()).getMetamodelContainerFieldMapKeyTypeName((MultiRelationshipMapping) this.getMapping()); + } + public String getMetamodelTypeName() { String typeName = this.resourcePersistentAttribute.getTypeName(); if (typeName == null) { |