diff options
author | Brian Vosburgh | 2013-04-30 20:40:21 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-04-30 20:53:00 +0000 |
commit | a89bf09664296357cfdfd0cbf473ee1820ce8d2e (patch) | |
tree | 9e26a7c28c072a0255497ffa8daa2d6c6edb5c76 | |
parent | 9b5ed45204c80b315f0f4807bdc5e2fed68976f0 (diff) | |
download | webtools.dali-a89bf09664296357cfdfd0cbf473ee1820ce8d2e.tar.gz webtools.dali-a89bf09664296357cfdfd0cbf473ee1820ce8d2e.tar.xz webtools.dali-a89bf09664296357cfdfd0cbf473ee1820ce8d2e.zip |
[406731] fix NPE in metamodel generation when target type is null
16 files changed, 153 insertions, 157 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaSpecifiedPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaSpecifiedPersistentAttribute.java index 5e7290c4f5..404d7f4cec 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaSpecifiedPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaSpecifiedPersistentAttribute.java @@ -79,7 +79,7 @@ public interface JavaSpecifiedPersistentAttribute /** * If the attribute's type is an appropriate "container" type, * return the type parameter that can be used as a target type. - * Return null if the attribute is not a container or if the type + * Return <code>null</code> if the attribute is not a container or if the type * parameter is not valid as a target type (i.e. it is either * an array or a "container"). */ 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 70da26a685..3c355cb1ec 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 @@ -402,7 +402,7 @@ public final class MappingTools { String mapKey = mapping.getMapKey(); if ((mapKey == null) || (targetType == null)) { String mapKeyClass = mapping.getFullyQualifiedMapKeyClass(); - return mapKeyClass != null ? mapKeyClass : MetamodelField2_0.DEFAULT_TYPE_NAME; + return (mapKeyClass != null) ? mapKeyClass : MetamodelField2_0.DEFAULT_TYPE_NAME; } PersistentAttribute mapKeyAttribute = targetType.resolveAttribute(mapKey); if (mapKeyAttribute == null) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaAttributeMapping.java index a60efa1e94..161172c161 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaAttributeMapping.java @@ -269,9 +269,9 @@ public abstract class AbstractJavaAttributeMapping<A extends Annotation> } /** - * by default, we add only the mapping's attribute type name; + * By default, we add only the mapping's attribute type name; * but collection relationship mappings will also need to add the key type - * name if the "collection" is of type java.util.Map + * name if the "collection" is of type {@link java.util.Map}. */ protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { typeArgumentNames.add(this.getMetamodelTypeName()); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmAttributeMapping.java index 4a1f441722..4e213ec197 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmAttributeMapping.java @@ -397,24 +397,15 @@ public abstract class AbstractOrmAttributeMapping<X extends XmlAttributeMapping> // ********** metamodel ********** public MetamodelField2_0 getMetamodelField() { - // if we don't have a name we can't build a metamodel field... String metamodelFieldName = this.getMetamodelFieldName(); - if(metamodelFieldName == null) { - return null; - } - MetamodelField2_0 result = null; - try { - result = new SimpleMetamodelField( - this.getMetamodelFieldModifiers(), - this.getMetamodelFieldTypeName(), - this.getMetamodelFieldTypeArgumentNames(), - metamodelFieldName - ); - } - catch(IllegalMetamodelFieldTypeArgumentException e) { - // the target entity is dynamic - } - return result; + // if we don't have a name we can't build a metamodel field... + return (metamodelFieldName == null) ? null : + new SimpleMetamodelField( + this.getMetamodelFieldModifiers(), + this.getMetamodelFieldTypeName(), + this.getMetamodelFieldTypeArgumentNames(), + metamodelFieldName + ); } protected Iterable<String> getMetamodelFieldModifiers() { @@ -436,16 +427,12 @@ public abstract class AbstractOrmAttributeMapping<X extends XmlAttributeMapping> } /** - * by default, we add only the mapping's attribute type name; + * By default, we add only the mapping's attribute type name; * but collection relationship mappings will also need to add the key type - * name if the "collection" is of type java.util.Map + * name if the "collection" is of type {@link java.util.Map}. */ protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { - String metamodelTypeName = this.getMetamodelTypeName(); - if(metamodelTypeName == null) { // the attribute is dynamic - throw this.buildIllegalMetamodelFieldTypeArgumentException(); - } - typeArgumentNames.add(metamodelTypeName); + typeArgumentNames.add(this.getMetamodelTypeName()); } public String getMetamodelTypeName() { @@ -456,9 +443,6 @@ public abstract class AbstractOrmAttributeMapping<X extends XmlAttributeMapping> return this.name; } - protected IllegalMetamodelFieldTypeArgumentException buildIllegalMetamodelFieldTypeArgumentException() { - return new IllegalMetamodelFieldTypeArgumentException(); - } // ********** refactoring ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java index d11dc1fad9..a33d2f2085 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java @@ -21,15 +21,16 @@ import org.eclipse.jpt.common.utility.internal.iterable.SingleElementIterable; import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.FetchType; -import org.eclipse.jpt.jpa.core.context.SpecifiedPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; +import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.RelationshipMapping; +import org.eclipse.jpt.jpa.core.context.SpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.orm.OrmMappingRelationship; -import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.context.orm.OrmRelationshipMapping; +import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmCascade; +import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField2_0; import org.eclipse.jpt.jpa.core.jpa2.context.PersistentType2_0; import org.eclipse.jpt.jpa.core.jpa2.context.RelationshipMapping2_0; import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmCascade2_0; @@ -154,16 +155,21 @@ public abstract class AbstractOrmRelationshipMapping<X extends AbstractXmlRelati } protected TypeMapping getResolvedTargetTypeMapping() { - PersistentType resolvedTargetType = this.getResolvedTargetType(); - return (resolvedTargetType == null) ? null : resolvedTargetType.getMapping(); + PersistentType targetType = this.getResolvedTargetType(); + return (targetType == null) ? null : targetType.getMapping(); } // sub-classes like this to be public public PersistentType getResolvedTargetType() { - if (this.fullyQualifiedTargetEntity == null) { - return null; - } - return getPersistenceUnit().getPersistentType(this.fullyQualifiedTargetEntity); + return (this.fullyQualifiedTargetEntity == null) ? null : this.getPersistenceUnit().getPersistentType(this.fullyQualifiedTargetEntity); + } + + /** + * <strong>NB:</strong> Be certain you are dealing with a JPA 2.0 project + * before calling this method. + */ + protected PersistentType2_0 getResolvedTargetType2_0() { + return (PersistentType2_0) this.getResolvedTargetType(); } public char getTargetEntityEnclosingTypeSeparator() { @@ -422,11 +428,12 @@ public abstract class AbstractOrmRelationshipMapping<X extends AbstractXmlRelati @Override public String getMetamodelTypeName() { - PersistentType resolvedTargetType = this.getResolvedTargetType(); - if(((PersistentType2_0)resolvedTargetType).getMetamodelType() == null) { // dynamic type - return null; + PersistentType2_0 targetType = this.getResolvedTargetType2_0(); + if (targetType == null) { + return MetamodelField2_0.DEFAULT_TYPE_NAME; } - return resolvedTargetType.getName(); + targetType = targetType.getMetamodelType(); + return (targetType != null) ? targetType.getName() : MetamodelField2_0.DEFAULT_TYPE_NAME; } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/IllegalMetamodelFieldTypeArgumentException.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/IllegalMetamodelFieldTypeArgumentException.java deleted file mode 100644 index 10b47ae755..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/IllegalMetamodelFieldTypeArgumentException.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * IllegalMetamodelFieldTypeArgumentException - */ -public class IllegalMetamodelFieldTypeArgumentException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public IllegalMetamodelFieldTypeArgumentException() { - super(); - } -} 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 c173b621e5..4dbd1ac715 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 @@ -20,8 +20,8 @@ import org.eclipse.core.resources.IFile; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.internal.resource.xml.EFactoryTools; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.AstNodeType; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.AstNodeType; import org.eclipse.jpt.common.core.resource.java.JavaResourceField; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; @@ -55,7 +55,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition; import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; -import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaPersistentType; import org.eclipse.jpt.jpa.core.internal.context.java.PropertyAccessor; import org.eclipse.jpt.jpa.core.internal.plugin.JptJpaCorePlugin; import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelSourceType2_0; 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 c6eb38db46..2a0155fd27 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 @@ -2727,11 +2727,7 @@ public abstract class AbstractPersistenceUnit */ // TODO check monitor for cancel public IStatus synchronizeMetamodel(IProgressMonitor monitor) { - // gather up the persistent unit's types, eliminating duplicates; - // if we have persistent types with the same name in multiple locations, - // the last one we encounter wins (i.e. the classes in the orm.xml take - // precedence) - HashMap<String, PersistentType> allPersistentTypes = this.getPersistentTypesToSynchronizeMetamodel(); + HashMap<String, PersistentType> allPersistentTypes = this.getMetamodelPersistentTypes(); // build a list of the top-level types and a tree of their associated // member types etc. @@ -2833,17 +2829,53 @@ public abstract class AbstractPersistenceUnit /** * Gather up the persistent unit's types, eliminating duplicates; * if we have persistent types with the same name in multiple locations, - * the last one we encounter wins (i.e. the classes in the orm.xml take - * precedence) + * the last one we encounter wins + * (i.e. the classes in the <code>orm.xml</code> take precedence) */ - protected HashMap<String, PersistentType> getPersistentTypesToSynchronizeMetamodel() { + protected HashMap<String, PersistentType> getMetamodelPersistentTypes() { HashMap<String, PersistentType> allPersistentTypes = new HashMap<String, PersistentType>(); - this.addPersistentTypesTo(this.getJarFilePersistentTypes(), allPersistentTypes); - this.addPersistentTypesTo(this.getClassRefPersistentTypes(), allPersistentTypes); - this.addPersistentTypesTo(this.getMappingFilePersistentTypes(), allPersistentTypes); + this.addPersistentTypesTo(this.getMetamodelJarFilePersistentTypes(), allPersistentTypes); + this.addPersistentTypesTo(this.getMetamodelClassRefPersistentTypes(), allPersistentTypes); + this.addPersistentTypesTo(this.getMetamodelMappingFilePersistentTypes(), allPersistentTypes); return allPersistentTypes; } + /** + * Remove any types that are not to be used in the metamodel. + * @see PersistentType2_0#getMetamodelType() + */ + protected Iterable<PersistentType2_0> getMetamodelJarFilePersistentTypes() { + return IterableTools.removeNulls(IterableTools.transform(this.getJarFilePersistentTypes2_0(), PersistentType2_0.METAMODEL_TYPE_TRANSFORMER)); + } + + protected Iterable<PersistentType2_0> getJarFilePersistentTypes2_0() { + return IterableTools.downCast(this.getJarFilePersistentTypes()); + } + + /** + * Remove any types that are not to be used in the metamodel. + * @see PersistentType2_0#getMetamodelType() + */ + protected Iterable<PersistentType2_0> getMetamodelClassRefPersistentTypes() { + return IterableTools.removeNulls(IterableTools.transform(this.getClassRefPersistentTypes2_0(), PersistentType2_0.METAMODEL_TYPE_TRANSFORMER)); + } + + protected Iterable<PersistentType2_0> getClassRefPersistentTypes2_0() { + return IterableTools.downCast(this.getClassRefPersistentTypes()); + } + + /** + * Remove any types that are not to be used in the metamodel. + * @see PersistentType2_0#getMetamodelType() + */ + protected Iterable<PersistentType2_0> getMetamodelMappingFilePersistentTypes() { + return IterableTools.removeNulls(IterableTools.transform(this.getMappingFilePersistentTypes2_0(), PersistentType2_0.METAMODEL_TYPE_TRANSFORMER)); + } + + protected Iterable<PersistentType2_0> getMappingFilePersistentTypes2_0() { + return IterableTools.downCast(this.getMappingFilePersistentTypes()); + } + protected MetamodelSourceType2_0 selectSourceType(Iterable<MetamodelSourceType2_0> types, String typeName) { if (types != null) { for (MetamodelSourceType2_0 type : types) { 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 754d6151ff..6f72588c65 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 @@ -87,6 +87,7 @@ import org.eclipse.jpt.jpa.core.internal.jpa2.context.MapKeyJoinColumnValidator; import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneRelationship2_0; +import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField2_0; import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneRelationship2_0; import org.eclipse.jpt.jpa.core.jpa2.context.PersistentType2_0; import org.eclipse.jpt.jpa.core.jpa2.context.SpecifiedPersistentAttribute2_0; @@ -312,10 +313,15 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen // ********** resolved target type/embeddable/entity ********** public PersistentType getResolvedTargetType() { - if (this.fullyQualifiedTargetClass == null) { - return null; - } - return this.getPersistenceUnit().getPersistentType(this.fullyQualifiedTargetClass); + return (this.fullyQualifiedTargetClass == null) ? null : this.getPersistenceUnit().getPersistentType(this.fullyQualifiedTargetClass); + } + + /** + * <strong>NB:</strong> Be certain you are dealing with a JPA 2.0 project + * before calling this method. + */ + protected PersistentType2_0 getResolvedTargetType2_0() { + return (PersistentType2_0) this.getResolvedTargetType(); } protected Embeddable getResolvedTargetEmbeddable() { @@ -329,8 +335,8 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen } protected TypeMapping getResolvedTargetTypeMapping() { - PersistentType resolvedTargetType = this.getResolvedTargetType(); - return (resolvedTargetType == null) ? null : resolvedTargetType.getMapping(); + PersistentType targetType = this.getResolvedTargetType(); + return (targetType == null) ? null : targetType.getMapping(); } @@ -1205,11 +1211,12 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen @Override public String getMetamodelTypeName() { - PersistentType resolvedTargetType = this.getResolvedTargetType(); - if(((PersistentType2_0)resolvedTargetType).getMetamodelType() == null) { // dynamic type - return null; + PersistentType2_0 targetType = this.getResolvedTargetType2_0(); + if (targetType == null) { + return MetamodelField2_0.DEFAULT_TYPE_NAME; } - return resolvedTargetType.getName(); + targetType = targetType.getMetamodelType(); + return (targetType != null) ? targetType.getName() : MetamodelField2_0.DEFAULT_TYPE_NAME; } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/context/PersistentType2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/context/PersistentType2_0.java index da303abbe1..df8b165b4c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/context/PersistentType2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/context/PersistentType2_0.java @@ -9,6 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.jpa2.context; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; +import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jpa.core.context.PersistentType; /** @@ -33,10 +35,22 @@ public interface PersistentType2_0 */ String getDeclaringTypeName(); String DECLARING_TYPE_NAME_PROPERTY = "declaringTypeName"; //$NON-NLS-1$ - + /** - * Return the PersistentType used for Metamodel, which is "this" most of the time. + * Return the persistent type to be used for static metamodel generation, + * typically the persistent type itself. Return <code>null</code> if the + * persistent type is not to be used for static metamodel generation + * (e.g. the type does not have a corresponding Java source declaration + * and the resulting metamodel classes would not compile). */ PersistentType2_0 getMetamodelType(); - + Transformer<PersistentType2_0, PersistentType2_0> METAMODEL_TYPE_TRANSFORMER = new MetamodelTypeTransformer(); + class MetamodelTypeTransformer + extends TransformerAdapter<PersistentType2_0, PersistentType2_0> + { + @Override + public PersistentType2_0 transform(PersistentType2_0 pt) { + return pt.getMetamodelType(); + } + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java index df894a2534..3df5223658 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java @@ -776,7 +776,7 @@ public class EclipseLinkPersistenceUnit return; } - if (ArrayTools.contains(EclipseLinkCustomization.RESERVED_PROFILER_NAMES, profilerProperty.getValue())) { + if (ArrayTools.contains(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.RESERVED_PROFILER_NAMES, profilerProperty.getValue())) { return; } @@ -807,7 +807,7 @@ public class EclipseLinkPersistenceUnit ) ); } else if (!TypeTools.isSubType( - profilerProperty.getValue(), EclipseLinkCustomization.ECLIPSELINK_SESSION_PROFILER_CLASS_NAME, javaProject) + profilerProperty.getValue(), org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_SESSION_PROFILER_CLASS_NAME, javaProject) ) { messages.add( this.buildValidationMessage( @@ -853,7 +853,7 @@ public class EclipseLinkPersistenceUnit ) ); } else if (!TypeTools.isSubType( - property.getValue(), EclipseLinkCustomization.ECLIPSELINK_SESSION_CUSTOMIZER_CLASS_NAME, javaProject) + property.getValue(), org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_SESSION_CUSTOMIZER_CLASS_NAME, javaProject) ) { messages.add( this.buildValidationMessage( @@ -883,47 +883,47 @@ public class EclipseLinkPersistenceUnit } private Property getCacheTypeDefaultProperty() { - return this.getProperty(EclipseLinkCaching.ECLIPSELINK_CACHE_TYPE_DEFAULT); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_CACHE_TYPE_DEFAULT); } private Property getCacheSizeDefaultProperty() { - return this.getProperty(EclipseLinkCaching.ECLIPSELINK_CACHE_SIZE_DEFAULT); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_CACHE_SIZE_DEFAULT); } private Property getCacheSharedDefaultProperty() { - return this.getProperty(EclipseLinkCaching.ECLIPSELINK_CACHE_SHARED_DEFAULT); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_CACHE_SHARED_DEFAULT); } private Property getFlushClearCacheProperty() { - return this.getProperty(EclipseLinkCaching.ECLIPSELINK_FLUSH_CLEAR_CACHE); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_FLUSH_CLEAR_CACHE); } /** * Returns all Shared Cache Properties, including Entity and default. */ private Iterable<Property> getSharedCacheProperties() { - return this.getPropertiesWithNamePrefix(EclipseLinkCaching.ECLIPSELINK_SHARED_CACHE); + return this.getPropertiesWithNamePrefix(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_SHARED_CACHE); } /** * Returns Entity Cache Size Properties, excluding default. */ private Iterable<Property> getEntityCacheSizeProperties() { - return this.getEntityPropertiesWithPrefix(EclipseLinkCaching.ECLIPSELINK_CACHE_SIZE); + return this.getEntityPropertiesWithPrefix(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_CACHE_SIZE); } /** * Returns Entity Cache Type Properties, excluding default. */ private Iterable<Property> getEntityCacheTypeProperties() { - return this.getEntityPropertiesWithPrefix(EclipseLinkCaching.ECLIPSELINK_CACHE_TYPE); + return this.getEntityPropertiesWithPrefix(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCaching.ECLIPSELINK_CACHE_TYPE); } /** * Returns Descriptor Customizer Properties. */ private Iterable<Property> getDescriptorCustomizerProperties() { - return this.getEntityPropertiesWithPrefix(EclipseLinkCustomization.ECLIPSELINK_DESCRIPTOR_CUSTOMIZER); + return this.getEntityPropertiesWithPrefix(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_DESCRIPTOR_CUSTOMIZER); } /** @@ -955,18 +955,18 @@ public class EclipseLinkPersistenceUnit } private Property getExceptionHandlerProperty() { - return this.getProperty(EclipseLinkCustomization.ECLIPSELINK_EXCEPTION_HANDLER); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_EXCEPTION_HANDLER); } private Property getPerformanceProfilerProperty() { - return this.getProperty(EclipseLinkCustomization.ECLIPSELINK_PROFILER); + return this.getProperty(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_PROFILER); } /** * Returns all Session Customizer Properties. */ private Iterable<Property> getSessionCustomizerProperties() { - return this.getPropertiesWithNamePrefix(EclipseLinkCustomization.ECLIPSELINK_SESSION_CUSTOMIZER); + return this.getPropertiesWithNamePrefix(org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkCustomization.ECLIPSELINK_SESSION_CUSTOMIZER); } /** @@ -1344,21 +1344,4 @@ public class EclipseLinkPersistenceUnit return convertibleModels; } - - // ********** metamodel ********** - - @Override - protected HashMap<String, PersistentType> getPersistentTypesToSynchronizeMetamodel() { - HashMap<String, PersistentType> allPersistentTypes = super.getPersistentTypesToSynchronizeMetamodel(); - - this.removeDynamicTypes(allPersistentTypes); - return allPersistentTypes; - } - - private void removeDynamicTypes(HashMap<String, PersistentType> persistentTypes) { - Iterator<String> dynamicTypeNames = this.getEclipseLinkDynamicPersistentTypeNames().iterator(); - while(dynamicTypeNames.hasNext()) { - persistentTypes.remove(dynamicTypeNames.next()); - } - } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicCollectionMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicCollectionMapping.java index a0168da556..8215c74ecc 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicCollectionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicCollectionMapping.java @@ -15,7 +15,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmAttributeMapping; import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField2_0; import org.eclipse.jpt.jpa.core.jpa2.context.SpecifiedPersistentAttribute2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.PersistentType2_0; import org.eclipse.jpt.jpa.eclipselink.core.EclipseLinkMappingKeys; import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkBasicCollectionMapping; import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.Attributes; @@ -59,11 +58,8 @@ public abstract class EclipseLinkAbstractOrmBasicCollectionMapping @Override public String getMetamodelTypeName() { String targetTypeName = null; - JavaSpecifiedPersistentAttribute javaPersistentAttribute = getJavaPersistentAttribute(); + JavaSpecifiedPersistentAttribute javaPersistentAttribute = this.getJavaPersistentAttribute(); if (javaPersistentAttribute != null) { - if(((PersistentType2_0)javaPersistentAttribute).getMetamodelType() == null) { // dynamic type - return null; - } targetTypeName = javaPersistentAttribute.getMultiReferenceTargetTypeName(); } return (targetTypeName != null) ? targetTypeName : MetamodelField2_0.DEFAULT_TYPE_NAME; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicMapMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicMapMapping.java index af2b35240e..5ef2620c6d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicMapMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkAbstractOrmBasicMapMapping.java @@ -16,7 +16,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmAttributeMapping; import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField2_0; import org.eclipse.jpt.jpa.core.jpa2.context.SpecifiedPersistentAttribute2_0; -import org.eclipse.jpt.jpa.core.jpa2.context.PersistentType2_0; import org.eclipse.jpt.jpa.eclipselink.core.EclipseLinkMappingKeys; import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkBasicMapMapping; import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.Attributes; @@ -63,9 +62,6 @@ public abstract class EclipseLinkAbstractOrmBasicMapMapping String targetTypeName = null; JavaSpecifiedPersistentAttribute javaPersistentAttribute = this.getJavaPersistentAttribute(); if (javaPersistentAttribute != null) { - if(((PersistentType2_0)javaPersistentAttribute).getMetamodelType() == null) { // dynamic type - return null; - } targetTypeName = javaPersistentAttribute.getMultiReferenceTargetTypeName(); } return (targetTypeName != null) ? targetTypeName : MetamodelField2_0.DEFAULT_TYPE_NAME; @@ -83,7 +79,9 @@ public abstract class EclipseLinkAbstractOrmBasicMapMapping if (javaPersistentAttribute != null) { mapKeyTypeName = javaPersistentAttribute.getMultiReferenceMapKeyTypeName(); } - mapKeyTypeName = mapKeyTypeName != null ? mapKeyTypeName : MetamodelField2_0.DEFAULT_TYPE_NAME; + if (mapKeyTypeName == null) { + mapKeyTypeName = MetamodelField2_0.DEFAULT_TYPE_NAME; + } typeArgumentNames.add(mapKeyTypeName); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java index 8013d43787..4973092340 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java @@ -22,8 +22,8 @@ import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmManyToManyMappin import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkAccessType; import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkJoinFetch; import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkManyToManyMapping2_0; -import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmConvertibleMapping; import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmConverterContainer; +import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmConvertibleMapping; import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit; import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlManyToMany; import org.eclipse.jpt.jpa.eclipselink.core.validation.JptJpaEclipseLinkCoreValidationMessages; @@ -205,7 +205,7 @@ public class EclipseLinkOrmManyToManyMapping protected Iterable<String> getCandidateTargetEntityClassNames() { return IterableTools.concatenate( super.getCandidateTargetEntityClassNames(), - ((EclipseLinkPersistenceUnit) this.getPersistenceUnit()).getEclipseLinkDynamicPersistentTypeNames() + IterableTools.sort(((EclipseLinkPersistenceUnit) this.getPersistenceUnit()).getEclipseLinkDynamicPersistentTypeNames()) ); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentTypeImpl.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentTypeImpl.java index aaac3d61c7..88ee6cbe02 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentTypeImpl.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentTypeImpl.java @@ -46,9 +46,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; * </ul> */ public class EclipseLinkOrmPersistentTypeImpl - extends SpecifiedOrmPersistentType - implements EclipseLinkOrmPersistentType { - + extends SpecifiedOrmPersistentType + implements EclipseLinkOrmPersistentType +{ protected String specifiedGetMethod; protected String defaultGetMethod; @@ -57,6 +57,7 @@ public class EclipseLinkOrmPersistentTypeImpl protected boolean dynamic; + public EclipseLinkOrmPersistentTypeImpl(EntityMappings parent, XmlTypeMapping xmlTypeMapping) { super(parent, xmlTypeMapping); this.specifiedGetMethod = this.buildSpecifiedGetMethod(); @@ -73,6 +74,7 @@ public class EclipseLinkOrmPersistentTypeImpl return (EclipseLinkOrmTypeMapping) super.getMapping(); } + // ********** synchronize/update ********** @Override @@ -91,7 +93,7 @@ public class EclipseLinkOrmPersistentTypeImpl } - //*************** dynamic ***************** + // ********** dynamic ********** public boolean isDynamic() { return this.dynamic; @@ -128,7 +130,7 @@ public class EclipseLinkOrmPersistentTypeImpl @Override protected JavaManagedType buildJavaManagedType(JavaResourceType jrt) { - return this.isDynamic() ? + return this.dynamic ? this.buildVirtualJavaPersistentType() : super.buildJavaManagedType(jrt); } @@ -140,10 +142,7 @@ public class EclipseLinkOrmPersistentTypeImpl @Override public PersistentType getOverriddenPersistentType() { - if (this.isDynamic()) { - return null; - } - return super.getOverriddenPersistentType(); + return this.dynamic ? null : super.getOverriddenPersistentType(); } public OrmSpecifiedPersistentAttribute addVirtualAttribute(String attributeName, String mappingKey, String attributeType, String targetType) { @@ -171,19 +170,17 @@ public class EclipseLinkOrmPersistentTypeImpl @Override public TypeBinding getAttributeTypeBinding(PersistentAttribute attribute) { - if (isDynamic()) { - PersistentType superPT = getSuperPersistentType(); - return (superPT == null) ? null : superPT.getAttributeTypeBinding(attribute); + if (this.dynamic) { + return (this.superPersistentType == null) ? null : this.superPersistentType.getAttributeTypeBinding(attribute); } return super.getAttributeTypeBinding(attribute); } - //*************** get method ***************** + // ********** get method ********** public String getGetMethod() { - String getMethod = this.getSpecifiedGetMethod(); - return (getMethod != null) ? getMethod : this.defaultGetMethod; + return (this.specifiedGetMethod != null) ? this.specifiedGetMethod : this.defaultGetMethod; } public String getDefaultGetMethod() { @@ -230,11 +227,10 @@ public class EclipseLinkOrmPersistentTypeImpl } - //*************** set method ***************** + // ********** set method ********** public String getSetMethod() { - String setMethod = this.getSpecifiedSetMethod(); - return (setMethod != null) ? setMethod : this.defaultSetMethod; + return (this.specifiedSetMethod != null) ? this.specifiedSetMethod : this.defaultSetMethod; } public String getDefaultSetMethod() { @@ -280,7 +276,8 @@ public class EclipseLinkOrmPersistentTypeImpl return accessMethods != null ? accessMethods.getSetMethod() : null; } - //*************** XML access methods ***************** + + // ********** XML access methods ********** protected XmlAccessMethodsHolder getXmlAccessMethodsHolder() { return this.getXmlTypeMapping(); @@ -324,16 +321,16 @@ public class EclipseLinkOrmPersistentTypeImpl @Override protected void validateClassResolves(List<IMessage> messages) { - if (this.isDynamic() && !this.isVirtualAccess()) { + if (this.dynamic && ! this.isVirtualAccess()) { super.validateClassResolves(messages); } } + // ********** metamodel ********** @Override public PersistentType2_0 getMetamodelType() { - return (this.isDynamic()) ? null : this; + return this.dynamic ? null : this; } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkVirtualJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkVirtualJavaPersistentType.java index df78b9b362..58184009c2 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkVirtualJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkVirtualJavaPersistentType.java @@ -360,6 +360,7 @@ public class EclipseLinkVirtualJavaPersistentType sb.append(this.getName()); } + // ********** metamodel ********** public PersistentType2_0 getMetamodelType() { |