diff options
author | Paul Fullbright | 2013-07-08 17:05:43 +0000 |
---|---|---|
committer | Paul Fullbright | 2013-07-08 17:06:42 +0000 |
commit | 959e886d890c18fa5682e2dac86c302230f61fa8 (patch) | |
tree | 8c3f8a0652c79313200237c5cd88b7b3dea1eaab /jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse | |
parent | 46cc00bceda89ffe238d1ce7b169485259daf198 (diff) | |
download | webtools.dali-959e886d890c18fa5682e2dac86c302230f61fa8.tar.gz webtools.dali-959e886d890c18fa5682e2dac86c302230f61fa8.tar.xz webtools.dali-959e886d890c18fa5682e2dac86c302230f61fa8.zip |
Refactored ID type mapping hierarchy and primary key API (bug 313204)
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse')
32 files changed, 1238 insertions, 1017 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/BaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/BaseEmbeddedMapping.java index 2e6ddedaf7..0e8a5b7b43 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/BaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/BaseEmbeddedMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2013 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. @@ -22,18 +22,27 @@ package org.eclipse.jpt.jpa.core.context; * @since 2.0 */ public interface BaseEmbeddedMapping - extends AttributeMapping -{ + extends AttributeMapping { + AttributeOverrideContainer getAttributeOverrideContainer(); + + // ***** target embeddable ***** + /** - * Return the embeddable the embedded mapping references. - * Return <code>null</code> if there is none. + * Return the fully qualified name of the target embeddable. + * This may exist even if {@link #getTargetEmbeddable()} return null. */ - Embeddable getTargetEmbeddable(); + String getTargetEmbeddableName(); /** * String associated with property change events for the target embeddable */ String TARGET_EMBEDDABLE_PROPERTY = "targetEmbeddable"; //$NON-NLS-1$ + + /** + * Return the embeddable the embedded mapping references. + * Return <code>null</code> if there is none. + */ + Embeddable getTargetEmbeddable(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java index 264a233c32..f3173d63f0 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java @@ -27,8 +27,8 @@ import org.eclipse.jpt.common.utility.iterable.ListIterable; * @since 2.0 */ public interface Entity - extends IdTypeMapping -{ + extends IdTypeMapping { + // ********** name ********** String getSpecifiedName(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdClassReference.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdClassReference.java index 45df000fb3..c115e02449 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdClassReference.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdClassReference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Oracle. All rights reserved. + * Copyright (c) 2010, 2013 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. @@ -20,14 +20,19 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. * - * @version 3.2 + * @version 3.6 * @since 2.3 */ public interface IdClassReference - extends JpaContextModel -{ - // ********** id class name ********** - + extends JpaContextModel { + + // ***** id class name ***** + + /** + * Property string associated with changes to the ID class name + */ + String ID_CLASS_NAME_PROPERTY = "idClassName"; //$NON-NLS-1$ + /** * Return the name of the id class, taking into consideration the default value if applicable */ @@ -65,16 +70,20 @@ public interface IdClassReference * applies, this should also return true. */ boolean isSpecified(); - + + /** + * Property string associated with changes to the fully qualified ID class name + */ + String FULLY_QUALIFIED_ID_CLASS_PROPERTY = "fullyQualifiedIdClass"; //$NON-NLS-1$ + /** * Return the fully qualified name of the id class, taking into consideration the default value if applicable */ String getFullyQualifiedIdClassName(); - String FULLY_QUALIFIED_ID_CLASS_PROPERTY = "fullyQualifiedIdClass"; //$NON-NLS-1$ - - // ********** id class ********** - + + // ***** id class ***** + /** * Property string associated with changes to the ID class. * This will change (potentially) if the id class name changes, or if other changes result @@ -94,5 +103,4 @@ public interface IdClassReference * @see org.eclipse.jdt.core.IType#getFullyQualifiedName(char) */ char getIdClassEnclosingTypeSeparator(); - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java index 3a14d74832..01467577ee 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Oracle. All rights reserved. + * Copyright (c) 2012, 2013 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. @@ -9,6 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.context; +import org.eclipse.jpt.common.utility.transformer.Transformer; + /** * ID type mapping:<ul> * <li>entity @@ -19,13 +21,73 @@ package org.eclipse.jpt.jpa.core.context; * It is available at this early stage to solicit feedback from pioneering * adopters on the understanding that any code that uses this API will almost * certainly be broken (repeatedly) as the API evolves. + * + * @version 3.6 + * @since 3.5 */ public interface IdTypeMapping - extends TypeMapping -{ + extends TypeMapping { + + // ***** primary key ***** + /** * Return the (aggregate) class reference for configuring and validating * the type mapping's ID class. */ IdClassReference getIdClassReference(); + + /** + * Return the fully qualified name of the type used as the primary key class + * (e.g. the id class name, or the type of the id mapping, etc.) + */ + String getPrimaryKeyClassName(); + + + // ***** inheritance ***** + + /** + * Return the type mapping's "persistence" inheritance hierarchy, + * <em>including</em> the type mapping itself. + * If there is an inheritance loop, the iterable will terminate before including + * this type mapping a second time. + * @see TypeMapping#getAncestors() + */ + Iterable<IdTypeMapping> getInheritanceHierarchy(); + + /** + * {@link Transformer} that returns the super type mapping of the input, + * except if result would be the leaf type mapping. + * Use to terminate inheritance cycles + * @see IdTypeMapping#getInheritanceHierarchy() + * @see TypeMapping#getAncestors() + */ + class SuperTypeMappingTransformer + implements Transformer<IdTypeMapping, IdTypeMapping> { + + private final IdTypeMapping leaf; + + public SuperTypeMappingTransformer(IdTypeMapping leaf) { + this.leaf = leaf; + } + + public IdTypeMapping transform(IdTypeMapping input) { + IdTypeMapping result = input.getSuperTypeMapping(); + return (result == this.leaf) ? null : result; + } + } + + /** + * Return whether this type mapping is a root entity in an inheritance hierarchy. + */ + boolean isRootEntity(); + + /** + * Return the root entity of the inheritance hierarchy or null. + */ + Entity getRootEntity(); + + /** + * Return the inheritance strategy or null + */ + InheritanceType getInheritanceStrategy(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/PersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/PersistentType.java index 3ff29722a5..a733288c71 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/PersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/PersistentType.java @@ -25,39 +25,44 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. * - * @version 3.3 + * @version 3.6 * @since 2.0 */ public interface PersistentType - extends ManagedType, JpaStructureNode, SpecifiedAccessReference -{ + extends ManagedType, JpaStructureNode, SpecifiedAccessReference { + Class<PersistentType> getManagedTypeType(); - - // ********** mapping ********** - + + + // ***** mapping ***** + + /** + * String associated with changes to the "mapping" property + */ + String MAPPING_PROPERTY = "mapping"; //$NON-NLS-1$ + /** * Return the persistent type's mapping. * Set the mapping via {@link #setMappingKey(String)}. */ TypeMapping getMapping(); - String MAPPING_PROPERTY = "mapping"; //$NON-NLS-1$ + Transformer<PersistentType, TypeMapping> MAPPING_TRANSFORMER = new MappingTransformer(); class MappingTransformer - extends TransformerAdapter<PersistentType, TypeMapping> - { + extends TransformerAdapter<PersistentType, TypeMapping> { @Override public TypeMapping transform(PersistentType pt) { return pt.getMapping(); } } - + String getMappingKey(); - + void setMappingKey(String key); - + boolean isMapped(); - - + + // ********** attributes ********** /** @@ -116,57 +121,28 @@ public interface PersistentType // ********** inheritance ********** - + /** - * Return the "super" {@link PersistentType} from the "persistence" - * inheritance hierarchy. - * If the Java inheritance parent is not a {@link PersistentType}, then continue - * up the hierarchy (the JPA spec allows non-persistent types to be part of the hierarchy.) - * Return <code>null</code> if the persistent type is the root persistent type. - * <p> - * Example: - * <pre> - * @Entity - * public abstract class Model {} - * - * public abstract class Animal extends Model {} - * - * @Entity - * public class Cat extends Animal {} - * </pre> - * The "super" persistent type of the <code>Cat</code> persistent type is - * the <code>Model</code> persistent type. The "super" persistent type can - * be either a Java annotated class or declared in the XML files. + * Return the persistent type of the super type mapping + * @see TypeMapping#getSuperTypeMapping() */ PersistentType getSuperPersistentType(); - String SUPER_PERSISTENT_TYPE_PROPERTY = "superPersistentType"; //$NON-NLS-1$ - Transformer<PersistentType, PersistentType> SUPER_PERSISTENT_TYPE_TRANSFORMER = new SuperPersistentTypeTransformer(); - class SuperPersistentTypeTransformer - extends TransformerAdapter<PersistentType, PersistentType> - { - @Override - public PersistentType transform(PersistentType persistentType) { - return persistentType.getSuperPersistentType(); - } - } - + /** * Return the persistent type's "persistence" inheritance hierarchy, * <em>including</em> the persistent type itself. - * The returned iterator will return elements infinitely if the hierarchy - * has a loop. + * @see TypeMapping#getTypeMappingInheritanceHierarchy() */ Iterable<PersistentType> getInheritanceHierarchy(); - + /** * Return the persistent type's "persistence" inheritance hierarchy, * <em>excluding</em> the persistent type itself. - * The returned iterator will return elements infinitely if the hierarchy - * has a loop. + * @see TypeMapping#getAncesors() */ Iterable<PersistentType> getAncestors(); - - + + // ********** misc ********** /** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TypeMapping.java index 6ff493f36d..39c2f9486c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/TypeMapping.java @@ -10,9 +10,11 @@ package org.eclipse.jpt.jpa.core.context; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; +import org.eclipse.jpt.common.utility.internal.ArrayTools; +import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; +import org.eclipse.jpt.jpa.core.MappingKeys; import org.eclipse.jpt.jpa.db.Schema; /** @@ -27,14 +29,24 @@ import org.eclipse.jpt.jpa.db.Schema; * adopters on the understanding that any code that uses this API will almost * certainly be broken (repeatedly) as the API evolves. * - * @version 3.1 + * @version 3.6 * @since 2.0 */ public interface TypeMapping - extends JpaContextModel -{ + extends JpaContextModel { + PersistentType getPersistentType(); - + + Transformer<TypeMapping, PersistentType> PERSISTENT_TYPE_TRANSFORMER = new PersistentTypeTransformer(); + + class PersistentTypeTransformer + extends TransformerAdapter<TypeMapping, PersistentType> { + @Override + public PersistentType transform(TypeMapping tm) { + return tm.getPersistentType(); + } + } + /** * Return the corresponding java resource type, this can be null */ @@ -54,11 +66,6 @@ public interface TypeMapping boolean isMapped(); - /** - * Return the resolved id class specified on this type mapping, null otherwise - */ - JavaPersistentType getIdClass(); - Iterable<Query> getQueries(); Transformer<TypeMapping, Iterable<Query>> QUERIES_TRANSFORMER = new QueriesTransformer(); class QueriesTransformer @@ -80,39 +87,56 @@ public interface TypeMapping return mapping.getGenerators(); } } - - + + // ********** inheritance ********** /** - * Return the type mapping of this type mapping's super type. - * Return null if this is the root. + * String associated with changes to the super type mapping property */ - TypeMapping getSuperTypeMapping(); + String SUPER_TYPE_MAPPING_PROPERTY = "superTypeMapping"; //$NON-NLS-1$ /** - * Return the type mapping's "persistence" inheritance hierarchy, - * <em>including</em> the type mapping itself. - * The returned iterator will return elements infinitely if the hierarchy - * has a loop. + * Return the "super" {@link TypeMapping} from the "persistence" + * inheritance hierarchy. + * If the Java inheritance parent is not persistent, then continue + * up the hierarchy (the JPA spec allows non-persistent types to be + * part of the hierarchy.) + * Return <code>null</code> if the type mapping is the root. + * <p> + * Example: + * <pre> + * @Entity + * public abstract class Model {} + * + * public abstract class Animal extends Model {} + * + * @Entity + * public class Cat extends Animal {} + * </pre> + * The "super" type mapping of the <code>Cat</code> type mapping is + * the <code>Model</code> type mapping. The "super" type mapping can + * either come from a Java annotated class from an XML mapping file. */ - Iterable<TypeMapping> getInheritanceHierarchy(); + IdTypeMapping getSuperTypeMapping(); /** - * Return the inheritance strategy or null - */ - InheritanceType getInheritanceStrategy(); - - /** - * Return whether this type mapping is a root entity in an inheritance hierarchy. + * Return the type mapping's "persistence" inheritance hierarchy, + * <em>excluding</em> the type mapping itself. + * If there is an inheritance loop, the iterable will terminate before including + * this type mapping. */ - boolean isRootEntity(); - + Iterable<IdTypeMapping> getAncestors(); + /** - * Return the root entity of the inheritance hierarchy or null. + * Return the type mapping's "persistence" inheritance hierarchy, + * <em>including</em> the type mapping itself. + * If there is an inheritance loop, the iterable will terminate before including + * this type mapping. */ - Entity getRootEntity(); - + Iterable<? extends TypeMapping> getInheritanceHierarchy(); + + // ********** tables ********** /** @@ -168,9 +192,9 @@ public interface TypeMapping */ boolean tableNameIsInvalid(String tableName); - + // ********** attribute mappings ********** - + /** * A convenience method for getting the attribute mappings from PersistentType.attributes() */ @@ -205,7 +229,31 @@ public interface TypeMapping * embeddable type mapping) */ boolean attributeMappingKeyAllowed(String attributeMappingKey); - + + /** + * Return all mappings that are mapped as id mappings + * @see MappingIsIdMapping + */ + Iterable<AttributeMapping> getIdAttributeMappings(); + + /** + * Return the (single) mapping used as the id mapping for this type mapping. + * If there is more than one, return null. + * @see MappingIsIdMapping + */ + AttributeMapping getIdAttributeMapping(); + + static String[] ID_ATTRIBUTE_MAPPING_KEYS + = new String[] { MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY }; + + static class MappingIsIdMapping + extends PredicateAdapter<AttributeMapping> { + @Override + public boolean evaluate(AttributeMapping mapping) { + return ArrayTools.contains(ID_ATTRIBUTE_MAPPING_KEYS, mapping.getKey()); + } + } + /** * Return whether the attribute with the specified name is a derived ID. */ diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java index 5c74a5156f..b7994556cc 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * Copyright (c) 2008, 2013 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. @@ -26,8 +26,8 @@ import org.eclipse.jpt.jpa.core.resource.orm.XmlMappedSuperclass; * @since 2.0 */ public interface OrmMappedSuperclass - extends MappedSuperclass, OrmIdTypeMapping -{ + extends MappedSuperclass, OrmIdTypeMapping { + XmlMappedSuperclass getXmlTypeMapping(); JavaMappedSuperclass getJavaTypeMapping(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java index 3de3df4abf..c0b248c6d5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java @@ -21,6 +21,7 @@ import org.eclipse.jpt.jpa.core.context.DeleteTypeRefactoringParticipant; import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.JpaContextModel; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.PersistentTypeContainer; @@ -42,7 +43,7 @@ import org.eclipse.jpt.jpa.core.resource.persistence.XmlProperty; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. * - * @version 3.3 + * @version 3.6 * @since 2.0 */ public interface PersistenceUnit @@ -797,7 +798,15 @@ public interface PersistenceUnit * @see org.eclipse.jpt.jpa.core.MappingKeys#EMBEDDABLE_TYPE_MAPPING_KEY */ Embeddable getEmbeddable(String typeName); - + + /** + * Return the ID type mapping (entity or mapped superclass) in the persistence unit + * with the specified type name. Return null if there is no persistent type with + * the specified name or if the persistent type is not mapped as an entity or + * mapped superclass. + */ + IdTypeMapping getIdTypeMapping(String typeName); + /** * Synchronize the persistence unit's list of specified classes with the * types in the project currently annotated. diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java index 3c355cb1ec..be06988900 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java @@ -18,8 +18,8 @@ import org.eclipse.core.resources.IResource; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.internal.resource.java.source.SourceModel; -import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceModel; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ClassNameTools; @@ -430,7 +430,7 @@ public final class MappingTools { } return null; } - + // TODO move to TypeMapping? may need different name (or may need to rename existing #resolve...) public static SpecifiedRelationship resolveOverriddenRelationship(TypeMapping overridableTypeMapping, String attributeName) { // convenience null check to simplify client code @@ -446,7 +446,7 @@ public final class MappingTools { } return null; } - + public static String getPrimaryKeyColumnName(Entity entity) { String pkColumnName = null; for (PersistentAttribute attribute : entity.getPersistentType().getAllAttributes()) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java index 89b58e9115..54800e59a5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java @@ -91,24 +91,28 @@ public abstract class AbstractJavaBaseEmbeddedMapping<A extends Annotation> protected abstract JavaAttributeOverrideContainer.ParentAdapter buildAttributeOverrideContainerParentAdapter(); - // ********** target embeddable ********** - + // ***** target embeddable ***** + + public String getTargetEmbeddableName() { + return getPersistentAttribute().getSingleReferenceTargetTypeName(); + } + public Embeddable getTargetEmbeddable() { return this.targetEmbeddable; } - + protected void setTargetEmbeddable(Embeddable embeddable) { Embeddable old = this.targetEmbeddable; this.targetEmbeddable = embeddable; this.firePropertyChanged(TARGET_EMBEDDABLE_PROPERTY, old, embeddable); } - + protected Embeddable buildTargetEmbeddable() { - String typeName = this.getPersistentAttribute().getSingleReferenceTargetTypeName(); - return (typeName == null) ? null : this.getPersistenceUnit().getEmbeddable(typeName); + String typeName = getTargetEmbeddableName(); + return (typeName == null) ? null : getPersistenceUnit().getEmbeddable(typeName); } - - + + // ********** embedded mappings ********** @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddable.java index 58d0c14da5..c6a52a30e5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddable.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddable.java @@ -10,8 +10,11 @@ package org.eclipse.jpt.jpa.core.internal.context.java; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; +import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; import org.eclipse.jpt.jpa.core.MappingKeys; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.Query; +import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddable; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation; @@ -20,21 +23,17 @@ import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation; * Java embeddable type mapping */ public abstract class AbstractJavaEmbeddable - extends AbstractJavaTypeMapping<EmbeddableAnnotation> - implements JavaEmbeddable -{ + extends AbstractJavaTypeMapping<EmbeddableAnnotation> + implements JavaEmbeddable { + protected AbstractJavaEmbeddable(JavaPersistentType parent, EmbeddableAnnotation mappingAnnotation) { super(parent, mappingAnnotation); } - + public String getKey() { return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; } - - public JavaPersistentType getIdClass() { - return null; - } - + public boolean isMapped() { return true; } @@ -47,8 +46,23 @@ public abstract class AbstractJavaEmbeddable public boolean validatesAgainstDatabase() { return false; } - + public Iterable<Query> getQueries() { return EmptyIterable.instance(); } + + + // ***** (no) inheritance ***** + + public IdTypeMapping getSuperTypeMapping() { + return null; + } + + public Iterable<IdTypeMapping> getAncestors() { + return EmptyIterable.instance(); + } + + public Iterable<? extends TypeMapping> getInheritanceHierarchy() { + return new SingleElementIterable(this); + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddedIdMapping.java index a5ac1737c6..35a4a61083 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddedIdMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEmbeddedIdMapping.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.context.java; -import java.io.Serializable; import java.util.List; import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java index d13ae15969..b6850e27b8 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java @@ -37,6 +37,7 @@ import org.eclipse.jpt.jpa.core.context.BaseJoinColumn; import org.eclipse.jpt.jpa.core.context.DiscriminatorType; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.InheritanceType; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.JoinTable; @@ -45,7 +46,6 @@ import org.eclipse.jpt.jpa.core.context.NamedColumn; import org.eclipse.jpt.jpa.core.context.NamedDiscriminatorColumn; import org.eclipse.jpt.jpa.core.context.OverrideContainer; import org.eclipse.jpt.jpa.core.context.Override_; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.SecondaryTable; import org.eclipse.jpt.jpa.core.context.SpecifiedAssociationOverride; @@ -63,7 +63,6 @@ import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; import org.eclipse.jpt.jpa.core.context.java.JavaAttributeOverrideContainer; import org.eclipse.jpt.jpa.core.context.java.JavaEntity; import org.eclipse.jpt.jpa.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer; import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedDiscriminatorColumn; @@ -108,17 +107,15 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * Java entity */ public abstract class AbstractJavaEntity - extends AbstractJavaTypeMapping<EntityAnnotation> - implements JavaEntity2_0, JavaGeneratorContainer.Parent, JavaQueryContainer.Parent -{ + extends AbstractJavaIdTypeMapping<EntityAnnotation> + implements JavaEntity2_0, JavaGeneratorContainer.Parent, JavaQueryContainer.Parent { + protected String specifiedName; protected String defaultName; protected Entity rootEntity; protected final Vector<Entity> descendants = new Vector<Entity>(); - protected final JavaIdClassReference idClassReference; - protected final JavaSpecifiedTable table; protected boolean specifiedTableIsAllowed; protected boolean tableIsUndefined; @@ -154,7 +151,6 @@ public abstract class AbstractJavaEntity protected AbstractJavaEntity(JavaPersistentType parent, EntityAnnotation mappingAnnotation) { super(parent, mappingAnnotation); this.specifiedName = this.mappingAnnotation.getName(); - this.idClassReference = this.buildIdClassReference(); this.table = this.buildTable(); // start with the entity as the root - it will be recalculated in update() this.rootEntity = this; @@ -178,7 +174,6 @@ public abstract class AbstractJavaEntity public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); this.setSpecifiedName_(this.mappingAnnotation.getName()); - this.idClassReference.synchronizeWithResourceModel(); this.table.synchronizeWithResourceModel(); this.syncSpecifiedSecondaryTables(); this.syncSpecifiedPrimaryKeyJoinColumns(); @@ -190,45 +185,43 @@ public abstract class AbstractJavaEntity this.generatorContainer.synchronizeWithResourceModel(); this.queryContainer.synchronizeWithResourceModel(); } - + @Override public void update() { super.update(); - + this.setDefaultName(this.buildDefaultName()); - + // calculate root entity early - other things depend on it this.setRootEntity(this.buildRootEntity()); this.updateDescendants(); - - this.idClassReference.update(); - + this.setDefaultInheritanceStrategy(this.buildDefaultInheritanceStrategy()); - + this.table.update(); this.setSpecifiedTableIsAllowed(this.buildSpecifiedTableIsAllowed()); this.setTableIsUndefined(this.buildTableIsUndefined()); - + this.updateModels(this.getSecondaryTables()); - + this.updateDefaultPrimaryKeyJoinColumn(); this.updateModels(this.getPrimaryKeyJoinColumns()); - + this.discriminatorColumn.update(); this.setSpecifiedDiscriminatorColumnIsAllowed(this.buildSpecifiedDiscriminatorColumnIsAllowed()); this.setDiscriminatorColumnIsUndefined(this.buildDiscriminatorColumnIsUndefined()); - + this.setDefaultDiscriminatorValue(this.buildDefaultDiscriminatorValue()); this.setSpecifiedDiscriminatorValueIsAllowed(this.buildSpecifiedDiscriminatorValueIsAllowed()); this.setDiscriminatorValueIsUndefined(this.buildDiscriminatorValueIsUndefined()); - + this.attributeOverrideContainer.update(); this.associationOverrideContainer.update(); - + this.generatorContainer.update(); this.queryContainer.update(); } - + // ********** name ********** @@ -269,7 +262,6 @@ public abstract class AbstractJavaEntity // ********** root entity ********** - @Override public Entity getRootEntity() { return this.rootEntity; } @@ -308,21 +300,6 @@ public abstract class AbstractJavaEntity } - // ********** id class ********** - - public JavaIdClassReference getIdClassReference() { - return this.idClassReference; - } - - protected JavaIdClassReference buildIdClassReference() { - return new GenericJavaIdClassReference(this); - } - - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - // ********** table ********** public JavaSpecifiedTable getTable() { @@ -659,7 +636,6 @@ public abstract class AbstractJavaEntity // ********** inheritance strategy ********** - @Override public InheritanceType getInheritanceStrategy() { return (this.specifiedInheritanceStrategy != null) ? this.specifiedInheritanceStrategy : this.defaultInheritanceStrategy; } @@ -885,11 +861,6 @@ public abstract class AbstractJavaEntity return this.getJpaFactory().buildJavaAttributeOverrideContainer(new AttributeOverrideContainerParentAdapter()); } - public TypeMapping getOverridableTypeMapping() { - PersistentType superPersistentType = this.getPersistentType().getSuperPersistentType(); - return (superPersistentType == null) ? null : superPersistentType.getMapping(); - } - // ********** association override container ********** @@ -966,7 +937,7 @@ public abstract class AbstractJavaEntity // TODO eliminate duplicate tables? @Override public Iterable<Table> getAllAssociatedTables() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.ASSOCIATED_TABLES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.ASSOCIATED_TABLES_TRANSFORMER); } @Override @@ -1112,7 +1083,6 @@ public abstract class AbstractJavaEntity return null; } - @Override public boolean isRootEntity() { return this == this.rootEntity; } @@ -1246,8 +1216,7 @@ public abstract class AbstractJavaEntity @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - - this.validatePrimaryKey(messages, reporter); + this.validateTable(messages, reporter); for (JavaSpecifiedSecondaryTable secondaryTable : this.getSecondaryTables()) { secondaryTable.validate(messages, reporter); @@ -1261,7 +1230,6 @@ public abstract class AbstractJavaEntity this.attributeOverrideContainer.validate(messages, reporter); this.associationOverrideContainer.validate(messages, reporter); this.validateEntityName(messages); - this.idClassReference.validate(messages, reporter); } @Override @@ -1288,11 +1256,8 @@ public abstract class AbstractJavaEntity public TextRange getNameTextRange() { return this.getMappingAnnotation().getNameTextRange(); } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - this.buildPrimaryKeyValidator().validate(messages, reporter); - } - + + @Override protected JpaValidator buildPrimaryKeyValidator() { return new GenericEntityPrimaryKeyValidator(this); } @@ -1453,8 +1418,8 @@ public abstract class AbstractJavaEntity return AbstractJavaEntity.this.getValidationTextRange(); } - public TypeMapping getOverridableTypeMapping() { - return AbstractJavaEntity.this.getOverridableTypeMapping(); + public IdTypeMapping getOverridableTypeMapping() { + return AbstractJavaEntity.this.getSuperTypeMapping(); } public Iterable<String> getAllOverridableNames() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdTypeMapping.java new file mode 100644 index 0000000000..9c1beae46b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdTypeMapping.java @@ -0,0 +1,155 @@ +/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.context.java; +
+import java.util.List;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.jpa.core.context.AttributeMapping;
+import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdTypeMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.internal.context.JpaValidator;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+ +public abstract class AbstractJavaIdTypeMapping<A extends Annotation>
+ extends AbstractJavaTypeMapping<A>
+ implements JavaIdTypeMapping {
+
+ protected IdTypeMapping superTypeMapping;
+
+ protected final JavaIdClassReference idClassReference;
+
+
+ protected AbstractJavaIdTypeMapping(JavaPersistentType parent, A mappingAnnotation) {
+ super(parent, mappingAnnotation);
+ this.idClassReference = buildIdClassReference();
+ }
+
+
+ // ***** sync/update *****
+
+ @Override
+ public void synchronizeWithResourceModel() {
+ super.synchronizeWithResourceModel();
+ this.idClassReference.synchronizeWithResourceModel();
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ setSuperTypeMapping_(findSuperTypeMapping());
+ this.idClassReference.update();
+ }
+
+
+ // ***** primary key ****
+
+ public JavaIdClassReference getIdClassReference() {
+ return this.idClassReference;
+ }
+
+ protected JavaIdClassReference buildIdClassReference() {
+ return new GenericJavaIdClassReference(this);
+ }
+
+ public String getPrimaryKeyClassName() {
+ String idClassName = getIdClassReference().getFullyQualifiedIdClassName();
+ if (StringTools.isNotBlank(idClassName)) {
+ return idClassName;
+ }
+
+ AttributeMapping idMapping = getIdAttributeMapping();
+ if (idMapping != null) {
+ return idMapping.getPersistentAttribute().getTypeName();
+ }
+
+ return null;
+ }
+
+
+ // ***** inheritance *****
+
+ public IdTypeMapping getSuperTypeMapping() {
+ return this.superTypeMapping;
+ }
+
+ protected void setSuperTypeMapping_(IdTypeMapping typeMapping) {
+ IdTypeMapping old = this.superTypeMapping;
+ this.superTypeMapping = typeMapping;
+ firePropertyChanged(SUPER_TYPE_MAPPING_PROPERTY, old, typeMapping);
+ }
+
+ protected IdTypeMapping findSuperTypeMapping() {
+ return findSuperTypeMapping(getJavaResourceType());
+ }
+
+ protected IdTypeMapping findSuperTypeMapping(JavaResourceType resourceType) {
+ String thisTypeName = getJavaResourceType().getTypeBinding().getQualifiedName();
+ String superTypeName = resourceType.getSuperclassQualifiedName();
+ // short circuit if there is no super type or if the super type is this type
+ if (superTypeName == null
+ || ObjectTools.equals(thisTypeName, superTypeName)) {
+ return null;
+ }
+ IdTypeMapping typeMapping = findTypeMapping(superTypeName);
+ if (typeMapping != null) {
+ return typeMapping;
+ }
+ JavaResourceType superResourceType = findResourceType(superTypeName);
+ return (superResourceType == null) ? null : findSuperTypeMapping(superResourceType);
+ }
+
+ protected JavaResourceType findResourceType(String typeName) {
+ return (JavaResourceType) getJpaProject().getJavaResourceType(
+ typeName, JavaResourceAnnotatedElement.AstNodeType.TYPE);
+ }
+
+ protected IdTypeMapping findTypeMapping(String typeName) {
+ return getPersistenceUnit().getIdTypeMapping(typeName);
+ }
+
+ public Iterable<IdTypeMapping> getInheritanceHierarchy() {
+ return buildInheritanceHierarchy(this);
+ }
+
+ public Iterable<IdTypeMapping> getAncestors() {
+ return (this.superTypeMapping == null) ?
+ IterableTools.<IdTypeMapping>emptyIterable() :
+ buildInheritanceHierarchy(this.superTypeMapping);
+ }
+
+ protected Iterable<IdTypeMapping> buildInheritanceHierarchy(IdTypeMapping start) {
+ // using a chain iterable to traverse up the inheritance tree
+ return ObjectTools.chain(start, new SuperTypeMappingTransformer(this));
+ }
+
+
+ // ***** validation *****
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ super.validate(messages, reporter);
+ validatePrimaryKey(messages, reporter);
+ this.idClassReference.validate(messages, reporter);
+ }
+
+ protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) {
+ buildPrimaryKeyValidator().validate(messages, reporter);
+ }
+
+ protected abstract JpaValidator buildPrimaryKeyValidator();
+} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMappedSuperclass.java index 66bd5fc9a7..d2491d6635 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMappedSuperclass.java @@ -12,8 +12,9 @@ package org.eclipse.jpt.jpa.core.internal.context.java; import java.util.List; import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; import org.eclipse.jpt.jpa.core.MappingKeys; +import org.eclipse.jpt.jpa.core.context.Entity; +import org.eclipse.jpt.jpa.core.context.InheritanceType; import org.eclipse.jpt.jpa.core.context.Query; -import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer; @@ -27,105 +28,93 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * Java mapped superclass */ public abstract class AbstractJavaMappedSuperclass - extends AbstractJavaTypeMapping<MappedSuperclassAnnotation> - implements JavaMappedSuperclass, JavaQueryContainer.Parent -{ - protected final JavaIdClassReference idClassReference; + extends AbstractJavaIdTypeMapping<MappedSuperclassAnnotation> + implements JavaMappedSuperclass, JavaQueryContainer.Parent { + protected final JavaQueryContainer queryContainer; - - + + protected AbstractJavaMappedSuperclass(JavaPersistentType parent, MappedSuperclassAnnotation mappingAnnotation) { super(parent, mappingAnnotation); - this.idClassReference = this.buildIdClassReference(); this.queryContainer = this.buildQueryContainer(); } - - - // ********** synchronize/update ********** - + + + // ***** synchronize/update ***** + @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.idClassReference.synchronizeWithResourceModel(); this.queryContainer.synchronizeWithResourceModel(); } - + @Override public void update() { super.update(); - this.idClassReference.update(); this.queryContainer.update(); } - - - // ********** id class ********** - - public JavaIdClassReference getIdClassReference() { - return this.idClassReference; - } - - protected JavaIdClassReference buildIdClassReference() { - return new GenericJavaIdClassReference(this); - } - - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - + + // ********** query container ********** - + public JavaQueryContainer getQueryContainer() { return this.queryContainer; } - + protected JavaQueryContainer buildQueryContainer() { return this.getJpaFactory().buildJavaQueryContainer(this); } - + public JavaResourceMember getResourceAnnotatedElement() { return this.getJavaResourceType(); } - + public Iterable<Query> getQueries() { return this.queryContainer.getQueries(); } - - + + // ********** misc ********** - + public String getKey() { return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; } - + public boolean isMapped() { return true; } - + public boolean tableNameIsInvalid(String tableName) { return false; } - - - // ********** validation ********** - + + public Entity getRootEntity() { + return null; + } + + public boolean isRootEntity() { + return false; + } + + public InheritanceType getInheritanceStrategy() { + return null; + } + + + // ***** validation ***** + @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validatePrimaryKey(messages, reporter); - this.idClassReference.validate(messages, reporter); this.queryContainer.validate(messages, reporter); } - + @Override public boolean validatesAgainstDatabase() { return false; } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - this.buildPrimaryKeyValidator().validate(messages, reporter); - } - + + @Override protected JpaValidator buildPrimaryKeyValidator() { return new GenericMappedSuperclassPrimaryKeyValidator(this); // TODO - JPA 2.0 validation diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java index 81397701a8..9761487596 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java @@ -35,6 +35,7 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.context.PersistentType; +import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaManagedType; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedPersistentAttribute; @@ -56,11 +57,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * </ul> */ public abstract class AbstractJavaPersistentType - extends AbstractJavaManagedType<PersistentType.Parent> - implements JavaPersistentType -{ - protected PersistentType superPersistentType; - + extends AbstractJavaManagedType<PersistentType.Parent> + implements JavaPersistentType { + protected AccessType specifiedAccess; protected AccessType defaultAccess; // never null @@ -97,68 +96,21 @@ public abstract class AbstractJavaPersistentType @Override public void update() { super.update(); - this.setSuperPersistentType(this.buildSuperPersistentType()); this.setDefaultAccess(this.buildDefaultAccess()); this.mapping.update(); this.updateAttributes(); this.updateStructureChildren(); } - - - // ********** super persistent type ********** - + + + // ***** inheritance ***** + public PersistentType getSuperPersistentType() { - return this.superPersistentType; - } - - protected void setSuperPersistentType(PersistentType superPersistentType) { - PersistentType old = this.superPersistentType; - this.superPersistentType = superPersistentType; - this.firePropertyChanged(SUPER_PERSISTENT_TYPE_PROPERTY, old, superPersistentType); - } - - protected PersistentType buildSuperPersistentType() { - HashSet<JavaResourceType> visited = new HashSet<JavaResourceType>(); - visited.add(this.resourceType); - PersistentType spt = this.resolveSuperPersistentType(this.resourceType.getSuperclassQualifiedName(), visited); - if (spt == null) { - return null; - } - if (IterableTools.contains(spt.getInheritanceHierarchy(), this)) { - return null; // short-circuit in this case, we have circular inheritance - } - return spt.isMapped() ? spt : spt.getSuperPersistentType(); + TypeMapping superTypeMapping = this.mapping.getSuperTypeMapping(); + return (superTypeMapping == null) ? null : superTypeMapping.getPersistentType(); } - - /** - * The JPA spec allows non-persistent types in a persistent type's - * inheritance hierarchy. We check for a persistent type with the - * specified name in the persistence unit. If it is not found we use - * resource persistent type and look for <em>its</em> super type. - * <p> - * The <code>visited</code> collection is used to detect a cycle in the - * <em>resource</em> type inheritance hierarchy and prevent the resulting - * stack overflow. Any cycles in the <em>context</em> type inheritance - * hierarchy are handled in {@link #buildSuperPersistentType()}. - */ - protected PersistentType resolveSuperPersistentType(String typeName, Collection<JavaResourceType> visited) { - if (typeName == null) { - return null; - } - JavaResourceType rType = (JavaResourceType) this.getJpaProject().getJavaResourceType(typeName, JavaResourceAnnotatedElement.AstNodeType.TYPE); - if ((rType == null) || visited.contains(rType)) { - return null; - } - visited.add(rType); - PersistentType superType = this.resolvePersistentType(typeName); - return (superType != null) ? superType : this.resolveSuperPersistentType(rType.getSuperclassQualifiedName(), visited); // recurse - } - - protected PersistentType resolvePersistentType(String typeName) { - return this.getPersistenceUnit().getPersistentType(typeName); - } - - + + // ********** access annotation ********** protected AccessAnnotation2_0 getAccessAnnotation() { @@ -242,8 +194,8 @@ public abstract class AbstractJavaPersistentType return accessType; } - if (this.superPersistentType != null) { - accessType = this.superPersistentType.getAccess(); + if (getSuperPersistentType() != null) { + accessType = getSuperPersistentType().getAccess(); if (accessType != null) { return accessType; } @@ -428,7 +380,7 @@ public abstract class AbstractJavaPersistentType return stream.hasNext() ? null : attribute; } // recurse - return (this.superPersistentType == null) ? null : this.superPersistentType.resolveAttribute(attributeName); + return (getSuperPersistentType() == null) ? null : getSuperPersistentType().resolveAttribute(attributeName); } protected Iterable<String> convertToNames(Iterable<? extends PersistentAttribute> attrs) { @@ -700,35 +652,27 @@ public abstract class AbstractJavaPersistentType // ********** inheritance ********** - + public Iterable<PersistentType> getInheritanceHierarchy() { - return this.buildInheritanceHierarchy(this); + return IterableTools.insert(this, getAncestors()); } - + public Iterable<PersistentType> getAncestors() { - return (this.superPersistentType == null) ? - IterableTools.<PersistentType>emptyIterable() : - this.buildInheritanceHierarchy(this.superPersistentType); - } - - protected Iterable<PersistentType> buildInheritanceHierarchy(PersistentType start) { - // using a chain iterable to traverse up the inheritance tree - return ObjectTools.chain(start, SUPER_PERSISTENT_TYPE_TRANSFORMER); + return IterableTools.transform(getMapping().getAncestors(), TypeMapping.PERSISTENT_TYPE_TRANSFORMER); } - + protected Iterable<JavaResourceType> getResourceInheritanceHierarchy() { return (this.resourceType == null) ? IterableTools.<JavaResourceType>emptyIterable() : ObjectTools.chain(this.resourceType, new SuperJavaResourceTypeTransformer()); } - - + /** * Transform a Java resource type into its super Java resource type. */ protected class SuperJavaResourceTypeTransformer - extends TransformerAdapter<JavaResourceType, JavaResourceType> - { + extends TransformerAdapter<JavaResourceType, JavaResourceType> { + // keep track of visited resource types to prevent cyclical inheritance private final HashSet<JavaResourceType> visitedResourceTypes = new HashSet<JavaResourceType>(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaTypeMapping.java index e576b50285..23cb8ad432 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaTypeMapping.java @@ -17,15 +17,12 @@ import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; -import org.eclipse.jpt.jpa.core.context.InheritanceType; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.SpecifiedColumn; import org.eclipse.jpt.jpa.core.context.SpecifiedRelationship; import org.eclipse.jpt.jpa.core.context.Table; -import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping; @@ -40,19 +37,19 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * Java type mapping */ public abstract class AbstractJavaTypeMapping<A extends Annotation> - extends AbstractJavaContextModel<JavaPersistentType> - implements JavaTypeMapping -{ + extends AbstractJavaContextModel<JavaPersistentType> + implements JavaTypeMapping { + // this can be null for a "null" type mapping protected final A mappingAnnotation; - - + + protected AbstractJavaTypeMapping(JavaPersistentType parent, A mappingAnnotation) { super(parent); this.mappingAnnotation = mappingAnnotation; } - - + + // ********** misc ********** public JavaPersistentType getPersistentType() { @@ -110,62 +107,24 @@ public abstract class AbstractJavaTypeMapping<A extends Annotation> public org.eclipse.jpt.jpa.db.Table resolveDbTable(String tableName) { return null; } - - - // ********** inheritance ********** - - public TypeMapping getSuperTypeMapping() { - PersistentType superPersistentType = this.getPersistentType().getSuperPersistentType(); - return (superPersistentType == null) ? null : superPersistentType.getMapping(); - } - - public Iterable<TypeMapping> getInheritanceHierarchy() { - return IterableTools.transform(this.getPersistentType().getInheritanceHierarchy(), PersistentType.MAPPING_TRANSFORMER); - } - - /** - * Return the type mapping's "persistence" ancestors, - * <em>excluding</em> the type mapping itself. - * The returned iterator will return elements infinitely if the hierarchy - * has a loop. - */ - protected Iterable<TypeMapping> getAncestors() { - return IterableTools.transform(this.getPersistentType().getAncestors(), PersistentType.MAPPING_TRANSFORMER); - } - - public InheritanceType getInheritanceStrategy() { - return null; - } - - public boolean isRootEntity() { - return false; - } - - public Entity getRootEntity() { - return null; - } - - + + // ********** attribute mappings ********** public Iterable<JavaAttributeMapping> getAttributeMappings() { - return IterableTools.downCast(IterableTools.transform(this.getPersistentType().getAttributes(), PersistentAttribute.MAPPING_TRANSFORMER)); + return IterableTools.downCast(IterableTools.transform(getPersistentType().getAttributes(), PersistentAttribute.MAPPING_TRANSFORMER)); } public Iterable<JavaAttributeMapping> getAttributeMappings(String mappingKey) { - return IterableTools.filter(this.getAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); + return IterableTools.filter(getAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); } public Iterable<AttributeMapping> getAllAttributeMappings() { - return IterableTools.children(this.getNonNullInheritanceHierarchy(), TypeMappingTools.ATTRIBUTE_MAPPINGS_TRANSFORMER); + return IterableTools.transform(getPersistentType().getAllAttributes(), PersistentAttribute.MAPPING_TRANSFORMER); } - - protected Iterable<TypeMapping> getNonNullInheritanceHierarchy() { - return IterableTools.removeNulls(this.getInheritanceHierarchy()); - } - + public Iterable<AttributeMapping> getAllAttributeMappings(final String mappingKey) { - return IterableTools.filter(this.getAllAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); + return IterableTools.filter(getAllAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); } public boolean attributeMappingKeyAllowed(String attributeMappingKey) { @@ -173,18 +132,30 @@ public abstract class AbstractJavaTypeMapping<A extends Annotation> } public Iterable<AttributeMapping> getNonTransientAttributeMappings() { - return new FilteringIterable<AttributeMapping>(this.getAllAttributeMappings(), AttributeMapping.IS_NOT_TRANSIENT); + return new FilteringIterable<AttributeMapping>(getAllAttributeMappings(), AttributeMapping.IS_NOT_TRANSIENT); } - - + + public Iterable<AttributeMapping> getIdAttributeMappings() { + return IterableTools.filter(getAllAttributeMappings(), new IdTypeMapping.MappingIsIdMapping()); + } + + public AttributeMapping getIdAttributeMapping() { + Iterable<AttributeMapping> idMappings = getIdAttributeMappings(); + if (IterableTools.size(idMappings) == 1) { + return IterableTools.get(idMappings, 0); + } + return null; + } + + // ********** attribute overrides ********** public Iterable<String> getOverridableAttributeNames() { - return IterableTools.children(this.getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ATTRIBUTE_MAPPING_NAMES_TRANSFORMER); + return IterableTools.children(getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ATTRIBUTE_MAPPING_NAMES_TRANSFORMER); } public Iterable<String> getAllOverridableAttributeNames() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ATTRIBUTE_NAMES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ATTRIBUTE_NAMES_TRANSFORMER); } public SpecifiedColumn resolveOverriddenColumn(String attributeName) { @@ -199,17 +170,17 @@ public abstract class AbstractJavaTypeMapping<A extends Annotation> // ********** association overrides ********** - + public Iterable<String> getOverridableAssociationNames() { - return IterableTools.children(this.getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ASSOCIATION_MAPPING_NAMES_TRANSFORMER); + return IterableTools.children(getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ASSOCIATION_MAPPING_NAMES_TRANSFORMER); } - + public Iterable<String> getAllOverridableAssociationNames() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ASSOCIATION_NAMES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ASSOCIATION_NAMES_TRANSFORMER); } - + public SpecifiedRelationship resolveOverriddenRelationship(String attributeName) { - for (AttributeMapping attributeMapping : this.getAttributeMappings()) { + for (AttributeMapping attributeMapping : getAttributeMappings()) { SpecifiedRelationship relationship = attributeMapping.resolveOverriddenRelationship(attributeName); if (relationship != null) { return relationship; @@ -217,15 +188,15 @@ public abstract class AbstractJavaTypeMapping<A extends Annotation> } return null; } - - + + // ********** generators ********** - + public Iterable<Generator> getGenerators() { - return IterableTools.children(this.getAttributeMappings(), AttributeMapping.GENERATORS_TRANSFORMER); + return IterableTools.children(getAttributeMappings(), AttributeMapping.GENERATORS_TRANSFORMER); } - - + + // ********** validation ********** @Override 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 452e85cf63..4ad8913d7d 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 @@ -16,6 +16,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.jpa.core.context.AccessType; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; @@ -29,18 +30,24 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * Java ID class reference */ public class GenericJavaIdClassReference - extends AbstractJavaContextModel<JavaTypeMapping> - implements JavaIdClassReference, PersistentType.Parent -{ + extends AbstractJavaContextModel<JavaTypeMapping> + implements JavaIdClassReference, PersistentType.Parent { + + protected String specifiedIdClassName; + + protected String defaultIdClassName; + protected String idClassName; + protected String fullyQualifiedIdClassName; + // the ref holds the type directly because the ref is the type's parent protected JavaPersistentType idClass; - - + + public GenericJavaIdClassReference(JavaTypeMapping parent) { super(parent); - this.idClassName = this.buildIdClassName(); + this.specifiedIdClassName = buildSpecifiedIdClassName(); // 'idClass' is resolved in the update } @@ -50,55 +57,78 @@ public class GenericJavaIdClassReference @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.setIdClassName_(this.buildIdClassName()); + setSpecifiedIdClassName_(buildSpecifiedIdClassName()); if (this.idClass != null) { this.idClass.synchronizeWithResourceModel(); } } - + @Override public void update() { super.update(); - this.setFullyQualifiedIdClassName(this.buildFullyQualifiedIdClassName()); - this.updateIdClass(); + setDefaultIdClassName_(buildDefaultIdClassName()); + setIdClassName_(buildIdClassName()); + setFullyQualifiedIdClassName(buildFullyQualifiedIdClassName()); + updateIdClass(); } - // ********** id class name ********** - + // ***** id class name ***** + public String getIdClassName() { return this.getSpecifiedIdClassName(); } - + + protected void setIdClassName_(String name) { + String old = this.idClassName; + this.idClassName = name; + firePropertyChanged(ID_CLASS_NAME_PROPERTY, old, name); + } + + protected String buildIdClassName() { + return (this.specifiedIdClassName != null) ? this.specifiedIdClassName : this.defaultIdClassName; + } + public String getSpecifiedIdClassName() { - return this.idClassName; + return this.specifiedIdClassName; } - + public void setSpecifiedIdClassName(String name) { - if (ObjectTools.notEquals(name, this.idClassName)) { - this.getIdClassAnnotationForUpdate().setValue(name); - this.removeIdClassAnnotationIfUnset(); - this.setIdClassName_(name); + if (ObjectTools.notEquals(name, this.specifiedIdClassName)) { + getIdClassAnnotationForUpdate().setValue(name); + removeIdClassAnnotationIfUnset(); + setSpecifiedIdClassName_(name); } } - - protected void setIdClassName_(String name) { - String old = this.idClassName; - this.idClassName = name; + + protected void setSpecifiedIdClassName_(String name) { + String old = this.specifiedIdClassName; + this.specifiedIdClassName = name; this.firePropertyChanged(SPECIFIED_ID_CLASS_NAME_PROPERTY, old, name); } - - protected String buildIdClassName() { + + protected String buildSpecifiedIdClassName() { IdClassAnnotation annotation = this.getIdClassAnnotation(); return (annotation == null) ? null : annotation.getValue(); } - + public String getDefaultIdClassName() { - return null; + return this.defaultIdClassName; } - + + protected void setDefaultIdClassName_(String name) { + String old = this.defaultIdClassName; + this.defaultIdClassName = name; + this.firePropertyChanged(DEFAULT_ID_CLASS_NAME_PROPERTY, old, name); + } + + protected String buildDefaultIdClassName() { + IdTypeMapping superType = getParent().getSuperTypeMapping(); + return (superType == null) ? null : superType.getIdClassReference().getFullyQualifiedIdClassName(); + } + public boolean isSpecified() { - return this.idClassName != null; + return this.specifiedIdClassName != null; } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/JavaNullTypeMapping.java index 6b70a8ff26..3334b14c9b 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/JavaNullTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/JavaNullTypeMapping.java @@ -13,8 +13,11 @@ import java.util.List; import org.eclipse.jpt.common.core.resource.java.Annotation; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; +import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; import org.eclipse.jpt.jpa.core.MappingKeys; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.Query; +import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -24,19 +27,16 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * Java null type mapping */ public class JavaNullTypeMapping - extends AbstractJavaTypeMapping<Annotation> -{ + extends AbstractJavaTypeMapping<Annotation> { + public JavaNullTypeMapping(JavaPersistentType parent) { super(parent, null); } - + + public String getKey() { return MappingKeys.NULL_TYPE_MAPPING_KEY; } - - public JavaPersistentType getIdClass() { - return null; - } public boolean isMapped() { return false; @@ -49,10 +49,22 @@ public class JavaNullTypeMapping public Iterable<Query> getQueries() { return EmptyIterable.instance(); } - - + + public IdTypeMapping getSuperTypeMapping() { + return null; + } + + public Iterable<IdTypeMapping> getAncestors() { + return EmptyIterable.instance(); + } + + public Iterable<? extends TypeMapping> getInheritanceHierarchy() { + return new SingleElementIterable(this); + } + + // ********** validation ********** - + /** * We added this message here because the most likely solution is to add * an annotation to the .java file. @@ -77,7 +89,7 @@ public class JavaNullTypeMapping public boolean validatesAgainstDatabase() { return false; } - + @Override public TextRange getValidationTextRange() { return this.getPersistentType().getValidationTextRange(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java index 1bbbe2c7f7..c02ec88280 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java @@ -24,7 +24,6 @@ import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.JpaContextModel; import org.eclipse.jpt.jpa.core.context.OverrideContainer; import org.eclipse.jpt.jpa.core.context.Override_; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.SpecifiedAttributeOverride; import org.eclipse.jpt.jpa.core.context.SpecifiedColumn; import org.eclipse.jpt.jpa.core.context.TableColumn; @@ -93,27 +92,27 @@ public abstract class AbstractOrmBaseEmbeddedMapping<X extends AbstractXmlEmbedd // ********** target embeddable ********** - + + public String getTargetEmbeddableName() { + return getFullyQualifiedAttributeType(); + } + public Embeddable getTargetEmbeddable() { return this.targetEmbeddable; } - + protected void setTargetEmbeddable(Embeddable embeddable) { Embeddable old = this.targetEmbeddable; this.targetEmbeddable = embeddable; this.firePropertyChanged(TARGET_EMBEDDABLE_PROPERTY, old, embeddable); } - + protected Embeddable buildTargetEmbeddable() { - TypeMapping typeMapping = this.getResolvedTargetTypeMapping(); - return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; + String typeName = getTargetEmbeddableName(); + return (typeName == null) ? null : getPersistenceUnit().getEmbeddable(typeName); } - - protected TypeMapping getResolvedTargetTypeMapping() { - PersistentType resolvedTargetType = this.getResolvedAttributeType(); - return (resolvedTargetType == null) ? null : resolvedTargetType.getMapping(); - } - + + // ********** embedded mappings ********** @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEmbeddable.java index d566bcaefe..d0eb056dc8 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEmbeddable.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEmbeddable.java @@ -10,9 +10,12 @@ package org.eclipse.jpt.jpa.core.internal.context.orm;
import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable;
import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.context.Table;
+import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaEmbeddable;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmEmbeddable;
@@ -98,8 +101,23 @@ public abstract class AbstractOrmEmbeddable<X extends XmlEmbeddable> public Iterable<Query> getQueries() {
return EmptyIterable.instance();
}
-
-
+
+
+ // ***** (no) inheritance *****
+
+ public IdTypeMapping getSuperTypeMapping() {
+ return null;
+ }
+
+ public Iterable<IdTypeMapping> getAncestors() {
+ return EmptyIterable.instance();
+ }
+
+ public Iterable<? extends TypeMapping> getInheritanceHierarchy() {
+ return new SingleElementIterable(this);
+ }
+
+
// ********** validation **********
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java index 7d6f1753e6..79c68fec83 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java @@ -48,7 +48,6 @@ import org.eclipse.jpt.jpa.core.context.NamedColumn; import org.eclipse.jpt.jpa.core.context.NamedDiscriminatorColumn; import org.eclipse.jpt.jpa.core.context.OverrideContainer; import org.eclipse.jpt.jpa.core.context.Override_; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.PrimaryKeyJoinColumn; import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.Relationship; @@ -65,7 +64,6 @@ import org.eclipse.jpt.jpa.core.context.Table; import org.eclipse.jpt.jpa.core.context.TableColumn; import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaEntity; -import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaOverrideContainer; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedPrimaryKeyJoinColumn; @@ -75,7 +73,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmAssociationOverrideContainer; import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeOverrideContainer; import org.eclipse.jpt.jpa.core.context.orm.OrmEntity; import org.eclipse.jpt.jpa.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.jpa.core.context.orm.OrmIdClassReference; import org.eclipse.jpt.jpa.core.context.orm.OrmOverrideContainer; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer; @@ -113,7 +110,6 @@ import org.eclipse.jpt.jpa.core.resource.orm.XmlAttributeOverride; import org.eclipse.jpt.jpa.core.resource.orm.XmlDiscriminatorColumn; import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity; import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.jpa.core.resource.orm.XmlIdClassContainer; import org.eclipse.jpt.jpa.core.resource.orm.XmlPrimaryKeyJoinColumn; import org.eclipse.jpt.jpa.core.resource.orm.XmlSecondaryTable; import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; @@ -126,17 +122,15 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * <code>orm.xml</code> entity */ public abstract class AbstractOrmEntity<X extends XmlEntity> - extends AbstractOrmTypeMapping<X> - implements OrmEntity2_0 -{ + extends AbstractOrmIdTypeMapping<X> + implements OrmEntity2_0 { + protected String specifiedName; protected String defaultName; protected Entity rootEntity; protected final Vector<Entity> descendants = new Vector<Entity>(); - protected final OrmIdClassReference idClassReference; - protected final OrmSpecifiedTable table; protected boolean specifiedTableIsAllowed; protected boolean tableIsUndefined; @@ -179,7 +173,6 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> protected AbstractOrmEntity(OrmPersistentType parent, X xmlEntity) { super(parent, xmlEntity); this.specifiedName = xmlEntity.getName(); - this.idClassReference = this.buildIdClassReference(); this.table = this.buildTable(); // start with the entity as the root - it will be recalculated in update() this.rootEntity = this; @@ -198,72 +191,68 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> } - // ********** synchronize/update ********** - + // ***** sync/update ***** + @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - + this.setSpecifiedName_(this.xmlTypeMapping.getName()); - - this.idClassReference.synchronizeWithResourceModel(); - + this.table.synchronizeWithResourceModel(); - + this.syncSpecifiedSecondaryTables(); - + this.syncSpecifiedPrimaryKeyJoinColumns(); - + this.setSpecifiedInheritanceStrategy_(this.buildSpecifiedInheritanceStrategy()); this.setSpecifiedDiscriminatorValue_(this.xmlTypeMapping.getDiscriminatorValue()); this.discriminatorColumn.synchronizeWithResourceModel(); - + this.attributeOverrideContainer.synchronizeWithResourceModel(); this.associationOverrideContainer.synchronizeWithResourceModel(); - + this.generatorContainer.synchronizeWithResourceModel(); this.queryContainer.synchronizeWithResourceModel(); } - + @Override public void update() { super.update(); - + this.setDefaultName(this.buildDefaultName()); - + // calculate root entity early - other things depend on it this.setRootEntity(this.buildRootEntity()); this.updateDescendants(); - - this.idClassReference.update(); - + this.setDefaultInheritanceStrategy(this.buildDefaultInheritanceStrategy()); - + this.table.update(); this.setSpecifiedTableIsAllowed(this.buildSpecifiedTableIsAllowed()); this.setTableIsUndefined(this.buildTableIsUndefined()); - + this.updateVirtualSecondaryTables(); this.updateModels(this.getSecondaryTables()); - + this.updateDefaultPrimaryKeyJoinColumns(); this.updateModels(this.getPrimaryKeyJoinColumns()); - + this.discriminatorColumn.update(); this.setSpecifiedDiscriminatorColumnIsAllowed(this.buildSpecifiedDiscriminatorColumnIsAllowed()); this.setDiscriminatorColumnIsUndefined(this.buildDiscriminatorColumnIsUndefined()); - + this.setDefaultDiscriminatorValue(this.buildDefaultDiscriminatorValue()); this.setSpecifiedDiscriminatorValueIsAllowed(this.buildSpecifiedDiscriminatorValueIsAllowed()); this.setDiscriminatorValueIsUndefined(this.buildDiscriminatorValueIsUndefined()); - + this.attributeOverrideContainer.update(); this.associationOverrideContainer.update(); - + this.generatorContainer.update(); this.queryContainer.update(); } - + // ********** name ********** @@ -359,30 +348,6 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> } - // ********** id class ********** - - public OrmIdClassReference getIdClassReference() { - return this.idClassReference; - } - - protected OrmIdClassReference buildIdClassReference() { - return new GenericOrmIdClassReference(this); - } - - public XmlIdClassContainer getXmlIdClassContainer() { - return this.getXmlTypeMapping(); - } - - public JavaIdClassReference getJavaIdClassReferenceForDefaults() { - JavaEntity javaEntity = this.getJavaTypeMappingForDefaults(); - return (javaEntity == null) ? null : javaEntity.getIdClassReference(); - } - - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - // ********** table ********** public OrmSpecifiedTable getTable() { @@ -1276,8 +1241,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> } protected TypeMapping getOverridableTypeMapping() { - PersistentType superPersistentType = this.getPersistentType().getSuperPersistentType(); - return (superPersistentType == null) ? null : superPersistentType.getMapping(); + return getSuperTypeMapping(); } protected Column resolveOverriddenColumnForAttributeOverride(String attributeName) { @@ -1381,7 +1345,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> // TODO eliminate duplicate tables? public Iterable<Table> getAllAssociatedTables() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.ASSOCIATED_TABLES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.ASSOCIATED_TABLES_TRANSFORMER); } public Iterable<String> getAllAssociatedTableNames() { @@ -1704,7 +1668,6 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validatePrimaryKey(messages, reporter); this.validateTable(messages, reporter); for (OrmSpecifiedSecondaryTable secondaryTable : this.getSpecifiedSecondaryTables()) { secondaryTable.validate(messages, reporter); @@ -1740,11 +1703,8 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> public TextRange getNameTextRange() { return this.getXmlTypeMapping().getNameTextRange(); } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - this.buildPrimaryKeyValidator().validate(messages, reporter); - } - + + @Override protected JpaValidator buildPrimaryKeyValidator() { return new GenericEntityPrimaryKeyValidator(this); // TODO - JPA 2.0 validation diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmIdTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmIdTypeMapping.java new file mode 100644 index 0000000000..140d0cc35d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmIdTypeMapping.java @@ -0,0 +1,208 @@ +/*******************************************************************************
+ * Copyright (c) 2013 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.jpa.core.internal.context.orm; +
+import java.util.List;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
+import org.eclipse.jpt.jpa.core.context.AttributeMapping;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
+import org.eclipse.jpt.jpa.core.context.InheritanceType;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference;
+import org.eclipse.jpt.jpa.core.context.java.JavaIdTypeMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
+import org.eclipse.jpt.jpa.core.context.orm.OrmIdClassReference;
+import org.eclipse.jpt.jpa.core.context.orm.OrmIdTypeMapping;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.internal.context.JpaValidator;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlIdClassContainer;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlIdTypeMapping;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+ +public abstract class AbstractOrmIdTypeMapping<X extends XmlIdTypeMapping>
+ extends AbstractOrmTypeMapping<X>
+ implements OrmIdTypeMapping {
+
+ protected final OrmIdClassReference idClassReference;
+
+ protected IdTypeMapping superTypeMapping;
+
+ protected AbstractOrmIdTypeMapping(OrmPersistentType parent, X xmlTypeMapping) {
+ super(parent, xmlTypeMapping);
+ this.idClassReference = buildIdClassReference();
+ }
+
+
+ // ***** sync/update *****
+
+ @Override
+ public void synchronizeWithResourceModel() {
+ super.synchronizeWithResourceModel();
+ this.idClassReference.synchronizeWithResourceModel();
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.idClassReference.update();
+ setSuperTypeMapping_(findSuperTypeMapping());
+ }
+
+
+ // ***** java *****
+
+ @Override
+ public JavaTypeMapping getJavaTypeMapping() {
+ return (JavaIdTypeMapping) super.getJavaTypeMapping();
+ }
+
+ @Override
+ public JavaIdTypeMapping getJavaTypeMappingForDefaults() {
+ return (JavaIdTypeMapping) super.getJavaTypeMappingForDefaults();
+ }
+
+
+ // ***** primary key *****
+
+ public OrmIdClassReference getIdClassReference() {
+ return this.idClassReference;
+ }
+
+ protected OrmIdClassReference buildIdClassReference() {
+ return new GenericOrmIdClassReference(this);
+ }
+
+ public XmlIdClassContainer getXmlIdClassContainer() {
+ return getXmlTypeMapping();
+ }
+
+ public JavaIdClassReference getJavaIdClassReferenceForDefaults() {
+ JavaIdTypeMapping javaTypeMapping = getJavaTypeMappingForDefaults();
+ return (javaTypeMapping == null) ? null : javaTypeMapping.getIdClassReference();
+ }
+
+ public String getPrimaryKeyClassName() {
+ String idClassName = getIdClassReference().getFullyQualifiedIdClassName();
+ if (StringTools.isNotBlank(idClassName)) {
+ return idClassName;
+ }
+
+ AttributeMapping idMapping = getIdAttributeMapping();
+ if (idMapping != null) {
+ return idMapping.getPersistentAttribute().getTypeName();
+ }
+
+ return null;
+ }
+
+
+ // ***** inheritance *****
+
+ public IdTypeMapping getSuperTypeMapping() {
+ return this.superTypeMapping;
+ }
+
+ protected void setSuperTypeMapping_(IdTypeMapping typeMapping) {
+ IdTypeMapping old = this.superTypeMapping;
+ this.superTypeMapping = typeMapping;
+ firePropertyChanged(SUPER_TYPE_MAPPING_PROPERTY, old, typeMapping);
+ }
+
+ protected IdTypeMapping findSuperTypeMapping() {
+ return findSuperTypeMapping(getFullyQualifiedParentClass());
+ }
+
+ protected IdTypeMapping findSuperTypeMapping(String superTypeName) {
+ String thisTypeName = getPersistentType().getName();
+ // short circuit if there is no super type or if the super type is this type
+ if (superTypeName == null
+ || ObjectTools.equals(thisTypeName, superTypeName)) {
+ return null;
+ }
+ IdTypeMapping typeMapping = findTypeMapping(superTypeName);
+ if (typeMapping != null) {
+ return typeMapping;
+ }
+ JavaResourceType superResourceType = findResourceType(superTypeName);
+ return (superResourceType == null) ? null : findSuperTypeMapping(superResourceType.getSuperclassQualifiedName());
+ }
+
+ protected JavaResourceType findResourceType(String typeName) {
+ return (JavaResourceType) getJpaProject().getJavaResourceType(
+ typeName, JavaResourceAnnotatedElement.AstNodeType.TYPE);
+ }
+
+ protected IdTypeMapping findTypeMapping(String typeName) {
+ return getPersistenceUnit().getIdTypeMapping(typeName);
+ }
+
+ public Iterable<IdTypeMapping> getInheritanceHierarchy() {
+ return buildInheritanceHierarchy(this);
+ }
+
+ public Iterable<IdTypeMapping> getAncestors() {
+ return (this.superTypeMapping == null) ?
+ IterableTools.<IdTypeMapping>emptyIterable() :
+ buildInheritanceHierarchy(this.superTypeMapping);
+ }
+
+ protected Iterable<IdTypeMapping> buildInheritanceHierarchy(IdTypeMapping start) {
+ // using a chain iterable to traverse up the inheritance tree
+ return ObjectTools.chain(start, new SuperTypeMappingTransformer(this));
+ }
+
+ public InheritanceType getInheritanceStrategy() {
+ return null;
+ }
+
+ public boolean isRootEntity() {
+ return false;
+ }
+
+ public Entity getRootEntity() {
+ return null;
+ }
+
+
+ // ***** content assist *****
+
+ @Override
+ public Iterable<String> getCompletionProposals(int pos) {
+ Iterable<String> result = super.getCompletionProposals(pos);
+ if (result != null) {
+ return result;
+ }
+ result = this.idClassReference.getCompletionProposals(pos);
+ if (result != null) {
+ return result;
+ }
+ return null;
+ }
+
+
+ // ***** validation *****
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ super.validate(messages, reporter);
+ validatePrimaryKey(messages, reporter);
+ }
+
+ protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) {
+ this.buildPrimaryKeyValidator().validate(messages, reporter);
+ }
+
+ protected abstract JpaValidator buildPrimaryKeyValidator();
+} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMappedSuperclass.java index 70466226c9..391fb992b3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMappedSuperclass.java @@ -9,7 +9,6 @@ ******************************************************************************/ 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.utility.internal.iterable.EmptyIterable; @@ -17,140 +16,91 @@ import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jpa.core.MappingKeys; import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.Table; -import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmIdClassReference; import org.eclipse.jpt.jpa.core.context.orm.OrmMappedSuperclass; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; import org.eclipse.jpt.jpa.core.internal.context.JpaValidator; import org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator; import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.jpa.core.resource.orm.XmlIdClassContainer; import org.eclipse.jpt.jpa.core.resource.orm.XmlMappedSuperclass; import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * <code>orm.xml</code> mapped superclass */ public abstract class AbstractOrmMappedSuperclass<X extends XmlMappedSuperclass> - extends AbstractOrmTypeMapping<X> - implements OrmMappedSuperclass -{ - protected final OrmIdClassReference idClassReference; - - + extends AbstractOrmIdTypeMapping<X> + implements OrmMappedSuperclass { + protected AbstractOrmMappedSuperclass(OrmPersistentType parent, X xmlMappedSuperclass) { super(parent, xmlMappedSuperclass); - this.idClassReference = this.buildIdClassReference(); } - - - // ********** synchronize/update ********** - - @Override - public void synchronizeWithResourceModel() { - super.synchronizeWithResourceModel(); - this.idClassReference.synchronizeWithResourceModel(); - } - - @Override - public void update() { - super.update(); - this.idClassReference.update(); - } - - + + // ********** key ********** - + public String getKey() { return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; } - - - // ********** id class ********** - - public OrmIdClassReference getIdClassReference() { - return this.idClassReference; - } - - protected OrmIdClassReference buildIdClassReference() { - return new GenericOrmIdClassReference(this); - } - - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - public XmlIdClassContainer getXmlIdClassContainer() { - return this.getXmlTypeMapping(); - } - - public JavaIdClassReference getJavaIdClassReferenceForDefaults() { - JavaMappedSuperclass javaMappedSuperclass = this.getJavaTypeMappingForDefaults(); - return (javaMappedSuperclass == null) ? null : javaMappedSuperclass.getIdClassReference(); - } - - + + // ********** entity mappings ********** - + public int getXmlSequence() { return 0; } - + public void addXmlTypeMappingTo(XmlEntityMappings entityMappings) { entityMappings.getMappedSuperclasses().add(this.xmlTypeMapping); } - + public void removeXmlTypeMappingFrom(XmlEntityMappings entityMappings) { entityMappings.getMappedSuperclasses().remove(this.xmlTypeMapping); } - - + + // ********** Java ********** - + @Override public JavaMappedSuperclass getJavaTypeMapping() { return (JavaMappedSuperclass) super.getJavaTypeMapping(); } - + @Override public JavaMappedSuperclass getJavaTypeMappingForDefaults() { return (JavaMappedSuperclass) super.getJavaTypeMappingForDefaults(); } - - + + // ********** tables ********** - + public Iterable<Table> getAssociatedTables() { return EmptyIterable.instance(); } - + public Iterable<Table> getAllAssociatedTables() { return EmptyIterable.instance(); } - + public Iterable<String> getAllAssociatedTableNames() { return EmptyIterable.instance(); } - + public boolean tableNameIsInvalid(String tableName) { return false; } - - + + // ********** queries ********** - + public Iterable<Query> getQueries() { // the orm.xml mapped superclass does NOT have queries(!) return EmptyIterable.instance(); } - - + + // ********** refactoring ********** - + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) { @@ -159,11 +109,11 @@ public abstract class AbstractOrmMappedSuperclass<X extends XmlMappedSuperclass> this.createIdClassReplaceTypeEdits(originalType, newName) ); } - + protected Iterable<ReplaceEdit> createIdClassReplaceTypeEdits(IType originalType, String newName) { return this.idClassReference.createRenameTypeEdits(originalType, newName); } - + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) { @@ -172,11 +122,11 @@ public abstract class AbstractOrmMappedSuperclass<X extends XmlMappedSuperclass> this.createIdClassMoveTypeEdits(originalType, newPackage) ); } - + protected Iterable<ReplaceEdit> createIdClassMoveTypeEdits(IType originalType, IPackageFragment newPackage) { return this.idClassReference.createMoveTypeEdits(originalType, newPackage); } - + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) { @@ -185,47 +135,22 @@ public abstract class AbstractOrmMappedSuperclass<X extends XmlMappedSuperclass> this.createIdClassRenamePackageEdits(originalPackage, newName) ); } - + protected Iterable<ReplaceEdit> createIdClassRenamePackageEdits(IPackageFragment originalPackage, String newName) { return this.idClassReference.createRenamePackageEdits(originalPackage, newName); } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validatePrimaryKey(messages, reporter); - this.idClassReference.validate(messages, reporter); - } - + + + // ***** validation ***** + @Override public boolean validatesAgainstDatabase() { return false; } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - this.buildPrimaryKeyValidator().validate(messages, reporter); - } - + + @Override protected JpaValidator buildPrimaryKeyValidator() { return new GenericMappedSuperclassPrimaryKeyValidator(this); // TODO - JPA 2.0 validation } - - // ********** completion proposals ********** - - @Override - public Iterable<String> getCompletionProposals(int pos) { - Iterable<String> result = super.getCompletionProposals(pos); - if (result != null) { - return result; - } - result = this.idClassReference.getCompletionProposals(pos); - if (result != null) { - return result; - } - return null; - } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTypeMapping.java index 7e62a933b8..1ffaceb0e1 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmTypeMapping.java @@ -18,13 +18,12 @@ import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; -import org.eclipse.jpt.jpa.core.context.InheritanceType; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; +import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.SpecifiedColumn; import org.eclipse.jpt.jpa.core.context.SpecifiedRelationship; -import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping; import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; @@ -45,19 +44,19 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * <code>orm.xml</code> type mapping */ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> - extends AbstractOrmXmlContextModel<OrmPersistentType> - implements OrmTypeMapping -{ + extends AbstractOrmXmlContextModel<OrmPersistentType> + implements OrmTypeMapping { + // never null protected final X xmlTypeMapping; - + protected Boolean specifiedMetadataComplete; protected boolean overrideMetadataComplete; - + protected String specifiedParentClass; protected String defaultParentClass; protected String fullyQualifiedParentClass; - + protected AbstractOrmTypeMapping(OrmPersistentType parent, X xmlTypeMapping) { super(parent); this.xmlTypeMapping = xmlTypeMapping; @@ -71,19 +70,19 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.setSpecifiedMetadataComplete_(this.xmlTypeMapping.getMetadataComplete()); - this.setSpecifiedParentClass_(this.buildSpecifiedParentClass()); + setSpecifiedMetadataComplete_(xmlTypeMapping.getMetadataComplete()); + setSpecifiedParentClass_(buildSpecifiedParentClass()); } - + @Override public void update() { super.update(); - this.setOverrideMetadataComplete(this.buildOverrideMetadataComplete()); - this.setDefaultParentClass(this.buildDefaultParentClass()); - this.setFullyQualifiedParentClass(this.buildFullyQualifiedParentClass()); + setOverrideMetadataComplete(buildOverrideMetadataComplete()); + setDefaultParentClass(buildDefaultParentClass()); + setFullyQualifiedParentClass(buildFullyQualifiedParentClass()); } - - + + // ********** metadata complete ********** /** @@ -216,8 +215,8 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> public JavaTypeMapping getJavaTypeMappingForDefaults() { return this.isMetadataComplete() ? null : this.getJavaTypeMapping(); } - - + + // ********** misc ********** public OrmPersistentType getPersistentType() { @@ -261,7 +260,7 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> public boolean attributeIsDerivedId(String attributeName) { return TypeMappingTools.attributeIsDerivedId(this, attributeName); } - + @Override public void toString(StringBuilder sb) { sb.append(this.getPersistentType().getName()); @@ -288,117 +287,92 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> // ********** attribute mappings ********** - + public boolean attributeMappingKeyAllowed(String attributeMappingKey) { return true; } - + public Iterable<AttributeMapping> getAttributeMappings() { - return IterableTools.transform(this.getPersistentType().getAttributes(), OrmPersistentAttribute.MAPPING_TRANSFORMER); + return IterableTools.transform(getPersistentType().getAttributes(), OrmPersistentAttribute.MAPPING_TRANSFORMER); } - + public Iterable<AttributeMapping> getAllAttributeMappings() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.ATTRIBUTE_MAPPINGS_TRANSFORMER); + return IterableTools.transform(getPersistentType().getAllAttributes(), PersistentAttribute.MAPPING_TRANSFORMER); } - + public Iterable<String> getOverridableAttributeNames() { - return IterableTools.children(this.getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ATTRIBUTE_MAPPING_NAMES_TRANSFORMER); + return IterableTools.children(getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ATTRIBUTE_MAPPING_NAMES_TRANSFORMER); } - + public Iterable<String> getAllOverridableAttributeNames() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ATTRIBUTE_NAMES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ATTRIBUTE_NAMES_TRANSFORMER); } - + public Iterable<AttributeMapping> getAttributeMappings(final String mappingKey) { - return IterableTools.filter(this.getAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); + return IterableTools.filter(getAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); } - + public Iterable<AttributeMapping> getAllAttributeMappings(final String mappingKey) { - return IterableTools.filter(this.getAllAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); + return IterableTools.filter(getAllAttributeMappings(), new AttributeMapping.KeyEquals(mappingKey)); } - + public Iterable<AttributeMapping> getNonTransientAttributeMappings() { - return new FilteringIterable<AttributeMapping>(this.getAllAttributeMappings(), AttributeMapping.IS_NOT_TRANSIENT); + return new FilteringIterable<AttributeMapping>(getAllAttributeMappings(), AttributeMapping.IS_NOT_TRANSIENT); } - + + public Iterable<AttributeMapping> getIdAttributeMappings() { + return IterableTools.filter(getAllAttributeMappings(), new IdTypeMapping.MappingIsIdMapping()); + } + + public AttributeMapping getIdAttributeMapping() { + Iterable<AttributeMapping> idMappings = getIdAttributeMappings(); + if (IterableTools.size(idMappings) == 1) { + return IterableTools.get(idMappings, 0); + } + return null; + } + public SpecifiedColumn resolveOverriddenColumn(String attributeName) { - for (AttributeMapping attributeMapping : this.getAttributeMappings()) { + for (AttributeMapping attributeMapping : getAttributeMappings()) { SpecifiedColumn column = attributeMapping.resolveOverriddenColumn(attributeName); if (column != null) { return column; } } - if ( ! this.isMetadataComplete()) { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); + if ( ! isMetadataComplete()) { + JavaPersistentType javaPersistentType = getJavaPersistentType(); if (javaPersistentType != null) { return javaPersistentType.getMapping().resolveOverriddenColumn(attributeName); } } return null; } - + public Iterable<String> getOverridableAssociationNames() { - return IterableTools.children(this.getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ASSOCIATION_MAPPING_NAMES_TRANSFORMER); + return IterableTools.children(getAttributeMappings(), AttributeMapping.ALL_OVERRIDABLE_ASSOCIATION_MAPPING_NAMES_TRANSFORMER); } - + public Iterable<String> getAllOverridableAssociationNames() { - return IterableTools.children(this.getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ASSOCIATION_NAMES_TRANSFORMER); + return IterableTools.children(getInheritanceHierarchy(), TypeMappingTools.OVERRIDABLE_ASSOCIATION_NAMES_TRANSFORMER); } - + public SpecifiedRelationship resolveOverriddenRelationship(String attributeName) { - for (AttributeMapping attributeMapping : this.getAttributeMappings()) { + for (AttributeMapping attributeMapping : getAttributeMappings()) { SpecifiedRelationship relationship = attributeMapping.resolveOverriddenRelationship(attributeName); if (relationship != null) { return relationship; } } - if ( ! this.isMetadataComplete()) { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); + if ( ! isMetadataComplete()) { + JavaPersistentType javaPersistentType = getJavaPersistentType(); if (javaPersistentType != null) { return javaPersistentType.getMapping().resolveOverriddenRelationship(attributeName); } } return null; } - - - // ********** inheritance hierarchy ********** - - public TypeMapping getSuperTypeMapping() { - PersistentType superPersistentType = this.getPersistentType().getSuperPersistentType(); - return (superPersistentType == null) ? null : superPersistentType.getMapping(); - } - - public Iterable<TypeMapping> getInheritanceHierarchy() { - return this.convertToMappings(this.getPersistentType().getInheritanceHierarchy()); - } - - /** - * Return the type mapping's "persistence" ancestors, - * <em>excluding</em> the type mapping itself. - * The returned iterator will return elements infinitely if the hierarchy - * has a loop. - */ - protected Iterable<TypeMapping> getAncestors() { - return this.convertToMappings(this.getPersistentType().getAncestors()); - } - - protected Iterable<TypeMapping> convertToMappings(Iterable<PersistentType> types) { - return IterableTools.transform(types, PersistentType.MAPPING_TRANSFORMER); - } - - public InheritanceType getInheritanceStrategy() { - return null; - } - - public boolean isRootEntity() { - return false; - } - - public Entity getRootEntity() { - return null; - } - + + // ********** text ranges ********** public TextRange getSelectionTextRange() { 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 c6a72fe292..4b6fab8204 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 @@ -12,8 +12,8 @@ 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.TypeTools; import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools; +import org.eclipse.jpt.common.core.internal.utility.TypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.AstNodeType; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; @@ -21,6 +21,7 @@ import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.jpa.core.context.AccessType; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; @@ -41,9 +42,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * <code>orm.xml</code> ID class reference */ public class GenericOrmIdClassReference - extends AbstractOrmXmlContextModel<OrmIdTypeMapping> - implements OrmIdClassReference, PersistentType.Parent -{ + extends AbstractOrmXmlContextModel<OrmIdTypeMapping> + implements OrmIdClassReference, PersistentType.Parent { + protected String specifiedIdClassName; protected String defaultIdClassName; protected String fullyQualifiedIdClassName; @@ -147,7 +148,11 @@ public class GenericOrmIdClassReference protected String buildDefaultIdClassName() { JavaIdClassReference javaRef = this.parent.getJavaIdClassReferenceForDefaults(); - return (javaRef == null) ? null : javaRef.getFullyQualifiedIdClassName(); + if (javaRef != null && javaRef.isSpecified()) { + return javaRef.getFullyQualifiedIdClassName(); + } + IdTypeMapping superType = getParent().getSuperTypeMapping(); + return (superType == null) ? null : superType.getIdClassReference().getFullyQualifiedIdClassName(); } public boolean isSpecified() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java index f9bb8d1d62..363f4e14a6 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java @@ -44,6 +44,7 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.context.PersistentType; +import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.TypeRefactoringParticipant; import org.eclipse.jpt.jpa.core.context.java.JavaManagedType; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; @@ -91,9 +92,7 @@ public abstract class SpecifiedOrmPersistentType protected final SpecifiedAttributeContainerAdapter specifiedAttributeContainerAdapter = new SpecifiedAttributeContainerAdapter(); protected final Vector<OrmPersistentAttribute> defaultAttributes = new Vector<OrmPersistentAttribute>(); - - protected PersistentType superPersistentType; - + protected String declaringTypeName; protected final MetamodelSourceType2_0.Synchronizer metamodelSynchronizer; @@ -130,7 +129,6 @@ public abstract class SpecifiedOrmPersistentType this.setDefaultAccess(this.buildDefaultAccess()); this.updateModels(this.getSpecifiedAttributes()); this.updateDefaultAttributes(); - this.setSuperPersistentType(this.buildSuperPersistentType()); this.setDeclaringTypeName(this.buildDeclaringTypeName()); this.updateStructureChildren(); } @@ -236,8 +234,8 @@ public abstract class SpecifiedOrmPersistentType return this.getJavaPersistentType().getAccess(); } } - if (this.superPersistentType != null) { - return this.superPersistentType.getAccess(); + if (getSuperPersistentType() != null) { + return getSuperPersistentType().getAccess(); } } AccessType access = this.getMappingFileRoot().getAccess(); @@ -292,7 +290,7 @@ public abstract class SpecifiedOrmPersistentType return attributes.hasNext() ? null /* more than one */: attribute; } // recurse - return (this.superPersistentType == null) ? null : this.superPersistentType.resolveAttribute(attributeName); + return (getSuperPersistentType() == null) ? null : getSuperPersistentType().resolveAttribute(attributeName); } protected Iterable<String> convertToNames(Iterable<? extends PersistentAttribute> attributes) { @@ -907,52 +905,24 @@ public abstract class SpecifiedOrmPersistentType defaultAttribute.dispose(); this.removeItemFromList(defaultAttribute, this.defaultAttributes, DEFAULT_ATTRIBUTES_LIST); } - - - // ********** super persistent type ********** - + + + // ***** inheritance ***** + public PersistentType getSuperPersistentType() { - return this.superPersistentType; - } - - protected void setSuperPersistentType(PersistentType persistentType) { - PersistentType old = this.superPersistentType; - this.superPersistentType = persistentType; - this.firePropertyChanged(SUPER_PERSISTENT_TYPE_PROPERTY, old, persistentType); - } - - protected PersistentType buildSuperPersistentType() { - PersistentType spt = this.buildSuperPersistentType_(); - if (spt == null) { - return null; - } - // check for circular inheritance - return IterableTools.contains(spt.getInheritanceHierarchy(), this) ? null : spt; + TypeMapping superTypeMapping = this.mapping.getSuperTypeMapping(); + return (superTypeMapping == null) ? null : superTypeMapping.getPersistentType(); } - - protected PersistentType buildSuperPersistentType_() { - return (this.getJavaPersistentType() == null) ? null : this.getJavaPersistentType().getSuperPersistentType(); - } - - - // ********** inheritance ********** - + public Iterable<PersistentType> getInheritanceHierarchy() { - return this.buildInheritanceHierarchy(this); + return IterableTools.insert(this, getAncestors()); } - + public Iterable<PersistentType> getAncestors() { - return (this.superPersistentType == null) ? - IterableTools.<PersistentType>emptyIterable() : - this.buildInheritanceHierarchy(this.superPersistentType); - } - - protected Iterable<PersistentType> buildInheritanceHierarchy(PersistentType start) { - // using a chain iterable to traverse up the inheritance tree - return ObjectTools.chain(start, SUPER_PERSISTENT_TYPE_TRANSFORMER); + return IterableTools.transform(getMapping().getAncestors(), TypeMapping.PERSISTENT_TYPE_TRANSFORMER); } - - + + // ********** declaring type name ********** public String getDeclaringTypeName() { @@ -1102,8 +1072,8 @@ public abstract class SpecifiedOrmPersistentType return this.specifiedAccess; } - if (this.superPersistentType instanceof OrmPersistentType) { - AccessType accessType = ((OrmPersistentType) this.superPersistentType).getSpecifiedAccess(); + if (getSuperPersistentType() instanceof OrmPersistentType) { + AccessType accessType = ((OrmPersistentType) getSuperPersistentType()).getSpecifiedAccess(); if (accessType != null) { return accessType; } @@ -1121,8 +1091,8 @@ public abstract class SpecifiedOrmPersistentType } public AccessType getDefaultPersistentTypeAccess() { - if (this.superPersistentType instanceof OrmPersistentType) { - AccessType accessType = ((OrmPersistentType) this.superPersistentType).getDefaultAccess(); + if (getSuperPersistentType() instanceof OrmPersistentType) { + AccessType accessType = ((OrmPersistentType) getSuperPersistentType()).getDefaultAccess(); if (accessType != null) { return accessType; } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java index 219c0663d7..7d2742cdda 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java @@ -61,6 +61,7 @@ import org.eclipse.jpt.jpa.core.context.DeleteTypeRefactoringParticipant; import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; +import org.eclipse.jpt.jpa.core.context.IdTypeMapping; import org.eclipse.jpt.jpa.core.context.JpaNamedContextModel; import org.eclipse.jpt.jpa.core.context.ManagedType; import org.eclipse.jpt.jpa.core.context.ManagedTypeContainer; @@ -1940,13 +1941,18 @@ public abstract class AbstractPersistenceUnit TypeMapping typeMapping = this.getTypeMapping(typeName); return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; } - + + public IdTypeMapping getIdTypeMapping(String typeName) { + TypeMapping typeMapping = this.getTypeMapping(typeName); + return (typeMapping instanceof IdTypeMapping) ? (IdTypeMapping) typeMapping : null; + } + // TODO bjv - this should probably *not* return Java type mappings when PU is "metadata complete"... protected TypeMapping getTypeMapping(String typeName) { PersistentType persistentType = this.getPersistentType(typeName); return (persistentType == null) ? null : persistentType.getMapping(); } - + public Iterable<Entity> getEntities() { return this.filterToEntities(this.getTypeMappings()); } 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 e14169805b..9fcec8c2a5 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 @@ -20,8 +20,6 @@ import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.collection.HashBag; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.SubIterableWrapper; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; -import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.jpa.core.MappingKeys; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.AttributeMapping; @@ -419,8 +417,8 @@ public abstract class AbstractPrimaryKeyValidator /** * Return whether an ancestor class has defined any aspect of the primary key */ - protected boolean definesPrimaryKeyOnAncestor(TypeMapping typeMapping) { - for (TypeMapping each : typeMapping.getInheritanceHierarchy()) { + protected boolean definesPrimaryKeyOnAncestor(IdTypeMapping typeMapping) { + for (IdTypeMapping each : typeMapping.getInheritanceHierarchy()) { if (each != typeMapping && definesPrimaryKey(each)) { return true; } @@ -431,7 +429,7 @@ public abstract class AbstractPrimaryKeyValidator /** * Return whether the type mapping has defined any aspect of the primary key */ - protected boolean definesPrimaryKey(TypeMapping typeMapping) { + protected boolean definesPrimaryKey(IdTypeMapping typeMapping) { return getIdClass(typeMapping) != null || ! IterableTools.isEmpty(getPrimaryKeyMappings(typeMapping)); } @@ -439,7 +437,7 @@ public abstract class AbstractPrimaryKeyValidator /** * Return true if the type mapping has defined any aspect of a complex primary key */ - protected boolean definesComplexPrimaryKey(TypeMapping typeMapping) { + protected boolean definesComplexPrimaryKey(IdTypeMapping typeMapping) { return definesIdClass(typeMapping) || getEmbeddedIdMapping(typeMapping) != null; } @@ -453,7 +451,7 @@ public abstract class AbstractPrimaryKeyValidator * - null if none of the above are coherent (i.e. there are multiple possibilities, or the * primary key is invalid) */ - protected String getPrimaryKeyTypeName(TypeMapping typeMapping) { + protected String getPrimaryKeyTypeName(IdTypeMapping typeMapping) { JavaPersistentType idClass = getIdClass(typeMapping); if (idClass != null) { return idClass.getName(); @@ -519,15 +517,15 @@ public abstract class AbstractPrimaryKeyValidator * NOTE: this is different from whether an id class is *specified*. If a specified id class * is not resolved, it is not defined. There will be a validation error to that effect. */ - protected boolean definesIdClass(TypeMapping typeMapping) { + protected boolean definesIdClass(IdTypeMapping typeMapping) { return getIdClass(typeMapping) != null; } /** * Return whether an ancestor class has defined an id class */ - protected boolean definesIdClassOnAncestor(TypeMapping typeMapping) { - for (TypeMapping each : typeMapping.getInheritanceHierarchy()) { + protected boolean definesIdClassOnAncestor(IdTypeMapping typeMapping) { + for (IdTypeMapping each : typeMapping.getInheritanceHierarchy()) { if (each != typeMapping && definesIdClass(each)) { return true; } @@ -539,10 +537,10 @@ public abstract class AbstractPrimaryKeyValidator * Return the id class to be used for the type mapping, whether that be locally * or on an ancestor */ - protected JavaPersistentType getIdClass(TypeMapping typeMapping) { - for (TypeMapping each : typeMapping.getInheritanceHierarchy()) { - if (each.getIdClass() != null) { - return each.getIdClass(); + protected JavaPersistentType getIdClass(IdTypeMapping typeMapping) { + for (IdTypeMapping each : typeMapping.getInheritanceHierarchy()) { + if (each.getIdClassReference().getIdClass() != null) { + return each.getIdClassReference().getIdClass(); } } return null; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java index a6d11cb8ee..931197e521 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaMapsIdDerivedIdentityStrategy2_0.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa2.context.java; -import java.util.Iterator; import java.util.List; import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; import org.eclipse.jpt.common.core.utility.TextRange; @@ -20,12 +19,12 @@ import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; import org.eclipse.jpt.common.utility.internal.iterable.TransformationIterable; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.jpa.core.MappingKeys; import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.EmbeddedIdMapping; +import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.SpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaContextModel; @@ -40,159 +39,178 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class GenericJavaMapsIdDerivedIdentityStrategy2_0 - extends AbstractJavaContextModel<JavaDerivedIdentity2_0> - implements MapsIdDerivedIdentityStrategy2_0 -{ + extends AbstractJavaContextModel<JavaDerivedIdentity2_0> + implements MapsIdDerivedIdentityStrategy2_0 { + protected String specifiedIdAttributeName; + protected String defaultIdAttributeName; - - + + public GenericJavaMapsIdDerivedIdentityStrategy2_0(JavaDerivedIdentity2_0 parent) { super(parent); - this.specifiedIdAttributeName = this.buildSpecifiedIdAttributeName(); + this.specifiedIdAttributeName = buildSpecifiedIdAttributeName(); } - - + + // ********** synchronize/update ********** - + @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.setSpecifiedIdAttributeName_(this.buildSpecifiedIdAttributeName()); + setSpecifiedIdAttributeName_(buildSpecifiedIdAttributeName()); } - + @Override public void update() { super.update(); - this.setDefaultIdAttributeName(this.buildDefaultIdAttributeName()); + setDefaultIdAttributeName(buildDefaultIdAttributeName()); } - - + + // ********** ID attribute name ********** - + public String getIdAttributeName() { return (this.specifiedIdAttributeName != null) ? this.specifiedIdAttributeName : this.defaultIdAttributeName; } - + public String getSpecifiedIdAttributeName() { return this.specifiedIdAttributeName; } - + public void setSpecifiedIdAttributeName(String idAttributeName) { if (ObjectTools.notEquals(idAttributeName, this.specifiedIdAttributeName)) { - this.getAnnotation().setValue(idAttributeName); - this.setSpecifiedIdAttributeName_(idAttributeName); + getAnnotation().setValue(idAttributeName); + setSpecifiedIdAttributeName_(idAttributeName); } } - + protected void setSpecifiedIdAttributeName_(String idAttributeName) { String old = this.specifiedIdAttributeName; this.specifiedIdAttributeName = idAttributeName; - this.firePropertyChanged(SPECIFIED_ID_ATTRIBUTE_NAME_PROPERTY, old, idAttributeName); + firePropertyChanged(SPECIFIED_ID_ATTRIBUTE_NAME_PROPERTY, old, idAttributeName); } - + protected String buildSpecifiedIdAttributeName() { - return this.getAnnotation().getValue(); + return getAnnotation().getValue(); } - + public String getDefaultIdAttributeName() { return this.defaultIdAttributeName; } - + protected void setDefaultIdAttributeName(String idAttributeName) { String old = this.defaultIdAttributeName; this.defaultIdAttributeName = idAttributeName; - this.firePropertyChanged(DEFAULT_ID_ATTRIBUTE_NAME_PROPERTY, old, idAttributeName); + firePropertyChanged(DEFAULT_ID_ATTRIBUTE_NAME_PROPERTY, old, idAttributeName); } - + protected String buildDefaultIdAttributeName() { - Iterator<AttributeMapping> stream = this.getIdAttributeMappings().iterator(); - if (stream.hasNext()) { - AttributeMapping mapping = stream.next(); - // return null if we have more than one id mapping - return stream.hasNext() ? null : mapping.getName(); + AttributeMapping mapping = getPersistentAttribute().getDeclaringTypeMapping().getIdAttributeMapping(); + if (mapping == null) { + return null; + } + + // if id mapping is embedded id ... + if (ObjectTools.equals(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, mapping.getKey())) { + // ... if embedded id and target entity have same primary key return embedded id name + EmbeddedIdMapping embeddedId = (EmbeddedIdMapping) mapping; + Entity targetEntity = getMapping().getResolvedTargetEntity(); + if (targetEntity != null && + ObjectTools.equals(embeddedId.getTargetEmbeddableName(), targetEntity.getPrimaryKeyClassName())) { + return embeddedId.getName(); + } + // ... otherwise use name of the mapping itself + else { + return getMapping().getName(); + } } + // if id mapping is simple id, return its name + else if (ObjectTools.equals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, mapping.getKey())) { + return mapping.getName(); + } + return null; // empty } - + public boolean defaultIdAttributeNameIsPossible() { return true; } - - + + // ********** annotation ********** - + /** * Do <em>not</em> return <code>null</code>. */ protected MapsIdAnnotation2_0 getAnnotation() { - return (MapsIdAnnotation2_0) this.getResourceAttribute().getNonNullAnnotation(this.getAnnotationName()); + return (MapsIdAnnotation2_0) getResourceAttribute().getNonNullAnnotation(getAnnotationName()); } - + /** * Return <code>null</code> if the annotation is not present. */ protected MapsIdAnnotation2_0 getAnnotationOrNull() { - return (MapsIdAnnotation2_0) this.getResourceAttribute().getAnnotation(this.getAnnotationName()); + return (MapsIdAnnotation2_0) getResourceAttribute().getAnnotation(getAnnotationName()); } - + protected void addAnnotation() { - this.getResourceAttribute().addAnnotation(this.getAnnotationName()); + getResourceAttribute().addAnnotation(getAnnotationName()); } - + protected void removeAnnotation() { - this.getResourceAttribute().removeAnnotation(this.getAnnotationName()); + getResourceAttribute().removeAnnotation(getAnnotationName()); } - + protected String getAnnotationName() { return MapsIdAnnotation2_0.ANNOTATION_NAME; } - - + + // ********** misc ********** - + protected JavaDerivedIdentity2_0 getDerivedIdentity() { return this.parent; } - + protected JavaSingleRelationshipMapping2_0 getMapping() { - return this.getDerivedIdentity().getMapping(); + return getDerivedIdentity().getMapping(); } - + protected JavaSpecifiedPersistentAttribute getPersistentAttribute() { - return this.getMapping().getPersistentAttribute(); + return getMapping().getPersistentAttribute(); } - + protected JavaResourceAttribute getResourceAttribute() { - return this.getPersistentAttribute().getResourceAttribute(); + return getPersistentAttribute().getResourceAttribute(); } - + protected Iterable<AttributeMapping> getAllAttributeMappings() { - return this.getPersistentAttribute().getDeclaringTypeMapping().getAllAttributeMappings(); + return getPersistentAttribute().getDeclaringTypeMapping().getAllAttributeMappings(); } - + public Iterable<String> getSortedCandidateIdAttributeNames() { - return IterableTools.sort(this.getAllAttributeMappingChoiceNames()); + return IterableTools.sort(getAllAttributeMappingChoiceNames()); } - + protected Iterable<String> getAllAttributeMappingChoiceNames() { - return IterableTools.transform(this.getAllAttributeMappingChoices(), AttributeMapping.NAME_TRANSFORMER); + return IterableTools.transform(getAllAttributeMappingChoices(), AttributeMapping.NAME_TRANSFORMER); } - + protected Iterable<AttributeMapping> getAllAttributeMappingChoices() { - return this.buildAttributeMappingChoices(this.getAllAttributeMappings()); + return buildAttributeMappingChoices(getAllAttributeMappings()); } - + /** * @see #getEmbeddedIdMappingChoiceIterable(EmbeddedIdMapping) */ protected Iterable<AttributeMapping> buildAttributeMappingChoices(Iterable<AttributeMapping> attributeMappings) { return IterableTools.children(attributeMappings, new AttributeMappingTransformer()); } - + public class AttributeMappingTransformer - extends TransformerAdapter<AttributeMapping, Iterable<AttributeMapping>> - { + extends TransformerAdapter<AttributeMapping, Iterable<AttributeMapping>> { + @Override public Iterable<AttributeMapping> transform(AttributeMapping mapping) { return (ObjectTools.equals(mapping.getKey(), MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)) ? @@ -200,7 +218,7 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0 new SingleElementIterable<AttributeMapping>(mapping); } } - + /** * Convert the specified mapping into a collection of its "mappings". * Typically, this collection will include just the mapping itself; @@ -217,11 +235,11 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0 embeddable.getAllAttributeMappings() ); } - + public AttributeMapping getDerivedIdAttributeMapping() { - String idAttributeName = this.getIdAttributeName(); + String idAttributeName = getIdAttributeName(); if (idAttributeName != null) { - for (AttributeMapping mapping : this.getAllAttributeMappingChoices()) { + for (AttributeMapping mapping : getAllAttributeMappingChoices()) { if (idAttributeName.equals(mapping.getName())) { return mapping; } @@ -229,113 +247,82 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0 } return null; } - + public boolean isSpecified() { - return this.getAnnotationOrNull() != null; + return getAnnotationOrNull() != null; } - + public void addStrategy() { - if (this.getAnnotationOrNull() == null) { - this.addAnnotation(); + if (getAnnotationOrNull() == null) { + addAnnotation(); } } - + public void removeStrategy() { - if (this.getAnnotationOrNull() != null) { - this.removeAnnotation(); + if (getAnnotationOrNull() != null) { + removeAnnotation(); } } - - + + // ********** Java completion proposals ********** - + @Override public Iterable<String> getCompletionProposals(int pos) { Iterable<String> result = super.getCompletionProposals(pos); if (result != null) { return result; } - if (this.getAnnotation().valueTouches(pos)) { - result = this.getSortedJavaValueChoices(); + if (getAnnotation().valueTouches(pos)) { + result = getSortedJavaValueChoices(); } return result; } - + protected Iterable<String> getSortedJavaValueChoices() { - return new TransformationIterable<String, String>(this.getSortedCandidateIdAttributeNames(), + return new TransformationIterable<String, String>(getSortedCandidateIdAttributeNames(), StringTools.JAVA_STRING_LITERAL_CONTENT_TRANSFORMER); } - - - // ********** ID mappings ********** - - protected Iterable<AttributeMapping> getIdAttributeMappings() { - return IterableTools.filter(this.getAllAttributeMappings(), new MappingIsIdMapping()); - } - - public class MappingIsIdMapping - extends PredicateAdapter<AttributeMapping> - { - @Override - public boolean evaluate(AttributeMapping mapping) { - return GenericJavaMapsIdDerivedIdentityStrategy2_0.this.mappingIsIdMapping(mapping); - } - } - - protected boolean mappingIsIdMapping(AttributeMapping mapping) { - return IterableTools.contains(this.getIdMappingKeys(), mapping.getKey()); - } - - protected Iterable<String> getIdMappingKeys() { - return ID_MAPPING_KEYS; - } - - protected static final String[] ID_MAPPING_KEYS_ARRAY = new String[] { - MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, - MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY - }; - protected static final Iterable<String> ID_MAPPING_KEYS = IterableTools.iterable(ID_MAPPING_KEYS_ARRAY); - - + // ********** validation ********** - + @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validateMapsId(messages); + validateMapsId(messages); } - + protected void validateMapsId(List<IMessage> messages) { - if (this.getDerivedIdentity().usesMapsIdDerivedIdentityStrategy()) { - this.validateMapsId_(messages); + if (getDerivedIdentity().usesMapsIdDerivedIdentityStrategy()) { + validateMapsId_(messages); } } - + protected void validateMapsId_(List<IMessage> messages) { // test whether id attribute name can be resolved - AttributeMapping attributeMapping = this.getDerivedIdAttributeMapping(); + AttributeMapping attributeMapping = getDerivedIdAttributeMapping(); if (attributeMapping == null) { // if id attribute name is not specified, use that message if (this.specifiedIdAttributeName == null) { - messages.add(this.buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_NOT_SPECIFIED)); + messages.add(buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_NOT_SPECIFIED)); } else { - messages.add(this.buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_NOT_RESOLVED, this.getIdAttributeName())); + messages.add(buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_NOT_RESOLVED, getIdAttributeName())); } } else { // test whether attribute mapping is allowable - if ( ! IterableTools.contains(this.getValidAttributeMappingChoices(), attributeMapping)) { - messages.add(this.buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_INVALID, this.getIdAttributeName())); + if ( ! IterableTools.contains(getValidAttributeMappingChoices(), attributeMapping)) { + messages.add(buildMessage(JptJpaCoreValidationMessages.MAPS_ID_VALUE_INVALID, getIdAttributeName())); } } } - + protected Iterable<AttributeMapping> getValidAttributeMappingChoices() { - return this.buildAttributeMappingChoices(this.getIdAttributeMappings()); + return this.buildAttributeMappingChoices(getPersistentAttribute().getDeclaringTypeMapping().getIdAttributeMappings()); } - + protected IMessage buildMessage(ValidationMessage msg, Object... args) { - SpecifiedPersistentAttribute attribute = this.getPersistentAttribute(); + SpecifiedPersistentAttribute attribute = getPersistentAttribute(); String attributeDescription = attribute.isVirtual() ? JptJpaCoreValidationArgumentMessages.VIRTUAL_ATTRIBUTE_DESC : JptJpaCoreValidationArgumentMessages.ATTRIBUTE_DESC; @@ -343,16 +330,16 @@ public class GenericJavaMapsIdDerivedIdentityStrategy2_0 args = ArrayTools.add(args, 0, attributeDescription); TextRange textRange = attribute.isVirtual() ? attribute.getValidationTextRange() : - this.getValidationTextRange(); - return this.buildValidationMessage(textRange, msg, args); + getValidationTextRange(); + return buildValidationMessage(textRange, msg, args); } - + public TextRange getValidationTextRange() { - TextRange textRange = this.getAnnotationTextRange(); - return (textRange != null) ? textRange : this.getDerivedIdentity().getValidationTextRange(); + TextRange textRange = getAnnotationTextRange(); + return (textRange != null) ? textRange : getDerivedIdentity().getValidationTextRange(); } - + protected TextRange getAnnotationTextRange() { - return this.getAnnotation().getTextRange(); + return getAnnotation().getTextRange(); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java index 5f5af98b10..8dddb4b99c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java @@ -1991,15 +1991,15 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen } public SpecifiedColumn resolveOverriddenColumn(String attributeName) { - return MappingTools.resolveOverriddenColumn(this.getOverridableTypeMapping(), attributeName); + return MappingTools.resolveOverriddenColumn(getOverridableTypeMapping(), attributeName); } public JpaValidator buildOverrideValidator(Override_ override, OverrideContainer container) { - return new AttributeOverrideValidator(this.getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, new EmbeddableOverrideDescriptionProvider()); + return new AttributeOverrideValidator(getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, new EmbeddableOverrideDescriptionProvider()); } public JpaValidator buildColumnValidator(Override_ override, BaseColumn column, TableColumn.ParentAdapter columnParentAdapter) { - return new AttributeOverrideColumnValidator(this.getPersistentAttribute(), (AttributeOverride) override, column, new CollectionTableTableDescriptionProvider()); + return new AttributeOverrideColumnValidator(getPersistentAttribute(), (AttributeOverride) override, column, new CollectionTableTableDescriptionProvider()); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmMapsIdDerivedIdentityStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmMapsIdDerivedIdentityStrategy2_0.java index 4637ce4519..474c4a9a50 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmMapsIdDerivedIdentityStrategy2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmMapsIdDerivedIdentityStrategy2_0.java @@ -16,7 +16,6 @@ import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; -import org.eclipse.jpt.common.utility.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jpa.core.MappingKeys; @@ -35,115 +34,123 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; +/* + * Currently, it does not look as though default values (maps-id="") + * are supported in XML. Therefore there is only a specified value + * and the alternative is an error specifying the value. + */ public class GenericOrmMapsIdDerivedIdentityStrategy2_0 - extends AbstractOrmXmlContextModel<OrmDerivedIdentity2_0> - implements OrmMapsIdDerivedIdentityStrategy2_0 -{ + extends AbstractOrmXmlContextModel<OrmDerivedIdentity2_0> + implements OrmMapsIdDerivedIdentityStrategy2_0 { + protected String specifiedIdAttributeName; - // no default - - + + public GenericOrmMapsIdDerivedIdentityStrategy2_0(OrmDerivedIdentity2_0 parent) { super(parent); - this.specifiedIdAttributeName = this.getXmlMapping().getMapsId(); + this.specifiedIdAttributeName = buildSpecifiedIdAttributeName(); } - - + + // ********** synchronize/update ********** - + @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.setSpecifiedIdAttributeName_(this.getXmlMapping().getMapsId()); + this.setSpecifiedIdAttributeName_(buildSpecifiedIdAttributeName()); } - - + + // ********** ID attribute name ********** - + public String getIdAttributeName() { - // there is no default return this.specifiedIdAttributeName; } - + public String getSpecifiedIdAttributeName() { return this.specifiedIdAttributeName; } - + public void setSpecifiedIdAttributeName(String idAttributeName) { this.setSpecifiedIdAttributeName_(idAttributeName); this.getXmlMapping().setMapsId(idAttributeName); } - + protected void setSpecifiedIdAttributeName_(String idAttributeName) { String old = this.specifiedIdAttributeName; this.specifiedIdAttributeName = idAttributeName; this.firePropertyChanged(SPECIFIED_ID_ATTRIBUTE_NAME_PROPERTY, old, idAttributeName); } - + + protected String buildSpecifiedIdAttributeName() { + return getXmlMapping().getMapsId(); + } + public String getDefaultIdAttributeName() { - // there is no way to have a default in xml + // see class comment return null; } - + public boolean defaultIdAttributeNameIsPossible() { + // see class comment return false; } - - + + // ********** misc ********** - + protected OrmDerivedIdentity2_0 getDerivedIdentity() { return this.parent; } - + public OrmSingleRelationshipMapping2_0 getMapping() { return this.getDerivedIdentity().getMapping(); } - + protected OrmSpecifiedPersistentAttribute getPersistentAttribute() { return this.getMapping().getPersistentAttribute(); } - + protected XmlSingleRelationshipMapping_2_0 getXmlMapping() { return this.getMapping().getXmlAttributeMapping(); } - + protected Iterable<AttributeMapping> getAllAttributeMappings() { return this.getPersistentAttribute().getDeclaringTypeMapping().getAllAttributeMappings(); } - + public Iterable<String> getSortedCandidateIdAttributeNames() { return IterableTools.sort(this.getNonNullCandidateIdAttributeNames()); } - + protected Iterable<String> getNonNullCandidateIdAttributeNames() { return IterableTools.removeNulls(this.getCandidateIdAttributeNames()); } - + protected Iterable<String> getCandidateIdAttributeNames() { return IterableTools.transform(this.getCandidateIdAttributeMappings(), AttributeMapping.NAME_TRANSFORMER); } - + protected Iterable<AttributeMapping> getCandidateIdAttributeMappings() { return this.buildCandidateIdAttributeMappings(this.getAllAttributeMappings()); } - + protected Iterable<AttributeMapping> buildCandidateIdAttributeMappings(Iterable<AttributeMapping> attributeMappings) { return IterableTools.children(attributeMappings, CANDIDATE_ID_ATTRIBUTE_MAPPING_LISTS_TRANSFORMER); } - + protected static final Transformer<AttributeMapping, Iterable<AttributeMapping>> CANDIDATE_ID_ATTRIBUTE_MAPPING_LISTS_TRANSFORMER = new CandidateIdAttributeMappingListsTransformer(); - + protected static class CandidateIdAttributeMappingListsTransformer - extends TransformerAdapter<AttributeMapping, Iterable<AttributeMapping>> - { + extends TransformerAdapter<AttributeMapping, Iterable<AttributeMapping>> { + @Override public Iterable<AttributeMapping> transform(AttributeMapping attributeMapping) { return ObjectTools.equals(attributeMapping.getKey(), MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) ? this.getEmbeddedIdMappingChoiceIterable((EmbeddedIdMapping) attributeMapping) : new SingleElementIterable<AttributeMapping>(attributeMapping); } - + /** * Convert the specified mapping into a collection of its "mappings". * Typically, this collection will include just the mapping itself; @@ -159,7 +166,7 @@ public class GenericOrmMapsIdDerivedIdentityStrategy2_0 IterableTools.insert(mapping, embeddable.getAllAttributeMappings()); } } - + public AttributeMapping getDerivedIdAttributeMapping() { String idAttributeName = this.getIdAttributeName(); if (idAttributeName != null) { @@ -171,69 +178,38 @@ public class GenericOrmMapsIdDerivedIdentityStrategy2_0 } return null; } - + public boolean isSpecified() { return this.getXmlMapping().getMapsId() != null; } - + public void addStrategy() { this.getXmlMapping().setMapsId(""); //$NON-NLS-1$ } - + public void removeStrategy() { this.getXmlMapping().setMapsId(null); } - + public void initializeFrom(OrmMapsIdDerivedIdentityStrategy2_0 oldStrategy) { this.setSpecifiedIdAttributeName(oldStrategy.getSpecifiedIdAttributeName()); } - - - // ********** ID mappings ********** - - protected Iterable<AttributeMapping> getIdAttributeMappings() { - return IterableTools.filter(this.getAllAttributeMappings(), new MappingIsIdMapping()); - } - - public class MappingIsIdMapping - extends PredicateAdapter<AttributeMapping> - { - @Override - public boolean evaluate(AttributeMapping mapping) { - return GenericOrmMapsIdDerivedIdentityStrategy2_0.this.mappingIsIdMapping(mapping); - } - } - - protected boolean mappingIsIdMapping(AttributeMapping mapping) { - return IterableTools.contains(this.getIdMappingKeys(), mapping.getKey()); - } - - protected Iterable<String> getIdMappingKeys() { - return ID_MAPPING_KEYS; - } - - protected static final String[] ID_MAPPING_KEYS_ARRAY = new String[] { - MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, - MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY - }; - protected static final Iterable<String> ID_MAPPING_KEYS = IterableTools.iterable(ID_MAPPING_KEYS_ARRAY); - - + // ********** validation ********** - + @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); this.validateMapsId(messages); } - + protected void validateMapsId(List<IMessage> messages) { if (this.getDerivedIdentity().usesMapsIdDerivedIdentityStrategy()) { this.validateMapsId_(messages); } } - + protected void validateMapsId_(List<IMessage> messages) { // test whether id attribute name can be resolved AttributeMapping attributeMapping = this.getDerivedIdAttributeMapping(); @@ -247,17 +223,17 @@ public class GenericOrmMapsIdDerivedIdentityStrategy2_0 } } } - + protected Iterable<AttributeMapping> getValidAttributeMappingChoices() { - return this.buildCandidateIdAttributeMappings(this.getIdAttributeMappings()); + return this.buildCandidateIdAttributeMappings(getPersistentAttribute().getDeclaringTypeMapping().getIdAttributeMappings()); } - + protected IMessage buildMessage(ValidationMessage msg, Object[] args) { String attributeDescription = NLS.bind(JptJpaCoreValidationArgumentMessages.ATTRIBUTE_DESC, this.getPersistentAttribute().getName()); args = ArrayTools.add(args, 0, attributeDescription); return this.buildValidationMessage(this.getValidationTextRange(), msg, args); } - + public TextRange getValidationTextRange() { TextRange textRange = this.getXmlMapping().getMapsIdTextRange(); return (textRange != null) ? textRange : this.getDerivedIdentity().getValidationTextRange(); |