diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm')
8 files changed, 756 insertions, 420 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java index cc18aebc73..7406045415 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java @@ -25,9 +25,12 @@ import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.resource.xml.EmfTools; import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.filter.Filter; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.collection.ListTools; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; @@ -40,12 +43,15 @@ import org.eclipse.jpt.jpa.core.MappingKeys; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.DeleteTypeRefactoringParticipant; import org.eclipse.jpt.jpa.core.context.Generator; +import org.eclipse.jpt.jpa.core.context.ManagedType; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.TypeMapping; import org.eclipse.jpt.jpa.core.context.TypeRefactoringParticipant; import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; import org.eclipse.jpt.jpa.core.context.orm.OrmIdClassReference; +import org.eclipse.jpt.jpa.core.context.orm.OrmManagedType; +import org.eclipse.jpt.jpa.core.context.orm.OrmManagedTypeDefinition; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer; @@ -58,14 +64,19 @@ import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit; import org.eclipse.jpt.jpa.core.internal.plugin.JptJpaCorePlugin; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.jpa2_1.context.orm.EntityMappings2_1; +import org.eclipse.jpt.jpa.core.jpa2_1.context.orm.OrmConverterType2_1; import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; +import org.eclipse.jpt.jpa.core.resource.orm.OrmPackage; import org.eclipse.jpt.jpa.core.resource.orm.XmlEmbeddable; 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.XmlManagedType; import org.eclipse.jpt.jpa.core.resource.orm.XmlMappedSuperclass; import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator; import org.eclipse.jpt.jpa.core.resource.orm.XmlTableGenerator; import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping; +import org.eclipse.jpt.jpa.core.resource.orm.v2_1.XmlConverter_2_1; import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; import org.eclipse.jpt.jpa.db.Catalog; import org.eclipse.jpt.jpa.db.Database; @@ -84,7 +95,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; */ public abstract class AbstractEntityMappings extends AbstractOrmXmlContextNode - implements EntityMappings + implements EntityMappings2_1 { protected final XmlEntityMappings xmlEntityMappings; @@ -103,8 +114,8 @@ public abstract class AbstractEntityMappings protected final OrmPersistenceUnitMetadata persistenceUnitMetadata; - protected final Vector<OrmPersistentType> persistentTypes = new Vector<OrmPersistentType>(); - protected final PersistentTypeContainerAdapter persistentTypeContainerAdapter = new PersistentTypeContainerAdapter(); + protected final Vector<OrmManagedType> managedTypes = new Vector<OrmManagedType>(); + protected final ManagedTypeContainerAdapter managedTypeContainerAdapter = new ManagedTypeContainerAdapter(); protected final ContextListContainer<OrmSequenceGenerator, XmlSequenceGenerator> sequenceGeneratorContainer; @@ -131,7 +142,8 @@ public abstract class AbstractEntityMappings this.persistenceUnitMetadata = this.buildPersistenceUnitMetadata(); - this.initializePersistentTypes(); + this.initializeManagedTypes(); + this.sequenceGeneratorContainer = this.buildSequenceGeneratorContainer(); this.tableGeneratorContainer = this.buildTableGeneratorContainer(); this.queryContainer = this.buildQueryContainer(); @@ -155,7 +167,8 @@ public abstract class AbstractEntityMappings this.persistenceUnitMetadata.synchronizeWithResourceModel(); - this.syncPersistentTypes(); + this.syncManagedTypes(); + this.syncSequenceGenerators(); this.syncTableGenerators(); @@ -172,7 +185,8 @@ public abstract class AbstractEntityMappings this.persistenceUnitMetadata.update(); - this.updateNodes(this.getPersistentTypes()); + this.updateNodes(this.getManagedTypes()); + this.updateNodes(this.getSequenceGenerators()); this.updateNodes(this.getTableGenerators()); @@ -222,14 +236,14 @@ public abstract class AbstractEntityMappings return this.xmlEntityMappings.getSelectionTextRange(); } - //TODO I think children needs to include all managed types, - //thus JPA 2.1 converters are going to appear in the structure and project explorer views?? + //for now I am making the children only PersistentTypes. If we decide + //we want Converters listed in the structure view for an orm.xml, we can change this. protected void initializeChildren() { - this.children.addAll(this.persistentTypes); + CollectionTools.addAll(this.children, this.getPersistentTypes()); } protected void updateChildren() { - this.synchronizeCollection(this.persistentTypes, this.children, CHILDREN_COLLECTION); + this.synchronizeCollection(this.getPersistentTypes(), this.children, CHILDREN_COLLECTION); } public Iterable<OrmPersistentType> getChildren() { @@ -306,17 +320,17 @@ public abstract class AbstractEntityMappings public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { AccessType savedAccess = ormPersistentType.getSpecifiedAccess(); - int sourceIndex = this.persistentTypes.indexOf(ormPersistentType); - this.persistentTypes.remove(sourceIndex); + int sourceIndex = this.managedTypes.indexOf(ormPersistentType); + this.managedTypes.remove(sourceIndex); oldMapping.removeXmlTypeMappingFrom(this.xmlEntityMappings); int targetIndex = this.calculateInsertionIndex(ormPersistentType); - this.persistentTypes.add(targetIndex, ormPersistentType); + this.managedTypes.add(targetIndex, ormPersistentType); newMapping.addXmlTypeMappingTo(this.xmlEntityMappings); newMapping.initializeFrom(oldMapping); //not sure where else to put this, need to set the access on the resource model ormPersistentType.setSpecifiedAccess(savedAccess); - this.fireItemMoved(PERSISTENT_TYPES_LIST, targetIndex, sourceIndex); + this.fireItemMoved(MANAGED_TYPES_LIST, targetIndex, sourceIndex); } public TextRange getValidationTextRange() { @@ -507,21 +521,49 @@ public abstract class AbstractEntityMappings } - // ********** persistent types ********** + // ********** managed types ********** - public ListIterable<OrmPersistentType> getPersistentTypes() { - return IterableTools.cloneLive(this.persistentTypes); + public ListIterable<OrmManagedType> getManagedTypes() { + return IterableTools.cloneLive(this.managedTypes); } - public int getPersistentTypesSize() { - return this.persistentTypes.size(); + public int getManagedTypesSize() { + return this.managedTypes.size(); } - public OrmPersistentType getPersistentType(String className) { - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - if (ormPersistentType.isFor(className)) { - return ormPersistentType; + public OrmManagedType getManagedType(String typeName) { + for (OrmManagedType ormManagedType : this.getManagedTypes()) { + if (ormManagedType.isFor(typeName)) { + return ormManagedType; + } + } + return null; + } + + public boolean containsManagedType(String typeName) { + return this.getManagedType(typeName) != null; + } + + + // ********** persistent types ********** + + public Iterable<OrmPersistentType> getPersistentTypes() { + return IterableTools.downCast(IterableTools.filter( + this.getManagedTypes(), + ORM_PERSISTENT_TYPE_FILTER)); + } + + protected static final Filter<OrmManagedType> ORM_PERSISTENT_TYPE_FILTER = + new Filter<OrmManagedType>() { + public boolean accept(OrmManagedType mt) { + return mt.getType() == OrmPersistentType.class; } + }; + + public OrmPersistentType getPersistentType(String typeName) { + ManagedType mt = this.getManagedType(typeName); + if (mt != null && (mt.getType() == OrmPersistentType.class)) { + return (OrmPersistentType) mt; } return null; } @@ -656,26 +698,26 @@ public abstract class AbstractEntityMappings return (className == null) ? null : PRIMITIVE_CLASSES.get(className); } + public OrmPersistentType addPersistentType(String mappingKey, String className) { + OrmTypeMappingDefinition md = this.getMappingFileDefinition().getTypeMappingDefinition(mappingKey); + XmlTypeMapping xmlManagedType = md.buildResourceMapping(this.getResourceNodeFactory()); + return (OrmPersistentType) this.addManagedType(xmlManagedType, className); + } + /** - * We have to calculate the new persistent type's index. + * We have to calculate the new managed type's index. * We will use the type's short name if the entity mappings's * package is the same as the type's package. */ - public OrmPersistentType addPersistentType(String mappingKey, String className) { - OrmTypeMappingDefinition md = this.getMappingFileDefinition().getTypeMappingDefinition(mappingKey); - XmlTypeMapping xmlTypeMapping = md.buildResourceMapping(this.getResourceNodeFactory()); - + protected OrmManagedType addManagedType(XmlManagedType xmlManagedType, String className) { // adds short name if package name is relevant - className = this.normalizeClassName(className); - xmlTypeMapping.setClassName(className); - - OrmPersistentType persistentType = this.buildPersistentType(xmlTypeMapping); - int index = this.calculateInsertionIndex(persistentType); - this.addItemToList(index, persistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - - persistentType.getMapping().addXmlTypeMappingTo(this.xmlEntityMappings); + xmlManagedType.setClassName(this.normalizeClassName(className)); - return persistentType; + OrmManagedType managedType = this.buildManagedType(xmlManagedType); + int index = this.calculateInsertionIndex(managedType); + this.addItemToList(index, managedType, this.managedTypes, MANAGED_TYPES_LIST); + managedType.addXmlManagedTypeTo(this.xmlEntityMappings); + return managedType; } //TODO add API - added this post-M6 @@ -704,7 +746,7 @@ public abstract class AbstractEntityMappings } List<XmlMappedSuperclass> mappedSuperclasses = new ArrayList<XmlMappedSuperclass>(addedItems.size()); for (OrmPersistentType persistentType : addedItems) { - mappedSuperclasses.add((XmlMappedSuperclass) persistentType.getMapping().getXmlTypeMapping()); + mappedSuperclasses.add((XmlMappedSuperclass) persistentType.getXmlManagedType()); } sm.subTask(JptJpaCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL); //use addAll to minimize change notifications to our model @@ -721,7 +763,7 @@ public abstract class AbstractEntityMappings } List<XmlEntity> entities = new ArrayList<XmlEntity>(addedItems.size()); for (OrmPersistentType persistentType : addedItems) { - entities.add((XmlEntity) persistentType.getMapping().getXmlTypeMapping()); + entities.add((XmlEntity) persistentType.getXmlManagedType()); } sm.subTask(JptJpaCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL); //use addAll to minimize change notifications to our model @@ -738,7 +780,7 @@ public abstract class AbstractEntityMappings } List<XmlEmbeddable> embeddables = new ArrayList<XmlEmbeddable>(addedItems.size()); for (OrmPersistentType persistentType : addedItems) { - embeddables.add((XmlEmbeddable) persistentType.getMapping().getXmlTypeMapping()); + embeddables.add((XmlEmbeddable) persistentType.getXmlManagedType()); } sm.subTask(JptJpaCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL); //use addAll to minimize change notifications to our model @@ -760,7 +802,7 @@ public abstract class AbstractEntityMappings className = this.normalizeClassName(className); xmlTypeMapping.setClassName(className); - addedItems.add(this.buildPersistentType(xmlTypeMapping)); + addedItems.add((OrmPersistentType) this.buildManagedType(xmlTypeMapping)); } } if (addedItems.size() == 0 || sm.isCanceled()) { @@ -770,7 +812,7 @@ public abstract class AbstractEntityMappings int index = this.calculateInsertionIndex(addedItems.get(0)); sm.subTask(JptJpaCoreMessages.MAKE_PERSISTENT_UPDATING_JPA_MODEL); - this.addItemsToList(index, addedItems, this.persistentTypes, PERSISTENT_TYPES_LIST); + this.addItemsToList(index, addedItems, this.managedTypes, MANAGED_TYPES_LIST); sm.worked(9); return addedItems; } @@ -787,19 +829,20 @@ public abstract class AbstractEntityMappings className; } - protected OrmPersistentType buildPersistentType(XmlTypeMapping xmlTypeMapping) { - return this.getContextNodeFactory().buildOrmPersistentType(this, xmlTypeMapping); + protected OrmManagedType buildManagedType(XmlManagedType xmlManagedType) { + OrmManagedTypeDefinition md = this.getMappingFileDefinition().getManagedTypeDefinition(xmlManagedType.getType()); + return md.buildContextManagedType(this, xmlManagedType, this.getContextNodeFactory()); } - protected int calculateInsertionIndex(OrmPersistentType ormPersistentType) { - return ListTools.insertionIndexOf(this.persistentTypes, ormPersistentType, MAPPING_COMPARATOR); + protected int calculateInsertionIndex(OrmManagedType ormManagedType) { + return ListTools.insertionIndexOf(this.managedTypes, ormManagedType, MAPPING_COMPARATOR); } - protected static final Comparator<OrmPersistentType> MAPPING_COMPARATOR = - new Comparator<OrmPersistentType>() { - public int compare(OrmPersistentType o1, OrmPersistentType o2) { - int o1Sequence = o1.getMapping().getXmlSequence(); - int o2Sequence = o2.getMapping().getXmlSequence(); + protected static final Comparator<OrmManagedType> MAPPING_COMPARATOR = + new Comparator<OrmManagedType>() { + public int compare(OrmManagedType o1, OrmManagedType o2) { + int o1Sequence = o1.getXmlSequence(); + int o2Sequence = o2.getXmlSequence(); if (o1Sequence < o2Sequence) { return -1; } @@ -810,74 +853,94 @@ public abstract class AbstractEntityMappings } }; - public void removePersistentType(int index) { - OrmPersistentType persistentType = this.removePersistentType_(index); - persistentType.getMapping().removeXmlTypeMappingFrom(this.xmlEntityMappings); + public void removeManagedType(int index) { + OrmManagedType managedType = this.removeManagedType_(index); + managedType.removeXmlManagedTypeFrom(this.xmlEntityMappings); } /** - * dispose and return the persistent type + * dispose and return the managed type */ - protected OrmPersistentType removePersistentType_(int index) { - OrmPersistentType persistentType = this.removeItemFromList(index, this.persistentTypes, PERSISTENT_TYPES_LIST); - persistentType.dispose(); - return persistentType; + protected OrmManagedType removeManagedType_(int index) { + OrmManagedType managedType = this.removeItemFromList(index, this.managedTypes, MANAGED_TYPES_LIST); + managedType.dispose(); + return managedType; } - public void removePersistentType(OrmPersistentType persistentType) { - this.removePersistentType(this.persistentTypes.indexOf(persistentType)); + public void removeManagedType(OrmManagedType managedType) { + this.removeManagedType(this.managedTypes.indexOf(managedType)); } - protected void initializePersistentTypes() { - for (XmlTypeMapping xmlTypeMapping : this.getXmlTypeMappings()) { - this.persistentTypes.add(this.buildPersistentType(xmlTypeMapping)); + protected void initializeManagedTypes() { + for (XmlManagedType xmlManagedType : this.getXmlManagedTypes()) { + this.managedTypes.add(this.buildManagedType(xmlManagedType)); } } - protected void syncPersistentTypes() { - ContextContainerTools.synchronizeWithResourceModel(this.persistentTypeContainerAdapter); + protected void syncManagedTypes() { + ContextContainerTools.synchronizeWithResourceModel(this.managedTypeContainerAdapter); } - protected Iterable<XmlTypeMapping> getXmlTypeMappings() { + protected Iterable<XmlManagedType> getXmlManagedTypes() { // clone to reduce chance of concurrency problems - return IterableTools.cloneLive(this.xmlEntityMappings.getTypeMappings()); + return IterableTools.cloneLive(this.getXmlManagedTypes_()); } - protected void movePersistentType_(int index, OrmPersistentType persistentType) { - this.moveItemInList(index, persistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); + // ********** managed types ********** + + protected List<XmlManagedType> getXmlManagedTypes_() { + // convert lists to arrays to *reduce* risk of ConcurrentModificationException + ArrayList<XmlManagedType> managedTypes = new ArrayList<XmlManagedType>(); + CollectionTools.addAll(managedTypes, this.xmlEntityMappings.getMappedSuperclasses().toArray(EMPTY_XML_MANAGED_TYPE_ARRAY)); + CollectionTools.addAll(managedTypes, this.xmlEntityMappings.getEntities().toArray(EMPTY_XML_MANAGED_TYPE_ARRAY)); + CollectionTools.addAll(managedTypes, this.xmlEntityMappings.getEmbeddables().toArray(EMPTY_XML_MANAGED_TYPE_ARRAY)); + if (this.isJpa2_1Compatible()) { + CollectionTools.addAll(managedTypes, this.getXml2_1Converters().toArray(EMPTY_XML_MANAGED_TYPE_ARRAY)); + } + return managedTypes; + } + + protected List<XmlConverter_2_1> getXml2_1Converters() { + return this.xmlEntityMappings.getConverters(); + } + + protected static final XmlManagedType[] EMPTY_XML_MANAGED_TYPE_ARRAY = new XmlManagedType[0]; + + protected void moveManagedType_(int index, OrmManagedType managedType) { + this.moveItemInList(index, managedType, this.managedTypes, MANAGED_TYPES_LIST); } - protected void addPersistentType_(int index, XmlTypeMapping xmlTypeMapping) { - this.addItemToList(index, this.buildPersistentType(xmlTypeMapping), this.persistentTypes, PERSISTENT_TYPES_LIST); + protected void addManagedType_(int index, XmlManagedType xmlManagedType) { + this.addItemToList(index, this.buildManagedType(xmlManagedType), this.managedTypes, MANAGED_TYPES_LIST); } - protected void removePersistentType_(OrmPersistentType persistentType) { - this.removePersistentType_(this.persistentTypes.indexOf(persistentType)); + protected void removeManagedType_(OrmManagedType managedType) { + this.removeManagedType_(this.managedTypes.indexOf(managedType)); } /** - * persistent type container adapter + * managed type container adapter */ - protected class PersistentTypeContainerAdapter - implements ContextContainerTools.Adapter<OrmPersistentType, XmlTypeMapping> + protected class ManagedTypeContainerAdapter + implements ContextContainerTools.Adapter<OrmManagedType, XmlManagedType> { - public Iterable<OrmPersistentType> getContextElements() { - return AbstractEntityMappings.this.getPersistentTypes(); + public Iterable<OrmManagedType> getContextElements() { + return AbstractEntityMappings.this.getManagedTypes(); } - public Iterable<XmlTypeMapping> getResourceElements() { - return AbstractEntityMappings.this.getXmlTypeMappings(); + public Iterable<XmlManagedType> getResourceElements() { + return AbstractEntityMappings.this.getXmlManagedTypes(); } - public XmlTypeMapping getResourceElement(OrmPersistentType contextElement) { - return contextElement.getMapping().getXmlTypeMapping(); + public XmlManagedType getResourceElement(OrmManagedType contextElement) { + return contextElement.getXmlManagedType(); } - public void moveContextElement(int index, OrmPersistentType element) { - AbstractEntityMappings.this.movePersistentType_(index, element); + public void moveContextElement(int index, OrmManagedType element) { + AbstractEntityMappings.this.moveManagedType_(index, element); } - public void addContextElement(int index, XmlTypeMapping resourceElement) { - AbstractEntityMappings.this.addPersistentType_(index, resourceElement); + public void addContextElement(int index, XmlManagedType resourceElement) { + AbstractEntityMappings.this.addManagedType_(index, resourceElement); } - public void removeContextElement(OrmPersistentType element) { - AbstractEntityMappings.this.removePersistentType_(element); + public void removeContextElement(OrmManagedType element) { + AbstractEntityMappings.this.removeManagedType_(element); } } @@ -1048,6 +1111,45 @@ public abstract class AbstractEntityMappings } + // ********** converter types ********** + + public Iterable<OrmConverterType2_1> getConverterTypes() { + return IterableTools.downCast(IterableTools.filter( + this.getManagedTypes(), + ORM_CONVERTER_TYPE_FILTER)); + } + + protected static final Filter<OrmManagedType> ORM_CONVERTER_TYPE_FILTER = + new Filter<OrmManagedType>() { + public boolean accept(OrmManagedType mt) { + return mt.getType() == OrmConverterType2_1.class; + } + }; + + public OrmConverterType2_1 getConverterType(String typeName) { + ManagedType mt = this.getManagedType(typeName); + if (mt != null && (mt.getType() == OrmPersistentType.class)) { + return (OrmConverterType2_1) mt; + } + return null; + } + + public boolean containsConverterType(String typeName) { + return this.getConverterType(typeName) != null; + } + + public OrmConverterType2_1 addConverterType(String className) { + return (OrmConverterType2_1) this.addManagedType(this.buildXmlConverter(), className); + } + + protected XmlConverter_2_1 buildXmlConverter() { + return EmfTools.create( + this.getResourceNodeFactory(), + OrmPackage.eINSTANCE.getXmlConverter(), + XmlConverter_2_1.class); + } + + // ********** query container ********** public OrmQueryContainer getQueryContainer() { @@ -1103,8 +1205,8 @@ public abstract class AbstractEntityMappings this.validateVersion(messages); // generators are validated in the persistence unit this.queryContainer.validate(messages, reporter); - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - this.validatePersistentType(ormPersistentType, messages, reporter); + for (OrmManagedType managedType : this.getManagedTypes()) { + this.validateManagedType(managedType, messages, reporter); } } @@ -1132,9 +1234,9 @@ public abstract class AbstractEntityMappings return XmlEntityMappings.CONTENT_TYPE; } - protected void validatePersistentType(OrmPersistentType persistentType, List<IMessage> messages, IReporter reporter) { + protected void validateManagedType(OrmManagedType managedType, List<IMessage> messages, IReporter reporter) { try { - persistentType.validate(messages, reporter); + managedType.validate(messages, reporter); } catch (Throwable exception) { JptJpaCorePlugin.instance().logError(exception); } @@ -1144,26 +1246,26 @@ public abstract class AbstractEntityMappings // ********** refactoring ********** public Iterable<DeleteEdit> createDeleteTypeEdits(IType type) { - return IterableTools.children(this.getPersistentTypes(), new DeleteTypeRefactoringParticipant.DeleteTypeEditsTransformer(type)); + return IterableTools.children(this.getManagedTypes(), new DeleteTypeRefactoringParticipant.DeleteTypeEditsTransformer(type)); } public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) { - return IterableTools.children(this.getPersistentTypes(), new TypeRefactoringParticipant.RenameTypeEditsTransformer(originalType, newName)); + return IterableTools.children(this.getManagedTypes(), new TypeRefactoringParticipant.RenameTypeEditsTransformer(originalType, newName)); } public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) { - return IterableTools.children(this.getPersistentTypes(), new TypeRefactoringParticipant.MoveTypeEditsTransformer(originalType, newPackage)); + return IterableTools.children(this.getManagedTypes(), new TypeRefactoringParticipant.MoveTypeEditsTransformer(originalType, newPackage)); } @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) { return IterableTools.concatenate( - this.createPersistentTypeRenamePackageEdits(originalPackage, newName), + this.createManagedTypeRenamePackageEdits(originalPackage, newName), this.createRenamePackageEdit(originalPackage, newName)); } - protected Iterable<ReplaceEdit> createPersistentTypeRenamePackageEdits(IPackageFragment originalPackage, String newName) { - return IterableTools.children(this.getPersistentTypes(), new TypeRefactoringParticipant.RenamePackageEditsTransformer(originalPackage, newName)); + protected Iterable<ReplaceEdit> createManagedTypeRenamePackageEdits(IPackageFragment originalPackage, String newName) { + return IterableTools.children(this.getManagedTypes(), new TypeRefactoringParticipant.RenamePackageEditsTransformer(originalPackage, newName)); } protected Iterable<ReplaceEdit> createRenamePackageEdit(IPackageFragment originalPackage, String newName) { @@ -1203,8 +1305,8 @@ public abstract class AbstractEntityMappings if (this.packageTouches(pos)) { return this.getCandidatePackages(); } - for (OrmPersistentType persistentType : this.getPersistentTypes()) { - result = persistentType.getCompletionProposals(pos); + for (OrmManagedType managedType : this.getManagedTypes()) { + result = managedType.getCompletionProposals(pos); if (result != null) { return result; } 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 becb45d714..de6f09be1c 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 @@ -300,7 +300,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> if (javaEntity != null) { return javaEntity.getName(); } - String className = this.getClass_(); + String className = this.getPersistentType().getClass_(); return StringTools.isBlank(className) ? null : ClassNameTools.simpleName(className); } @@ -1744,7 +1744,7 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JptJpaCoreValidationMessages.ENTITY_NAME_MISSING, - new String[] {this.getClass_()}, + new String[] {this.getPersistentType().getClass_()}, this, this.getNameTextRange() ) @@ -1756,7 +1756,6 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> return true; } - @Override public TextRange getNameTextRange() { return this.getXmlTypeMapping().getNameTextRange(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmManagedType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmManagedType.java new file mode 100644 index 0000000000..02528f1be1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmManagedType.java @@ -0,0 +1,377 @@ +/******************************************************************************* + * 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.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IType; +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; +import org.eclipse.jpt.common.utility.internal.ClassNameTools; +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.ManagedType; +import org.eclipse.jpt.jpa.core.context.java.JavaManagedType; +import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; +import org.eclipse.jpt.jpa.core.context.orm.OrmManagedType; +import org.eclipse.jpt.jpa.core.internal.context.MappingTools; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.resource.orm.XmlManagedType; +import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; +import org.eclipse.text.edits.DeleteEdit; +import org.eclipse.text.edits.ReplaceEdit; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +/** + * specified <code>orm.xml</code> managed type:<ul> + + * <li>Java managed type + * </ul> + */ +public abstract class AbstractOrmManagedType + extends AbstractOrmXmlContextNode + implements OrmManagedType { + + protected XmlManagedType xmlManagedType; + + protected String class_; + + protected String name; + + protected JavaManagedType javaManagedType; + + + protected AbstractOrmManagedType(EntityMappings parent, XmlManagedType xmlManagedType) { + super(parent); + this.xmlManagedType = xmlManagedType; + this.class_ = this.xmlManagedType.getClassName(); + this.name = this.buildName(); + // 'javaManagedType' is resolved in the update + } + + + // ********** synchronize/update ********** + + @Override + public void synchronizeWithResourceModel() { + super.synchronizeWithResourceModel(); + this.setClass_(this.xmlManagedType.getClassName()); + this.setName(this.buildName()); + this.syncJavaManagedType(); + } + + @Override + public void update() { + super.update(); + this.updateJavaManagedType(); + } + + public XmlManagedType getXmlManagedType() { + return this.xmlManagedType; + } + + + // ********** class ********** + + public String getClass_() { + return this.class_; + } + + public void setClass(String class_) { + this.setClass_(class_); + this.xmlManagedType.setClassName(class_); + } + + protected void setClass_(String class_) { + String old = this.class_; + this.class_ = class_; + this.firePropertyChanged(CLASS_PROPERTY, old, class_); + } + + + // ********** name ********** + + public String getName() { + return this.name; + } + + protected void setName(String name) { + String old = this.name; + this.name = name; + if (this.firePropertyChanged(NAME_PROPERTY, old, name)) { + // clear out the Java managed type here, it will be rebuilt during "update" + if (this.javaManagedType != null) { + this.setJavaManagedType(null); + } + } + } + + protected String buildName() { + return this.getEntityMappings().qualify(this.class_); + } + + public String getSimpleName(){ + String className = this.getName(); + return StringTools.isBlank(className) ? null : ClassNameTools.simpleName(className); + } + + public String getTypeQualifiedName() { + String className = this.class_; + if (className == null) { + return null; + } + int lastPeriod = className.lastIndexOf('.'); + className = (lastPeriod == -1) ? className : className.substring(lastPeriod + 1); + className = className.replace('$', '.'); + return className; + } + + protected TextRange getClassTextRange() { + return this.getValidationTextRange(this.getXmlManagedType().getClassTextRange()); + } + + + // ********** Java managed type ********** + + public JavaManagedType getJavaManagedType() { + return this.javaManagedType; + } + + protected void setJavaManagedType(JavaManagedType javaManagedType) { + ManagedType old = this.javaManagedType; + this.javaManagedType = javaManagedType; + this.firePropertyChanged(JAVA_MANAGED_TYPE_PROPERTY, old, javaManagedType); + } + + /** + * If the managed type's name changes during <em>update</em>, + * the Java managed type will be cleared out in + * {@link #setName(String)}. If we get here and + * the Java managed type is present, we can + * <em>sync</em> it. In some circumstances it will be obsolete + * since the name is changed during update (the class name or + * the entity mapping's package affect the name) + * + * @see #updateJavaManagedType() + */ + protected void syncJavaManagedType() { + if (this.javaManagedType != null) { + this.javaManagedType.synchronizeWithResourceModel(); + } + } + + /** + * @see #syncJavaManagedType() + */ + protected void updateJavaManagedType() { + if (this.getName() == null) { + if (this.javaManagedType != null) { + this.setJavaManagedType(null); + } + } + else { + JavaResourceType resourceType = this.resolveJavaResourceType(); + if (this.javaManagedType == null) { + this.setJavaManagedType(this.buildJavaManagedType(resourceType)); + } + else { + // bug 379051 using == here because it is possible that the names are the same, + // but the location has changed: the java resource type has moved from "external" + // to part of the jpa project's jpa files. + if (this.javaManagedType.getJavaResourceType() == resourceType) { + this.javaManagedType.update(); + } else { + this.setJavaManagedType(this.buildJavaManagedType(resourceType)); + } + } + } + } + + /** + * Return null it's an enum; don't build a JavaManagedType + * @see #updateJavaManagedType() + */ + protected JavaResourceType resolveJavaResourceType() { + if (this.name == null) { + return null; + } + return (JavaResourceType) this.getJpaProject().getJavaResourceType(this.name, AstNodeType.TYPE); + } + + protected abstract JavaManagedType buildJavaManagedType(JavaResourceType jrt); + + + public JavaResourceType getJavaResourceType() { + return (this.javaManagedType == null) ? null : this.javaManagedType.getJavaResourceType(); + } + + public TextRange getValidationTextRange() { + // this should never be null; + TextRange textRange = this.getXmlManagedType().getValidationTextRange(); + //*return an Empty text range because validation sometimes run concurrently + //with the code adding the type mapping to xml; the IDOMNode might not + //be set when this is called. Brian's batch update changes in 3.2 should + //fix this problem. bug 358745 + return (textRange != null) ? textRange : TextRange.Empty.instance(); + } + + public TextRange getFullTextRange() { + return this.getXmlManagedType().getFullTextRange(); + } + + public boolean containsOffset(int textOffset) { + return this.getXmlManagedType().containsOffset(textOffset); + } + + + // ********** completion proposals ********** + + @Override + public Iterable<String> getCompletionProposals(int pos) { + Iterable<String> result = super.getCompletionProposals(pos); + if (result != null) { + return result; + } + if (this.classNameTouches(pos)) { + return this.getCandidateClassNames(); + } + return null; + } + + protected Iterable<String> getCandidateClassNames() { + return MappingTools.getSortedJavaClassNames(this.getJavaProject()); + } + + protected boolean classNameTouches(int pos) { + return this.getXmlManagedType().classNameTouches(pos); + } + + + //*********** refactoring *********** + + public Iterable<DeleteEdit> createDeleteTypeEdits(IType type) { + return this.isFor(type.getFullyQualifiedName('.')) ? + IterableTools.singletonIterable(this.createDeleteTypeEdit()) : + IterableTools.<DeleteEdit>emptyIterable(); + } + + protected DeleteEdit createDeleteTypeEdit() { + return this.getXmlManagedType().createDeleteEdit(); + } + + public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) { + return this.isFor(originalType.getFullyQualifiedName('.')) ? + IterableTools.singletonIterable(this.createRenameTypeEdit(originalType, newName)) : + IterableTools.<ReplaceEdit>emptyIterable(); + } + + protected ReplaceEdit createRenameTypeEdit(IType originalType, String newName) { + return this.getXmlManagedType().createRenameTypeEdit(originalType, newName); + } + + public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) { + return this.isFor(originalType.getFullyQualifiedName('.')) ? + IterableTools.singletonIterable(this.createRenamePackageEdit(newPackage.getElementName())) : + IterableTools.<ReplaceEdit>emptyIterable(); + } + + public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) { + return this.isIn(originalPackage) ? + IterableTools.singletonIterable(this.createRenamePackageEdit(newName)) : + IterableTools.<ReplaceEdit>emptyIterable(); + } + + protected ReplaceEdit createRenamePackageEdit(String newName) { + return this.getXmlManagedType().createRenamePackageEdit(newName); + } + + + // ********** validation ********** + + @Override + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + this.validateClass(messages); + } + + protected void validateClass(List<IMessage> messages) { + if (StringTools.isBlank(this.class_)) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JptJpaCoreValidationMessages.MANAGED_TYPE_UNSPECIFIED_CLASS, + this, + this.getClassTextRange() + ) + ); + return; + } + this.validateClassResolves(messages); + } + + protected void validateClassResolves(List<IMessage> messages) { + if (this.javaManagedType == null) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JptJpaCoreValidationMessages.MANAGED_TYPE_UNRESOLVED_CLASS, + new String[] {this.getName()}, + this, + this.getClassTextRange() + ) + ); + } + } + + + // ********** misc ********** + + @Override + public EntityMappings getParent() { + return (EntityMappings) super.getParent(); + } + + protected EntityMappings getEntityMappings() { + return this.getParent(); + } + + public String getDefaultPackage() { + return this.getEntityMappings().getDefaultPersistentTypePackage(); + } + + public boolean isFor(String typeName) { + return ObjectTools.equals(typeName, this.getName()); + } + + public boolean isIn(IPackageFragment packageFragment) { + String packageName = this.getPackageName(); + if (ObjectTools.equals(packageName, packageFragment.getElementName())) { + return true; + } + return false; + } + + protected String getPackageName() { + String className = this.class_; + if (className == null) { + return null; + } + int lastPeriod = className.lastIndexOf('.'); + return (lastPeriod == -1) ? this.getDefaultPackage() : className.substring(0, lastPeriod); + } + + @Override + public void toString(StringBuilder sb) { + sb.append(this.getName()); + } +} 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 a3b1b776be..34bc00a956 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 @@ -14,10 +14,8 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.resource.java.JavaResourceType; import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterable.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; -import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.Column; import org.eclipse.jpt.jpa.core.context.Entity; @@ -37,12 +35,9 @@ import org.eclipse.jpt.jpa.core.internal.context.JptValidator; import org.eclipse.jpt.jpa.core.internal.context.MappingTools; import org.eclipse.jpt.jpa.core.internal.context.TypeMappingTools; import org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericTypeMappingValidator; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.Table; -import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -57,8 +52,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> // never null protected final X xmlTypeMapping; - protected String class_; - protected Boolean specifiedMetadataComplete; protected boolean overrideMetadataComplete; @@ -69,7 +62,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> protected AbstractOrmTypeMapping(OrmPersistentType parent, X xmlTypeMapping) { super(parent); this.xmlTypeMapping = xmlTypeMapping; - this.class_ = xmlTypeMapping.getClassName(); this.specifiedMetadataComplete = xmlTypeMapping.getMetadataComplete(); this.specifiedParentClass = this.buildSpecifiedParentClass(); } @@ -80,7 +72,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> @Override public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); - this.setClass_(this.xmlTypeMapping.getClassName()); this.setSpecifiedMetadataComplete_(this.xmlTypeMapping.getMetadataComplete()); this.setSpecifiedParentClass_(this.buildSpecifiedParentClass()); } @@ -94,24 +85,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> } - // ********** class ********** - - public String getClass_() { - return this.class_; - } - - public void setClass(String class_) { - this.setClass_(class_); - this.xmlTypeMapping.setClassName(class_); - } - - protected void setClass_(String class_) { - String old = this.class_; - this.class_ = class_; - this.firePropertyChanged(CLASS_PROPERTY, old, class_); - } - - // ********** metadata complete ********** /** @@ -283,7 +256,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> * mapping to the new (this). */ public void initializeFrom(OrmTypeMapping oldMapping) { - this.setClass(oldMapping.getClass_()); this.setSpecifiedMetadataComplete(oldMapping.getSpecifiedMetadataComplete()); this.setOverrideMetadataComplete(oldMapping.isOverrideMetadataComplete()); } @@ -435,57 +407,27 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> // ********** text ranges ********** - public JpaStructureNode getStructureNode(int offset) { - return this.xmlTypeMapping.containsOffset(offset) ? this.getPersistentType() : null; - } - public TextRange getSelectionTextRange() { return this.xmlTypeMapping.getSelectionTextRange(); } - public TextRange getClassTextRange() { - return this.getValidationTextRange(this.xmlTypeMapping.getClassTextRange()); - } - public TextRange getAttributesTextRange() { return this.getValidationTextRange(this.xmlTypeMapping.getAttributesTextRange()); } - public TextRange getNameTextRange() { - return this.getValidationTextRange(this.xmlTypeMapping.getNameTextRange()); - } - // ********** refactoring ********** - public DeleteEdit createDeleteEdit() { - return this.xmlTypeMapping.createDeleteEdit(); - } - public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) { - return this.getPersistentType().isFor(originalType.getFullyQualifiedName('.')) ? - IterableTools.singletonIterable(this.createRenameTypeEdit(originalType, newName)) : - IterableTools.<ReplaceEdit>emptyIterable(); - } - - protected ReplaceEdit createRenameTypeEdit(IType originalType, String newName) { - return this.xmlTypeMapping.createRenameTypeEdit(originalType, newName); + return IterableTools.<ReplaceEdit>emptyIterable(); } public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) { - return this.getPersistentType().isFor(originalType.getFullyQualifiedName('.')) ? - IterableTools.singletonIterable(this.createRenamePackageEdit(newPackage.getElementName())) : - IterableTools.<ReplaceEdit>emptyIterable(); + return IterableTools.<ReplaceEdit>emptyIterable(); } public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) { - return this.getPersistentType().isIn(originalPackage) ? - IterableTools.singletonIterable(this.createRenamePackageEdit(newName)) : - IterableTools.<ReplaceEdit>emptyIterable(); - } - - protected ReplaceEdit createRenamePackageEdit(String newName) { - return this.xmlTypeMapping.createRenamePackageEdit(newName); + return IterableTools.<ReplaceEdit>emptyIterable(); } @@ -505,17 +447,6 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> } protected void validateClass(List<IMessage> messages, IReporter reporter) { - if (StringTools.isBlank(this.class_)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JptJpaCoreValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CLASS, - this, - this.getClassTextRange() - ) - ); - return; - } if (this.getJavaResourceType() != null) { this.buildTypeMappingValidator().validate(messages, reporter); } @@ -534,35 +465,11 @@ public abstract class AbstractOrmTypeMapping<X extends XmlTypeMapping> } public TextRange getValidationTextRange() { - // this should never be null; also, the persistent type delegates - // to here, so don't delegate back to it (or we will get a stack overflow) bug 355415 - TextRange textRange = this.xmlTypeMapping.getValidationTextRange(); - //*return an Empty text range because validation sometimes run concurrently - //with the code adding the type mapping to xml; the IDOMNode might not - //be set when this is called. Brian's batch update changes in 3.2 should - //fix this problem. bug 358745 - return (textRange != null) ? textRange : TextRange.Empty.instance(); - } - - // ********** completion proposals ********** - - @Override - public Iterable<String> getCompletionProposals(int pos) { - Iterable<String> result = super.getCompletionProposals(pos); - if (result != null) { - return result; - } - if (this.classNameTouches(pos)) { - return this.getCandidateClassNames(); - } - return null; + return this.getPersistentType().getValidationTextRange(); } protected Iterable<String> getCandidateClassNames() { return MappingTools.getSortedJavaClassNames(this.getJavaProject()); } - protected boolean classNameTouches(int pos) { - return this.getXmlTypeMapping().classNameTouches(pos); - } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlContextNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlContextNode.java index 9e513ddad1..7096ae8048 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlContextNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 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. @@ -17,7 +17,9 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory; import org.eclipse.jpt.jpa.core.context.orm.OrmXmlDefinition; import org.eclipse.jpt.jpa.core.internal.context.AbstractJpaContextNode; import org.eclipse.jpt.jpa.core.internal.jpa2.context.orm.GenericOrmXml2_0Definition; +import org.eclipse.jpt.jpa.core.internal.jpa2.context.orm.GenericOrmXml2_1Definition; import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; +import org.eclipse.jpt.jpa.core.jpa2_1.context.orm.OrmXml2_1ContextNodeFactory; /** * Use this abstract class for context nodes that are part of an @@ -56,6 +58,10 @@ public abstract class AbstractOrmXmlContextNode return this.getResourceType().isKindOf(GenericOrmXml2_0Definition.instance().getResourceType()); } + protected boolean isOrmXml2_1Compatible() { + return this.getResourceType().isKindOf(GenericOrmXml2_1Definition.instance().getResourceType()); + } + /** * Call {@link #isOrmXml2_0Compatible()} before calling this method. */ @@ -63,6 +69,13 @@ public abstract class AbstractOrmXmlContextNode return (OrmXml2_0ContextNodeFactory) this.getContextNodeFactory(); } + /** + * Call {@link #isOrmXml2_1Compatible()} before calling this method. + */ + protected OrmXml2_1ContextNodeFactory getContextNodeFactory2_1() { + return (OrmXml2_1ContextNodeFactory) this.getContextNodeFactory(); + } + protected OrmXmlContextNodeFactory getContextNodeFactory() { return this.getMappingFileDefinition().getContextNodeFactory(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java index 3b492ec5e5..ccf3ad4202 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Oracle. All rights reserved. + * Copyright (c) 2009, 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. @@ -16,10 +16,12 @@ import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMappingDefinition; +import org.eclipse.jpt.jpa.core.context.orm.OrmManagedTypeDefinition; import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition; import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory; import org.eclipse.jpt.jpa.core.context.orm.OrmXmlDefinition; import org.eclipse.jpt.jpa.core.context.orm.UnsupportedOrmAttributeMappingDefinition; +import org.eclipse.jpt.jpa.core.resource.orm.XmlManagedType; /** * All the state in the definition should be "static" @@ -30,6 +32,8 @@ public abstract class AbstractOrmXmlDefinition { protected final OrmXmlContextNodeFactory factory; + protected ArrayList<OrmManagedTypeDefinition> managedTypeDefinitions; + protected ArrayList<OrmTypeMappingDefinition> typeMappingDefinitions; protected ArrayList<OrmAttributeMappingDefinition> attributeMappingDefinitions; @@ -52,6 +56,47 @@ public abstract class AbstractOrmXmlDefinition return this.factory; } + // ********** managed type definitions ********** + + public OrmManagedTypeDefinition getManagedTypeDefinition(Class<? extends XmlManagedType> resourceType) { + for (OrmManagedTypeDefinition definition : this.getManagedTypeDefinitions()) { + if (definition.getResourceType() == resourceType) { + return definition; + } + } + throw new IllegalArgumentException("Illegal managed type resource type: " + resourceType); //$NON-NLS-1$ + } + + /** + * Return a list of mapping definitions to use for types in + * <code>orm.xml</code> mapping files. + * The order is unimportant. + */ + protected synchronized ArrayList<OrmManagedTypeDefinition> getManagedTypeDefinitions() { + if (this.managedTypeDefinitions == null) { + this.managedTypeDefinitions = this.buildManagedTypeDefinitions(); + } + return this.managedTypeDefinitions; + } + + protected ArrayList<OrmManagedTypeDefinition> buildManagedTypeDefinitions() { + ArrayList<OrmManagedTypeDefinition> definitions = new ArrayList<OrmManagedTypeDefinition>(); + this.addManagedTypeDefinitionsTo(definitions); + return definitions; + } + + protected void addManagedTypeDefinitionsTo(ArrayList<OrmManagedTypeDefinition> definitions) { + CollectionTools.addAll(definitions, MANAGED_TYPE_DEFINITIONS); + } + + /** + * Order should not matter here; but we'll use the same order as for Java. + * @see org.eclipse.jpt.jpa.core.internal.GenericJpaPlatformProvider + */ + protected static final OrmManagedTypeDefinition[] MANAGED_TYPE_DEFINITIONS = new OrmManagedTypeDefinition[] { + OrmPersistentTypeDefinition.instance(), + }; + // ********** type mapping definitions ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/OrmPersistentTypeDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/OrmPersistentTypeDefinition.java new file mode 100644 index 0000000000..c3de65cba1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/OrmPersistentTypeDefinition.java @@ -0,0 +1,52 @@ +/*******************************************************************************
+ * 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 org.eclipse.jpt.jpa.core.context.JpaContextNode;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.orm.OrmManagedType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmManagedTypeDefinition;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlManagedType;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
+
+public class OrmPersistentTypeDefinition
+ implements OrmManagedTypeDefinition
+{
+ // singleton
+ private static final OrmManagedTypeDefinition INSTANCE = new OrmPersistentTypeDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static OrmManagedTypeDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Enforce singleton usage
+ */
+ private OrmPersistentTypeDefinition() {
+ super();
+ }
+
+ public Class<? extends OrmPersistentType> getContextType() {
+ return OrmPersistentType.class;
+ }
+
+ public Class<? extends XmlManagedType> getResourceType() {
+ return XmlTypeMapping.class;
+ }
+
+ public OrmManagedType buildContextManagedType(JpaContextNode parent, XmlManagedType resourceManagedType, OrmXmlContextNodeFactory factory) {
+ return factory.buildOrmPersistentType((EntityMappings) parent, (XmlTypeMapping) resourceManagedType);
+ }
+}
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 eac7b8d80a..1aeb24c7d5 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 @@ -28,9 +28,7 @@ import org.eclipse.jpt.common.core.utility.BodySourceWriter; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.core.utility.jdt.TypeBinding; import org.eclipse.jpt.common.utility.filter.Filter; -import org.eclipse.jpt.common.utility.internal.ClassNameTools; import org.eclipse.jpt.common.utility.internal.ObjectTools; -import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.collection.CollectionTools; import org.eclipse.jpt.common.utility.internal.collection.ListTools; import org.eclipse.jpt.common.utility.internal.filter.FilterAdapter; @@ -45,6 +43,7 @@ import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute; 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; import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMapping; @@ -58,15 +57,13 @@ 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.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelSourceType; import org.eclipse.jpt.jpa.core.jpa2.context.PersistentType2_0; import org.eclipse.jpt.jpa.core.resource.orm.Attributes; import org.eclipse.jpt.jpa.core.resource.orm.OrmPackage; import org.eclipse.jpt.jpa.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages; -import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -81,15 +78,11 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; * </ul> */ public abstract class SpecifiedOrmPersistentType - extends AbstractOrmXmlContextNode + extends AbstractOrmManagedType implements OrmPersistentType, PersistentType2_0 { protected OrmTypeMapping mapping; // never null - protected String name; - - protected JavaPersistentType javaPersistentType; - protected AccessType specifiedAccess; protected AccessType defaultAccess; // never null @@ -108,10 +101,8 @@ public abstract class SpecifiedOrmPersistentType protected SpecifiedOrmPersistentType(EntityMappings parent, XmlTypeMapping xmlTypeMapping) { - super(parent); + super(parent, xmlTypeMapping); this.mapping = this.buildMapping(xmlTypeMapping); - this.name = this.buildName(); - // 'javaPersistentType' is resolved in the update this.specifiedAccess = this.buildSpecifiedAccess(); this.defaultAccess = AccessType.FIELD; // keep this non-null this.initializeSpecifiedAttributes(); @@ -126,8 +117,6 @@ public abstract class SpecifiedOrmPersistentType public void synchronizeWithResourceModel() { super.synchronizeWithResourceModel(); this.mapping.synchronizeWithResourceModel(); - this.setName(this.buildName()); - this.syncJavaPersistentType(); this.setSpecifiedAccess_(this.buildSpecifiedAccess()); this.syncSpecifiedAttributes(); this.synchronizeNodesWithResourceModel(this.getDefaultAttributes()); @@ -137,7 +126,6 @@ public abstract class SpecifiedOrmPersistentType public void update() { super.update(); this.mapping.update(); - this.updateJavaPersistentType(); this.setDefaultAccess(this.buildDefaultAccess()); this.updateNodes(this.getSpecifiedAttributes()); this.updateDefaultAttributes(); @@ -146,10 +134,9 @@ public abstract class SpecifiedOrmPersistentType this.updateChildren(); } - public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) { - if (this.javaPersistentType != null) { - this.javaPersistentType.gatherRootStructureNodes(jpaFile, rootStructureNodes); - } + @Override + public XmlTypeMapping getXmlManagedType() { + return (XmlTypeMapping) super.getXmlManagedType(); } @@ -172,8 +159,10 @@ public abstract class SpecifiedOrmPersistentType protected void setMappingKey_(String mappingKey) { OrmTypeMapping old = this.mapping; OrmTypeMappingDefinition mappingDefinition = this.getMappingFileDefinition().getTypeMappingDefinition(mappingKey); - XmlTypeMapping xmlTypeMapping = mappingDefinition.buildResourceMapping(this.getResourceNodeFactory()); - this.mapping = this.buildMapping(xmlTypeMapping); + String className = this.getClass_(); + this.xmlManagedType = mappingDefinition.buildResourceMapping(this.getResourceNodeFactory()); + this.xmlManagedType.setClassName(className); + this.mapping = this.buildMapping(this.getXmlTypeMapping()); this.getEntityMappings().changeMapping(this, old, this.mapping); this.firePropertyChanged(MAPPING_PROPERTY, old, this.mapping); } @@ -184,7 +173,7 @@ public abstract class SpecifiedOrmPersistentType } protected XmlTypeMapping getXmlTypeMapping() { - return this.mapping.getXmlTypeMapping(); + return this.getXmlManagedType(); } public boolean isMapped() { @@ -192,115 +181,14 @@ public abstract class SpecifiedOrmPersistentType } - // ********** name ********** - - public String getName() { - return this.name; - } - - protected void setName(String name) { - String old = this.name; - this.name = name; - if (this.firePropertyChanged(NAME_PROPERTY, old, name)) { - // clear out the Java persistent type here, it will be rebuilt during "update" - if (this.javaPersistentType != null) { - this.setJavaPersistentType(null); - } - } - } - - protected String buildName() { - return this.getEntityMappings().qualify(this.getMappingClassName()); - } - - public String getSimpleName(){ - String className = this.getName(); - return StringTools.isBlank(className) ? null : ClassNameTools.simpleName(className); - } - - public String getTypeQualifiedName() { - String className = this.getMappingClassName(); - if (className == null) { - return null; - } - int lastPeriod = className.lastIndexOf('.'); - className = (lastPeriod == -1) ? className : className.substring(lastPeriod + 1); - className = className.replace('$', '.'); - return className; - } - - protected String getMappingClassName() { - return this.mapping.getClass_(); - } - // ********** Java persistent type ********** public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType javaPersistentType) { - JavaPersistentType old = this.javaPersistentType; - this.javaPersistentType = javaPersistentType; - this.firePropertyChanged(JAVA_PERSISTENT_TYPE_PROPERTY, old, javaPersistentType); + return (JavaPersistentType) super.getJavaManagedType(); } - /** - * If the persistent type's name changes during <em>update</em>, - * the Java persistent type will be cleared out in - * {@link #setName(String)}. If we get here and - * the Java persistent type is present, we can - * <em>sync</em> it. In some circumstances it will be obsolete - * since the name is changed during update (the mapping class name or - * the entity mapping's package affect the name) - * - * @see #updateJavaPersistentType() - */ - protected void syncJavaPersistentType() { - if (this.javaPersistentType != null) { - this.javaPersistentType.synchronizeWithResourceModel(); - } - } - - /** - * @see #syncJavaPersistentType() - */ - protected void updateJavaPersistentType() { - if (this.getName() == null) { - if (this.javaPersistentType != null) { - this.setJavaPersistentType(null); - } - } - else { - JavaResourceType resourceType = this.resolveJavaResourceType(); - if (this.javaPersistentType == null) { - this.setJavaPersistentType(this.buildJavaPersistentType(resourceType)); - } - else { - // bug 379051 using == here because it is possible that the names are the same, - // but the location has changed: the java resource type has moved from "external" - // to part of the jpa project's jpa files. - if (this.javaPersistentType.getJavaResourceType() == resourceType) { - this.javaPersistentType.update(); - } else { - this.setJavaPersistentType(this.buildJavaPersistentType(resourceType)); - } - } - } - } - - /** - * Return null it's an enum; don't build a JavaPersistentType - * @see #updateJavaPersistentType() - */ - protected JavaResourceType resolveJavaResourceType() { - if (this.name == null) { - return null; - } - return (JavaResourceType) this.getJpaProject().getJavaResourceType(this.name, AstNodeType.TYPE); - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourceType jrt) { + @Override + protected JavaManagedType buildJavaManagedType(JavaResourceType jrt) { return jrt != null ? this.getJpaFactory().buildJavaPersistentType(this, jrt) : null; } @@ -342,9 +230,9 @@ public abstract class SpecifiedOrmPersistentType protected AccessType buildDefaultAccess() { if ( ! this.mapping.isMetadataComplete()) { - if (this.javaPersistentType != null) { + if (this.getJavaPersistentType() != null) { if (this.javaPersistentTypeHasSpecifiedAccess()) { - return this.javaPersistentType.getAccess(); + return this.getJavaPersistentType().getAccess(); } } if (this.superPersistentType != null) { @@ -359,8 +247,8 @@ public abstract class SpecifiedOrmPersistentType * pre-condition: {@link #javaPersistentType} is not <code>null</code> */ protected boolean javaPersistentTypeHasSpecifiedAccess() { - return (this.javaPersistentType.getSpecifiedAccess() != null) || - this.javaPersistentType.hasAnyAnnotatedAttributes(); + return (this.getJavaPersistentType().getSpecifiedAccess() != null) || + this.getJavaPersistentType().hasAnyAnnotatedAttributes(); } public AccessType getOwnerOverrideAccess() { @@ -419,7 +307,7 @@ public abstract class SpecifiedOrmPersistentType } public TypeBinding getAttributeTypeBinding(ReadOnlyPersistentAttribute attribute) { - return (this.javaPersistentType == null) ? null : this.javaPersistentType.getAttributeTypeBinding(attribute); + return (this.getJavaPersistentType() == null) ? null : this.getJavaPersistentType().getAttributeTypeBinding(attribute); } @@ -908,10 +796,6 @@ public abstract class SpecifiedOrmPersistentType }; } - protected JavaResourceType getJavaResourceType() { - return (this.javaPersistentType == null) ? null : this.javaPersistentType.getJavaResourceType(); - } - /** * Return the access type that determines which Java attributes are to be * used for the <code>orm.xml</code> type's <em>default</em> attributes. @@ -923,7 +807,7 @@ public abstract class SpecifiedOrmPersistentType if (this.mapping.isMetadataComplete()) { return this.defaultAccess; } - AccessType javaAccess = this.javaPersistentType == null ? null : this.javaPersistentType.getSpecifiedAccess(); + AccessType javaAccess = this.getJavaPersistentType() == null ? null : this.getJavaPersistentType().getSpecifiedAccess(); return (javaAccess != null) ? javaAccess : this.defaultAccess; } @@ -1023,7 +907,7 @@ public abstract class SpecifiedOrmPersistentType } protected PersistentType buildSuperPersistentType_() { - return (this.javaPersistentType == null) ? null : this.javaPersistentType.getSuperPersistentType(); + return (this.getJavaPersistentType() == null) ? null : this.getJavaPersistentType().getSuperPersistentType(); } @@ -1060,8 +944,8 @@ public abstract class SpecifiedOrmPersistentType } protected String buildDeclaringTypeName_() { - return (this.javaPersistentType == null) ? - null : ((PersistentType2_0) this.javaPersistentType).getDeclaringTypeName(); + return (this.getJavaPersistentType() == null) ? + null : ((PersistentType2_0) this.getJavaPersistentType()).getDeclaringTypeName(); } @@ -1074,7 +958,7 @@ public abstract class SpecifiedOrmPersistentType } public IFile getMetamodelFile() { - return (this.javaPersistentType == null) ? null : this.metamodelSynchronizer.getFile(); + return (this.getJavaPersistentType() == null) ? null : this.metamodelSynchronizer.getFile(); } public void initializeMetamodel() { @@ -1090,13 +974,13 @@ public abstract class SpecifiedOrmPersistentType * because 1.0 <code>orm.xml</code> files can be referenced from 2.0 persistence.xml files. */ public void synchronizeMetamodel(Map<String, Collection<MetamodelSourceType>> memberTypeTree) { - if (this.javaPersistentType != null) { + if (this.getJavaPersistentType() != null) { this.metamodelSynchronizer.synchronize(memberTypeTree); } } public void printBodySourceOn(BodySourceWriter pw, Map<String, Collection<MetamodelSourceType>> memberTypeTree) { - if (this.javaPersistentType != null) { + if (this.getJavaPersistentType() != null) { this.metamodelSynchronizer.printBodySourceOn(pw, memberTypeTree); } } @@ -1110,6 +994,21 @@ public abstract class SpecifiedOrmPersistentType } + // ********** OrmManagedType implementation ********** + + public int getXmlSequence() { + return this.getMapping().getXmlSequence(); + } + + public void addXmlManagedTypeTo(XmlEntityMappings entityMappings) { + this.getMapping().addXmlTypeMappingTo(entityMappings); + } + + public void removeXmlManagedTypeFrom(XmlEntityMappings entityMappings) { + this.getMapping().removeXmlTypeMappingFrom(entityMappings); + } + + // ********** JpaStructureNode implementation ********** public ContextType getContextType() { @@ -1120,6 +1019,12 @@ public abstract class SpecifiedOrmPersistentType return OrmPersistentType.class; } + public void gatherRootStructureNodes(JpaFile jpaFile, Collection<JpaStructureNode> rootStructureNodes) { + if (this.getJavaPersistentType() != null) { + this.getJavaPersistentType().gatherRootStructureNodes(jpaFile, rootStructureNodes); + } + } + protected void initializeChildren() { this.children.addAll(this.specifiedAttributes); //defaultAttributes haven't been built yet } @@ -1139,12 +1044,9 @@ public abstract class SpecifiedOrmPersistentType return this.children.size(); } - public TextRange getFullTextRange() { - return this.getXmlTypeMapping().getFullTextRange(); - } - public boolean containsOffset(int textOffset) { - return this.getXmlTypeMapping().containsOffset(textOffset); + public TextRange getSelectionTextRange() { + return this.mapping.getSelectionTextRange(); } public JpaStructureNode getStructureNode(int textOffset) { @@ -1156,10 +1058,6 @@ public abstract class SpecifiedOrmPersistentType return this; } - public TextRange getSelectionTextRange() { - return this.mapping.getSelectionTextRange(); - } - public void dispose() { for (OrmReadOnlyPersistentAttribute defaultAttribute : this.getDefaultAttributes()) { defaultAttribute.dispose(); @@ -1206,15 +1104,11 @@ public abstract class SpecifiedOrmPersistentType //*********** refactoring *********** - public Iterable<DeleteEdit> createDeleteTypeEdits(IType type) { - return this.isFor(type.getFullyQualifiedName('.')) ? - IterableTools.singletonIterable(this.mapping.createDeleteEdit()) : - IterableTools.<DeleteEdit>emptyIterable(); - } - + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) { return IterableTools.concatenate( + super.createRenameTypeEdits(originalType, newName), this.mapping.createRenameTypeEdits(originalType, newName), this.createSpecifiedAttributesRenameTypeEdits(originalType, newName) ); @@ -1224,9 +1118,11 @@ public abstract class SpecifiedOrmPersistentType return IterableTools.children(this.getSpecifiedAttributes(), new TypeRefactoringParticipant.RenameTypeEditsTransformer(originalType, newName)); } + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) { return IterableTools.concatenate( + super.createMoveTypeEdits(originalType, newPackage), this.mapping.createMoveTypeEdits(originalType, newPackage), this.createSpecifiedAttributesMoveTypeEdits(originalType, newPackage) ); @@ -1236,9 +1132,11 @@ public abstract class SpecifiedOrmPersistentType return IterableTools.children(this.getSpecifiedAttributes(), new TypeRefactoringParticipant.MoveTypeEditsTransformer(originalType, newPackage)); } + @Override @SuppressWarnings("unchecked") public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) { return IterableTools.concatenate( + super.createRenamePackageEdits(originalPackage, newName), this.mapping.createRenamePackageEdits(originalPackage, newName), this.createSpecifiedAttributesRenamePackageEdits(originalPackage, newName) ); @@ -1254,25 +1152,10 @@ public abstract class SpecifiedOrmPersistentType @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validateClass(messages); this.validateMapping(messages, reporter); this.validateAttributes(messages, reporter); } - protected void validateClass(List<IMessage> messages) { - if (this.javaPersistentType == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JptJpaCoreValidationMessages.PERSISTENT_TYPE_UNRESOLVED_CLASS, - new String[] {this.getName()}, - this, - this.mapping.getClassTextRange() - ) - ); - } - } - protected void validateMapping(List<IMessage> messages, IReporter reporter) { try { this.mapping.validate(messages, reporter); @@ -1295,10 +1178,6 @@ public abstract class SpecifiedOrmPersistentType } } - public TextRange getValidationTextRange() { - return this.mapping.getValidationTextRange(); - } - // ********** completion proposals ********** @Override @@ -1320,48 +1199,10 @@ public abstract class SpecifiedOrmPersistentType return null; } - // ********** misc ********** - - @Override - public EntityMappings getParent() { - return (EntityMappings) super.getParent(); - } - - protected EntityMappings getEntityMappings() { - return this.getParent(); - } - - public String getDefaultPackage() { - return this.getEntityMappings().getDefaultPersistentTypePackage(); - } - - public boolean isFor(String typeName) { - return ObjectTools.equals(typeName, this.getName()); - } - - public boolean isIn(IPackageFragment packageFragment) { - String packageName = this.getPackageName(); - if (ObjectTools.equals(packageName, packageFragment.getElementName())) { - return true; - } - return false; - } - protected String getPackageName() { - String className = this.getMappingClassName(); - if (className == null) { - return null; - } - int lastPeriod = className.lastIndexOf('.'); - return (lastPeriod == -1) ? this.getDefaultPackage() : className.substring(0, lastPeriod); - } + // ********** misc ********** public PersistentType getOverriddenPersistentType() { - return this.mapping.isMetadataComplete() ? null : this.javaPersistentType; - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); + return this.mapping.isMetadataComplete() ? null : this.getJavaPersistentType(); } } |