diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm')
89 files changed, 0 insertions, 16602 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java deleted file mode 100644 index 8a17c88245..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java +++ /dev/null @@ -1,822 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.MappingFileRoot; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * <code>orm.xml</code> file - * <br> - * <code>entity-mappings</code> element - */ -public abstract class AbstractEntityMappings - extends AbstractOrmXmlContextNode - implements EntityMappings -{ - protected final XmlEntityMappings xmlEntityMappings; - - protected String description; - - protected String package_; - - protected AccessType specifiedAccess; - protected AccessType defaultAccess; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected final PersistenceUnitMetadata persistenceUnitMetadata; - - protected final List<OrmPersistentType> persistentTypes; - - protected final List<OrmSequenceGenerator> sequenceGenerators; - - protected final List<OrmTableGenerator> tableGenerators; - - protected final OrmQueryContainer queryContainer; - - - protected AbstractEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.xmlEntityMappings = xmlEntityMappings; - this.persistentTypes = new ArrayList<OrmPersistentType>(); - this.sequenceGenerators = new ArrayList<OrmSequenceGenerator>(); - this.tableGenerators = new ArrayList<OrmTableGenerator>(); - this.queryContainer = this.getXmlContextNodeFactory().buildOrmQueryContainer(this, xmlEntityMappings); - - this.persistenceUnitMetadata = this.buildPersistenceUnitMetadata(); - this.description = this.xmlEntityMappings.getDescription(); - this.package_ = this.xmlEntityMappings.getPackage(); - - this.defaultAccess = this.getPersistenceUnit().getDefaultAccess(); - this.specifiedAccess = this.getResourceAccess(); - - this.defaultCatalog = this.getPersistenceUnit().getDefaultCatalog(); - this.specifiedCatalog = this.xmlEntityMappings.getCatalog(); - - this.defaultSchema = this.getPersistenceUnit().getDefaultSchema(); - this.specifiedSchema = this.xmlEntityMappings.getSchema(); - - this.initializePersistentTypes(); - this.initializeTableGenerators(); - this.initializeSequenceGenerators(); - } - - protected PersistenceUnitMetadata buildPersistenceUnitMetadata() { - return this.getXmlContextNodeFactory().buildPersistenceUnitMetadata(this); - } - - protected OrmPersistentType buildPersistentType(XmlTypeMapping resourceMapping) { - return this.getXmlContextNodeFactory().buildOrmPersistentType(this, resourceMapping); - } - - // **************** JpaNode impl ******************************************* - - @Override - public OrmXml getParent() { - return (OrmXml) super.getParent(); - } - - protected OrmXml getOrmXml() { - return this.getParent(); - } - - - // **************** JpaContextNode impl ************************************ - - @Override - public MappingFileRoot getMappingFileRoot() { - return this; - } - - - // **************** JpaStructureNode impl ********************************** - - public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; - } - - - // ********** PersistentType.Owner implementation ********** - - public AccessType getOverridePersistentTypeAccess() { - return this.isXmlMappingMetadataComplete() ? this.getSpecifiedAccess() : null; - } - - public AccessType getDefaultPersistentTypeAccess() { - return getAccess(); - } - - public String getDefaultPersistentTypePackage() { - return getPackage(); - } - - protected boolean isXmlMappingMetadataComplete() { - return this.persistenceUnitMetadata.isXmlMappingMetadataComplete(); - } - - public boolean isDefaultPersistentTypeMetadataComplete() { - return this.isXmlMappingMetadataComplete(); - } - - - // **************** EntityMappings impl ************************************ - - public XmlEntityMappings getXmlEntityMappings() { - return this.xmlEntityMappings; - } - - public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { - AccessType savedAccess = ormPersistentType.getSpecifiedAccess(); - ormPersistentType.dispose(); - int sourceIndex = this.persistentTypes.indexOf(ormPersistentType); - this.persistentTypes.remove(sourceIndex); - oldMapping.removeFromResourceModel(this.xmlEntityMappings); - int targetIndex = insertionIndex(ormPersistentType); - this.persistentTypes.add(targetIndex, ormPersistentType); - newMapping.addToResourceModel(this.xmlEntityMappings); - - newMapping.initializeFrom(oldMapping); - //not sure where else to put this, need to set the access on the resource model - ormPersistentType.setSpecifiedAccess(savedAccess); - fireItemMoved(PERSISTENT_TYPES_LIST, targetIndex, sourceIndex); - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - if (ormPersistentType.isFor(fullyQualifiedTypeName)) { - return ormPersistentType; - } - } - return null; - } - - public boolean containsPersistentType(String fullyQualifiedTypeName) { - return getPersistentType(fullyQualifiedTypeName) != null; - } - - public PersistentType resolvePersistentType(String className) { - if (className == null) { - return null; - } - - //static inner class listed in orm.xml will use '$', replace with '.' - className = className.replace('$', '.'); - - // first try to resolve using only the locally specified name... - PersistentType mapKeyPersistentType = getPersistenceUnit().getPersistentType(className); - if (mapKeyPersistentType != null) { - return mapKeyPersistentType; - } - - // ...then try to resolve by prepending the global package name - if (getPackage() == null) { - return null; - } - return getPersistenceUnit().getPersistentType(getPackage() + '.' + className); - } - - public JavaResourcePersistentType resolveJavaResourcePersistentType(String className) { - if (className == null) { - return null; - } - - //static inner class listed in orm.xml will use '$', replace with '.' - className = className.replace('$', '.'); - - // first try to resolve using only the locally specified name... - JavaResourcePersistentType jrpt = getJpaProject().getJavaResourcePersistentType(className); - if (jrpt != null) { - return jrpt; - } - - // ...then try to resolve by prepending the global package name - if (getPackage() == null) { - return null; - } - return getJpaProject().getJavaResourcePersistentType(getPackage() + '.' + className); - } - - public PersistenceUnitMetadata getPersistenceUnitMetadata() { - return this.persistenceUnitMetadata; - } - - public String getPackage() { - return this.package_; - } - - public void setPackage(String newPackage) { - String oldPackage = this.package_; - this.package_ = newPackage; - this.xmlEntityMappings.setPackage(newPackage); - firePropertyChanged(PACKAGE_PROPERTY, oldPackage, newPackage); - } - - public String getVersion() { - return this.xmlEntityMappings.getVersion(); - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String newDescription) { - String oldDescription = this.description; - this.description = newDescription; - this.xmlEntityMappings.setDescription(newDescription); - firePropertyChanged(DESCRIPTION_PROPERTY, oldDescription, newDescription); - } - - - // ********** access ********** - - public AccessType getAccess() { - return (this.specifiedAccess != null) ? this.specifiedAccess : this.defaultAccess; - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType access) { - AccessType old = this.specifiedAccess; - this.specifiedAccess = access; - this.xmlEntityMappings.setAccess(AccessType.toOrmResourceModel(access)); - this.firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, old, access); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType access) { - AccessType old = this.defaultAccess; - this.defaultAccess = access; - this.firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, access); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.xmlEntityMappings.setSchema(schema); - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - this.xmlEntityMappings.setCatalog(catalog); - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String catalog) { - String old = this.defaultCatalog; - this.defaultCatalog = catalog; - this.firePropertyChanged(DEFAULT_CATALOG_PROPERTY, old, catalog); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - - // ********** schema container ********** - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - - // ********** ORM persistent types ********** - - public ListIterator<OrmPersistentType> persistentTypes() { - return new CloneListIterator<OrmPersistentType>(this.persistentTypes); - } - - public ListIterable<OrmPersistentType> getPersistentTypes() { - return new LiveCloneListIterable<OrmPersistentType>(this.persistentTypes); - } - - public int getPersistentTypesSize() { - return this.persistentTypes.size(); - } - - public OrmPersistentType addPersistentType(String mappingKey, String className) { - OrmTypeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmTypeMappingDefinition(mappingKey); - XmlTypeMapping typeMapping = - mappingDefinition.buildResourceMapping(getResourceNodeFactory()); - OrmPersistentType persistentType = buildPersistentType(typeMapping); - int index = insertionIndex(persistentType); - this.persistentTypes.add(index, persistentType); - if (className.startsWith(getPackage() + '.')) { - // adds short name if package name is specified - className = className.substring(getPackage().length() + 1); - } - persistentType.getMapping().addToResourceModel(this.xmlEntityMappings); - typeMapping.setClassName(className); - fireItemAdded(PERSISTENT_TYPES_LIST, index, persistentType); - return persistentType; - } - - protected int insertionIndex(OrmPersistentType ormPersistentType) { - return CollectionTools.insertionIndexOf(this.persistentTypes, ormPersistentType, 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(); - if (o1Sequence < o2Sequence) { - return -1; - } - if (o1Sequence == o2Sequence) { - return 0; - } - return 1; - } - }; - - public void removePersistentType(int index) { - OrmPersistentType persistentType = this.persistentTypes.get(index); - persistentType.dispose(); - this.persistentTypes.remove(index); - persistentType.getMapping().removeFromResourceModel(this.xmlEntityMappings); - fireItemRemoved(PERSISTENT_TYPES_LIST, index, persistentType); - } - - public void removePersistentType(OrmPersistentType persistentType) { - removePersistentType(this.persistentTypes.indexOf(persistentType)); - } - - protected void removePersistentType_(OrmPersistentType persistentType) { - persistentType.dispose(); - removeItemFromList(persistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - protected void movePersistentType_(int index, OrmPersistentType persistentType) { - moveItemInList(index, this.persistentTypes.indexOf(persistentType), this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - - // ********** sequence generators ********** - - public ListIterable<OrmSequenceGenerator> getSequenceGenerators() { - return new LiveCloneListIterable<OrmSequenceGenerator>(this.sequenceGenerators); - } - - public int getSequenceGeneratorsSize() { - return this.sequenceGenerators.size(); - } - - public OrmSequenceGenerator addSequenceGenerator(int index) { - XmlSequenceGenerator resourceSequenceGenerator = this.buildResourceSequenceGenerator(); - OrmSequenceGenerator contextSequenceGenerator = this.buildSequenceGenerator(resourceSequenceGenerator); - this.sequenceGenerators.add(index, contextSequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().add(index, resourceSequenceGenerator); - fireItemAdded(SEQUENCE_GENERATORS_LIST, index, contextSequenceGenerator); - return contextSequenceGenerator; - } - - protected void addSequenceGenerator(int index, OrmSequenceGenerator sequenceGenerator) { - addItemToList(index, sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - protected void addSequenceGenerator(OrmSequenceGenerator sequenceGenerator) { - this.addSequenceGenerator(this.sequenceGenerators.size(), sequenceGenerator); - } - - public void removeSequenceGenerator(OrmSequenceGenerator sequenceGenerator) { - removeSequenceGenerator(this.sequenceGenerators.indexOf(sequenceGenerator)); - } - - public void removeSequenceGenerator(int index) { - OrmSequenceGenerator removedSequenceGenerator = this.sequenceGenerators.remove(index); - fireItemRemoved(SEQUENCE_GENERATORS_LIST, index, removedSequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().remove(index); - } - - protected void removeSequenceGenerator_(OrmSequenceGenerator sequenceGenerator) { - removeItemFromList(sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - public void moveSequenceGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.sequenceGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getSequenceGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.SEQUENCE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - protected XmlSequenceGenerator buildResourceSequenceGenerator() { - return OrmFactory.eINSTANCE.createXmlSequenceGenerator(); - } - - // ********** table generators ********** - - public ListIterable<OrmTableGenerator> getTableGenerators() { - return new LiveCloneListIterable<OrmTableGenerator>(this.tableGenerators); - } - - public int getTableGeneratorsSize() { - return this.tableGenerators.size(); - } - - public OrmTableGenerator addTableGenerator(int index) { - XmlTableGenerator resourceTableGenerator = buildResourceTableGenerator(); - OrmTableGenerator contextTableGenerator = buildTableGenerator(resourceTableGenerator); - this.tableGenerators.add(index, contextTableGenerator); - this.xmlEntityMappings.getTableGenerators().add(index, resourceTableGenerator); - fireItemAdded(TABLE_GENERATORS_LIST, index, contextTableGenerator); - return contextTableGenerator; - } - - protected void addTableGenerator(int index, OrmTableGenerator tableGenerator) { - addItemToList(index, tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - protected void addTableGenerator(OrmTableGenerator tableGenerator) { - this.addTableGenerator(this.tableGenerators.size(), tableGenerator); - } - - public void removeTableGenerator(OrmTableGenerator tableGenerator) { - removeTableGenerator(this.tableGenerators.indexOf(tableGenerator)); - } - - public void removeTableGenerator(int index) { - OrmTableGenerator removedTableGenerator = this.tableGenerators.remove(index); - this.xmlEntityMappings.getTableGenerators().remove(index); - fireItemRemoved(TABLE_GENERATORS_LIST, index, removedTableGenerator); - } - - protected void removeTableGenerator_(OrmTableGenerator tableGenerator) { - removeItemFromList(tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - public void moveTableGenerator(int targetIndex, int sourceIndex) { - CollectionTools.move(this.tableGenerators, targetIndex, sourceIndex); - this.xmlEntityMappings.getTableGenerators().move(targetIndex, sourceIndex); - fireItemMoved(EntityMappings.TABLE_GENERATORS_LIST, targetIndex, sourceIndex); - } - - protected XmlTableGenerator buildResourceTableGenerator() { - return OrmFactory.eINSTANCE.createXmlTableGenerator(); - } - - - // ********** named queries ********** - public OrmQueryContainer getQueryContainer() { - return this.queryContainer; - } - - - // ********** misc ********** - - public OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { - return this.persistenceUnitMetadata.getPersistenceUnitDefaults(); - } - - - // ********** initialization ********** - - protected void initializePersistentTypes() { - for (XmlTypeMapping typeMapping : this.xmlEntityMappings.getTypeMappings()) { - addPersistentType(typeMapping); - } - } - - protected void initializeTableGenerators() { - for (XmlTableGenerator tableGenerator : this.xmlEntityMappings.getTableGenerators()) { - this.tableGenerators.add(buildTableGenerator(tableGenerator)); - } - } - - protected void initializeSequenceGenerators() { - for (XmlSequenceGenerator sequenceGenerator : this.xmlEntityMappings.getSequenceGenerators()) { - this.sequenceGenerators.add(buildSequenceGenerator(sequenceGenerator)); - } - } - - - // ********** update ********** - - public void update() { - this.setDescription(this.xmlEntityMappings.getDescription()); - this.setPackage(this.xmlEntityMappings.getPackage()); - - this.setDefaultAccess(this.getPersistenceUnit().getDefaultAccess()); - this.setSpecifiedAccess(this.getResourceAccess()); - - this.setDefaultCatalog(this.getPersistenceUnit().getDefaultCatalog()); - this.setSpecifiedCatalog(this.xmlEntityMappings.getCatalog()); - - this.setDefaultSchema(this.getPersistenceUnit().getDefaultSchema()); - this.setSpecifiedSchema(this.xmlEntityMappings.getSchema()); - - this.persistenceUnitMetadata.update(); - this.updatePersistentTypes(); - this.updateTableGenerators(); - this.updateSequenceGenerators(); - getQueryContainer().update(); - } - - protected AccessType getResourceAccess() { - return AccessType.fromOrmResourceModel(this.xmlEntityMappings.getAccess()); - } - - protected void updatePersistentTypes() { - Collection<OrmPersistentType> contextTypesToRemove = CollectionTools.collection(persistentTypes()); - Collection<OrmPersistentType> contextTypesToUpdate = new ArrayList<OrmPersistentType>(); - int resourceIndex = 0; - - List<XmlTypeMapping> xmlTypeMappings = this.xmlEntityMappings.getTypeMappings(); - for (XmlTypeMapping xmlTypeMapping : xmlTypeMappings.toArray(new XmlTypeMapping[xmlTypeMappings.size()])) { - boolean contextAttributeFound = false; - for (OrmPersistentType contextType : contextTypesToRemove) { - if (contextType.getMapping().getResourceTypeMapping() == xmlTypeMapping) { - movePersistentType_(resourceIndex, contextType); - contextTypesToRemove.remove(contextType); - contextTypesToUpdate.add(contextType); - contextAttributeFound = true; - break; - } - } - if (!contextAttributeFound) { - OrmPersistentType ormPersistentType = addPersistentType(xmlTypeMapping); - fireItemAdded(PERSISTENT_TYPES_LIST, getPersistentTypesSize(), ormPersistentType); - } - resourceIndex++; - } - for (OrmPersistentType contextType : contextTypesToRemove) { - removePersistentType_(contextType); - } - //first handle adding/removing of the persistent types, then update the others last, - //this causes less churn in the update process - for (OrmPersistentType contextType : contextTypesToUpdate) { - contextType.update(); - } - } - - //not firing change notification so this can be reused in initialize and update - protected OrmPersistentType addPersistentType(XmlTypeMapping resourceMapping) { - OrmPersistentType ormPersistentType = buildPersistentType(resourceMapping); - this.persistentTypes.add(ormPersistentType); - return ormPersistentType; - } - - protected void updateTableGenerators() { - // make a copy of the XML generators (to prevent ConcurrentModificationException) - Iterator<XmlTableGenerator> xmlGenerators = new CloneIterator<XmlTableGenerator>(this.xmlEntityMappings.getTableGenerators()); - - for (OrmTableGenerator contextGenerator : this.getTableGenerators()) { - if (xmlGenerators.hasNext()) { - contextGenerator.update(xmlGenerators.next()); - } else { - this.removeTableGenerator_(contextGenerator); - } - } - - while (xmlGenerators.hasNext()) { - addTableGenerator(buildTableGenerator(xmlGenerators.next())); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator resourceTableGenerator) { - return getXmlContextNodeFactory().buildOrmTableGenerator(this, resourceTableGenerator); - } - - protected void updateSequenceGenerators() { - // make a copy of the XML sequence generators (to prevent ConcurrentModificationException) - Iterator<XmlSequenceGenerator> xmlSequenceGenerators = new CloneIterator<XmlSequenceGenerator>(this.xmlEntityMappings.getSequenceGenerators());//prevent ConcurrentModificiationException - - for (OrmSequenceGenerator contextSequenceGenerator : this.getSequenceGenerators()) { - if (xmlSequenceGenerators.hasNext()) { - contextSequenceGenerator.update(xmlSequenceGenerators.next()); - } - else { - removeSequenceGenerator_(contextSequenceGenerator); - } - } - - while (xmlSequenceGenerators.hasNext()) { - addSequenceGenerator(buildSequenceGenerator(xmlSequenceGenerators.next())); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator resourceSequenceGenerator) { - return getXmlContextNodeFactory().buildOrmSequenceGenerator(this, resourceSequenceGenerator); - } - - @Override - public void postUpdate() { - super.postUpdate(); - for (PersistentType persistentType : this.getPersistentTypes()) { - persistentType.postUpdate(); - } - } - - // ********** text ********** - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentType persistentType: this.getPersistentTypes()) { - if (persistentType.contains(textOffset)) { - return persistentType.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - return (this.xmlEntityMappings != null) && this.xmlEntityMappings.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.xmlEntityMappings.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return null; - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateVersion(messages); - this.validateGenerators(messages); - this.queryContainer.validate(messages, reporter); - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - this.validatePersistentType(ormPersistentType, messages, reporter); - } - } - - protected void validateVersion(List<IMessage> messages) { - if (! latestDocumentVersion().equals(this.xmlEntityMappings.getVersion())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.LOW_SEVERITY, - JpaValidationMessages.XML_VERSION_NOT_LATEST, - this, - this.xmlEntityMappings.getVersionTextRange())); - } - } - - /** - * Return the latest version of the document supported by the platform - */ - protected abstract String latestDocumentVersion(); - - protected void validateGenerators(List<IMessage> messages) { - for (OrmGenerator localGenerator : this.getGenerators()) { - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {localGenerator.getName()}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - } - } - } - } - - /** - * Return all the generators, table and sequence. - */ - @SuppressWarnings("unchecked") - protected Iterable<OrmGenerator> getGenerators() { - return new CompositeIterable<OrmGenerator>( - this.getTableGenerators(), - this.getSequenceGenerators() - ); - } - - - protected void validatePersistentType(OrmPersistentType persistentType, List<IMessage> messages, IReporter reporter) { - try { - persistentType.validate(messages, reporter); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - } - - - // ********** dispose ********** - - public void dispose() { - for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { - ormPersistentType.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java deleted file mode 100644 index de18403841..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAssociationOverrideRelationshipReference.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.AssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnInAssociationOverrideJoiningStrategy; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmAssociationOverrideRelationshipReference extends AbstractOrmXmlContextNode - implements OrmAssociationOverrideRelationshipReference -{ - - // cache the strategy for property change notification - protected JoiningStrategy cachedPredominantJoiningStrategy; - - protected OrmJoinColumnInAssociationOverrideJoiningStrategy joinColumnJoiningStrategy; - - protected AbstractOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, XmlAssociationOverride xao) { - super(parent); - this.initializeJoiningStrategies(xao); - } - - protected OrmJoinColumnInAssociationOverrideJoiningStrategy buildJoinColumnJoiningStrategy(XmlAssociationOverride xao) { - return new GenericOrmJoinColumnInAssociationOverrideJoiningStrategy(this, xao); - } - - public void initializeFrom(AssociationOverrideRelationshipReference oldAssociationOverride) { - if (oldAssociationOverride.getJoinColumnJoiningStrategy().hasSpecifiedJoinColumns()) { - getJoinColumnJoiningStrategy().initializeFrom(oldAssociationOverride.getJoinColumnJoiningStrategy()); - } - } - - @Override - public OrmAssociationOverride getParent() { - return (OrmAssociationOverride) super.getParent(); - } - - public OrmAssociationOverride getAssociationOverride() { - return getParent(); - } - - public TypeMapping getTypeMapping() { - return getAssociationOverride().getOwner().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public boolean isOverridableAssociation() { - return false; - } - - public boolean isParentVirtual() { - return getAssociationOverride().isVirtual(); - } - - public boolean isTargetForeignKeyRelationship() { - return false; - } - - // **************** predominant joining strategy *************************** - - public JoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy(JoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - protected void initialize(XmlAssociationOverride associationOverride) { - initializeJoiningStrategies(associationOverride); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected void initializeJoiningStrategies(XmlAssociationOverride xao) { - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(xao); - } - - public void update(XmlAssociationOverride associationOverride) { - updateJoiningStrategies(associationOverride); - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected void updateJoiningStrategies(XmlAssociationOverride associationOverride) { - this.joinColumnJoiningStrategy.update(associationOverride); - } - - protected abstract JoiningStrategy calculatePredominantJoiningStrategy(); - - // **************** join columns ******************************************* - - - public OrmJoinColumnInAssociationOverrideJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.addStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return false; - } - - public RelationshipMapping getRelationshipMapping() { - return getAssociationOverride().getOwner().getRelationshipMapping(getAssociationOverride().getName()); - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return getRelationshipMapping().isOwnedBy(mapping); - } - - public boolean isRelationshipOwner() { - return getRelationshipMapping().isRelationshipOwner(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - } - - public TextRange getValidationTextRange() { - return getAssociationOverride().getValidationTextRange(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java deleted file mode 100644 index ed650203bb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.jpa2.context.SimpleMetamodelField; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.AttributeMapping2_0; -import org.eclipse.jpt.core.jpa2.context.MetamodelField; -import org.eclipse.jpt.core.jpa2.context.orm.OrmPersistentAttribute2_0; -import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> - extends AbstractOrmXmlContextNode - implements OrmAttributeMapping, AttributeMapping2_0 -{ - protected String name; - - protected final T resourceAttributeMapping; - - protected AbstractOrmAttributeMapping(OrmPersistentAttribute parent, T resourceAttributeMapping) { - super(parent); - this.resourceAttributeMapping = resourceAttributeMapping; - this.name = this.getResourceMappingName(); - } - - protected JavaPersistentAttribute getJavaPersistentAttribute() { - return this.getPersistentAttribute().getJavaPersistentAttribute(); - } - - protected JavaResourcePersistentAttribute getJavaResourcePersistentAttribute() { - return this.getJavaPersistentAttribute().getResourcePersistentAttribute(); - } - - public boolean isVirtual() { - return getPersistentAttribute().isVirtual(); - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.resourceAttributeMapping.setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - this.getPersistentAttribute().nameChanged(old, name); - } - - protected void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - this.getPersistentAttribute().nameChanged(old, name); - } - - public OrmPersistentAttribute getPersistentAttribute() { - return (OrmPersistentAttribute) getParent(); - } - - protected EntityMappings getEntityMappings() { - return this.getPersistentAttribute().getOwningPersistentType().getParent(); - } - - protected PersistentType resolvePersistentType(String className) { - return this.getEntityMappings().resolvePersistentType(className); - } - - public boolean isDefault() { - return false; - } - - public void initializeFromOrmAttributeMapping(OrmAttributeMapping oldMapping) { - setName(oldMapping.getName()); - } - - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromOrmBasicMapping(OrmBasicMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmIdMapping(OrmIdMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmTransientMapping(OrmTransientMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedMapping(OrmEmbeddedMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmEmbeddedIdMapping(OrmEmbeddedIdMapping oldMapping) { - initializeFromOrmBaseEmbeddedMapping(oldMapping); - } - - public void initializeFromOrmVersionMapping(OrmVersionMapping oldMapping) { - initializeFromOrmColumnMapping(oldMapping); - } - - public void initializeFromOrmRelationshipMapping(OrmRelationshipMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromOrmMultiRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - initializeFromOrmRelationshipMapping(oldMapping); - } - - public void initializeFromOrmSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - initializeFromOrmRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToManyMapping(OrmOneToManyMapping oldMapping) { - initializeFromOrmMultiRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToOneMapping(OrmManyToOneMapping oldMapping) { - initializeFromOrmSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToOneMapping(OrmOneToOneMapping oldMapping) { - initializeFromOrmSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToManyMapping(OrmManyToManyMapping oldMapping) { - initializeFromOrmMultiRelationshipMapping(oldMapping); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public OrmTypeMapping getTypeMapping() { - return this.getPersistentAttribute().getOwningTypeMapping(); - } - - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isRelationshipOwner() { - return false; - } - - public boolean isOwnedBy(AttributeMapping mapping) { - // Default implementation - override where needed - return false; - } - - public Iterator<String> allMappingNames() { - return getName() == null ? EmptyIterator.<String> instance() : new SingleElementIterator<String>(getName()); - } - - public AttributeMapping resolveAttributeMapping(String attributeName) { - if (getName() != null && getName().equals(attributeName)) { - return this; - } - return null; - } - - public Iterator<String> allOverrideableAttributeMappingNames() { - if (isOverridableAttributeMapping() && getName() != null) { - return new SingleElementIterator<String>(getName()); - } - return EmptyIterator.<String> instance(); - } - - public Iterator<String> allOverrideableAssociationMappingNames() { - if (isOverridableAssociationMapping() && getName() != null) { - return new SingleElementIterator<String>(getName()); - } - return EmptyIterator.<String> instance(); - } - - public Column resolveOverriddenColumn(String attributeName) { - ColumnMapping columnMapping = this.resolveColumnMapping(attributeName); - return columnMapping == null ? null : columnMapping.getColumn(); - } - - protected ColumnMapping resolveColumnMapping(String attributeName) { - AttributeMapping attributeMapping = resolveAttributeMapping(attributeName); - if (attributeMapping != null && attributeMapping.isOverridableAttributeMapping()) { - return (ColumnMapping) attributeMapping; - } - return null; - } - - public RelationshipReference resolveRelationshipReference(String attributeName) { - RelationshipMapping relationshipMapping = this.resolveRelationshipMapping(attributeName); - return relationshipMapping == null ? null : relationshipMapping.getRelationshipReference(); - } - - protected RelationshipMapping resolveRelationshipMapping(String attributeName) { - AttributeMapping attributeMapping = resolveAttributeMapping(attributeName); - if (attributeMapping != null && attributeMapping.isOverridableAssociationMapping()) { - return (RelationshipMapping) attributeMapping; - } - return null; - } - - public T getResourceAttributeMapping() { - return this.resourceAttributeMapping; - } - - public void update() { - this.setName_(this.getResourceMappingName()); - } - - protected String getResourceMappingName() { - return this.resourceAttributeMapping.getName(); - } - - public boolean shouldValidateAgainstDatabase() { - return this.getTypeMapping().shouldValidateAgainstDatabase(); - } - - public boolean contains(int textOffset) { - return this.resourceAttributeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.resourceAttributeMapping.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return (this.getPersistentAttribute().isVirtual()) ? this.getTypeMapping().getAttributesTextRange() : this.resourceAttributeMapping.getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.resourceAttributeMapping.getNameTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** metamodel ********** - - public MetamodelField getMetamodelField() { - // if we don't have a name we can't build a metamodel field... - String metamodelFieldName = this.getMetamodelFieldName(); - return (metamodelFieldName == null) ? null : - new SimpleMetamodelField( - this.getMetamodelFieldModifiers(), - this.getMetamodelFieldTypeName(), - this.getMetamodelFieldTypeArgumentNames(), - metamodelFieldName - ); - } - - protected Iterable<String> getMetamodelFieldModifiers() { - return STANDARD_METAMODEL_FIELD_MODIFIERS; - } - - /** - * most mappings are "singular" - */ - protected String getMetamodelFieldTypeName() { - return JPA2_0.SINGULAR_ATTRIBUTE; - } - - protected final Iterable<String> getMetamodelFieldTypeArgumentNames() { - ArrayList<String> typeArgumentNames = new ArrayList<String>(3); - typeArgumentNames.add(this.getTypeMapping().getPersistentType().getName()); - this.addMetamodelFieldTypeArgumentNamesTo(typeArgumentNames); - return typeArgumentNames; - } - - /** - * by default, we add only the mapping's attribute type name; - * but collection relationship mappings will also need to add the key type - * name if the "collection" is of type java.util.Map - */ - protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { - typeArgumentNames.add(this.getMetamodelTypeName()); - } - - public String getMetamodelTypeName() { - return ((OrmPersistentAttribute2_0) this.getPersistentAttribute()).getMetamodelTypeName(); - } - - protected String getMetamodelFieldName() { - return this.getName(); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateAttribute(messages); - this.validateMapping(messages); - } - - protected void validateAttribute(List<IMessage> messages) { - if (StringTools.stringIsEmpty(this.name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME, - this, - this.getValidationTextRange() - ) - ); - return; - } - } - - //TODO validation message - i think more info is needed in this message. include type mapping type? - protected void validateMapping(List<IMessage> messages) { - if ( ! this.getTypeMapping().attributeMappingKeyAllowed(this.getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {this.name}, - this, - this.getValidationTextRange() - ) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java deleted file mode 100644 index fe0fc25c4e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmBaseColumn; -import org.eclipse.jpt.core.resource.orm.AbstractXmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmBaseColumn<T extends AbstractXmlColumn> extends AbstractOrmNamedColumn<T> - implements OrmBaseColumn -{ - protected String specifiedTable; - - protected String defaultTable; - - protected Boolean specifiedUnique; - - protected Boolean specifiedNullable; - - protected Boolean specifiedInsertable; - - protected Boolean specifiedUpdatable; - - protected AbstractOrmBaseColumn(XmlContextNode parent, OrmBaseColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(BaseColumn oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedTable(oldColumn.getSpecifiedTable()); - setSpecifiedUnique(oldColumn.getSpecifiedUnique()); - setSpecifiedNullable(oldColumn.getSpecifiedNullable()); - setSpecifiedInsertable(oldColumn.getSpecifiedInsertable()); - setSpecifiedUpdatable(oldColumn.getSpecifiedUpdatable()); - } - - @Override - public OrmBaseColumn.Owner getOwner() { - return (OrmBaseColumn.Owner) super.getOwner(); - } - -// @Override -// protected void addInsignificantXmlFeatureIdsTo(Set<Integer> insignificantXmlFeatureIds) { -// super.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE); -// insignificantXmlFeatureIds.add(JpaCoreMappingsPackage.IABSTRACT_COLUMN__TABLE); -// } - - @Override - public String getTable() { - return (this.getSpecifiedTable() == null) ? getDefaultTable() : this.getSpecifiedTable(); - } - - public String getSpecifiedTable() { - return this.specifiedTable; - } - - public void setSpecifiedTable(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - if (this.valuesAreDifferent(oldSpecifiedTable, newSpecifiedTable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setTable(newSpecifiedTable); - this.removeResourceColumnIfFeaturesUnset(); - } - else if (newSpecifiedTable != null) { - addResourceColumn(); - getResourceColumn().setTable(newSpecifiedTable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(BaseColumn.DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public boolean tableNameIsInvalid() { - return getOwner().tableNameIsInvalid(getTable()); - } - - public Iterator<String> candidateTableNames() { - return getOwner().candidateTableNames(); - } - - public boolean isUnique() { - return (this.getSpecifiedUnique() == null) ? this.isDefaultUnique() : this.getSpecifiedUnique().booleanValue(); - } - - public boolean isDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - if (this.valuesAreDifferent(oldSpecifiedUnique, newSpecifiedUnique)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setUnique(newSpecifiedUnique); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedUnique != null) { - addResourceColumn(); - getResourceColumn().setUnique(newSpecifiedUnique); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - protected void setSpecifiedUnique_(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - public boolean isNullable() { - return (this.getSpecifiedNullable() == null) ? this.isDefaultNullable() : this.getSpecifiedNullable().booleanValue(); - } - - public boolean isDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - if (this.valuesAreDifferent(oldSpecifiedNullable, newSpecifiedNullable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setNullable(newSpecifiedNullable); - this.removeResourceColumnIfFeaturesUnset(); - } - else if (newSpecifiedNullable != null) { - addResourceColumn(); - getResourceColumn().setNullable(newSpecifiedNullable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - protected void setSpecifiedNullable_(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - public boolean isInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.isDefaultInsertable() : this.getSpecifiedInsertable().booleanValue(); - } - - public boolean isDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - if (this.valuesAreDifferent(oldSpecifiedInsertable, newSpecifiedInsertable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setInsertable(newSpecifiedInsertable); - this.removeResourceColumnIfFeaturesUnset(); - } - else if (newSpecifiedInsertable != null) { - addResourceColumn(); - getResourceColumn().setInsertable(newSpecifiedInsertable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - protected void setSpecifiedInsertable_(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - public boolean isUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.isDefaultUpdatable() : this.getSpecifiedUpdatable().booleanValue(); - } - - public boolean isDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - if (this.valuesAreDifferent(oldSpecifiedUpdatable, newSpecifiedUpdatable)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setUpdatable(newSpecifiedUpdatable); - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - else if (newSpecifiedUpdatable != null) { - addResourceColumn(); - getResourceColumn().setUpdatable(newSpecifiedUpdatable); - } - } - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - protected void setSpecifiedUpdatable_(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - public TextRange getTableTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getTableTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - @Override - protected void initialize(T column) { - super.initialize(column); - this.specifiedTable = this.getResourceTable(column); - this.defaultTable = this.buildDefaultTableName(); - //TODO default from java for all of these settings - this.specifiedNullable = this.getResourceNullable(column); - this.specifiedUpdatable = this.getResourceUpdatable(column); - this.specifiedUnique = this.getResourceUnique(column); - this.specifiedInsertable = this.getResourceInsertable(column); - } - - @Override - protected void update(T column) { - super.update(column); - setSpecifiedTable_(this.getResourceTable(column)); - setDefaultTable(this.buildDefaultTableName()); - setSpecifiedNullable_(this.getResourceNullable(column)); - setSpecifiedUpdatable_(this.getResourceUpdatable(column)); - setSpecifiedUnique_(this.getResourceUnique(column)); - setSpecifiedInsertable_(this.getResourceInsertable(column)); - } - - protected String getResourceTable(T column) { - return column == null ? null : column.getTable(); - } - - protected Boolean getResourceNullable(T column) { - return column == null ? null : column.getNullable(); - } - - protected Boolean getResourceUpdatable(T column) { - return column == null ? null : column.getUpdatable(); - } - - protected Boolean getResourceUnique(T column) { - return column == null ? null : column.getUnique(); - } - - protected Boolean getResourceInsertable(T column) { - return column == null ? null : column.getInsertable(); - } - - protected String buildDefaultTableName() { - return getOwner().getDefaultTableName(); - } - - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - if (this.validateTable(messages)) { - super.validate(messages, reporter); - } - } - - /** - * Return true if the table is valid and no messages are logged - */ - protected boolean validateTable(List<IMessage> messages) { - if (this.tableNameIsInvalid()) { - messages.add(this.getOwner().buildTableNotValidMessage(this, this.getTableTextRange())); - return false; - } - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java deleted file mode 100644 index eb17fbafee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmBaseEmbeddedMapping<T extends AbstractXmlEmbedded> - extends AbstractOrmAttributeMapping<T> - implements OrmBaseEmbeddedMapping -{ - protected OrmAttributeOverrideContainer attributeOverrideContainer; - - protected Embeddable targetEmbeddable; - - - protected AbstractOrmBaseEmbeddedMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.targetEmbeddable = embeddableFor(this.getJavaPersistentAttribute()); - this.attributeOverrideContainer - = getXmlContextNodeFactory().buildOrmAttributeOverrideContainer( - this, - buildAttributeOverrideContainerOwner()); - } - - - protected OrmAttributeOverrideContainer.Owner buildAttributeOverrideContainerOwner() { - return new AttributeOverrideContainerOwner(); - } - - @Override - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - super.initializeFromOrmBaseEmbeddedMapping(oldMapping); - this.attributeOverrideContainer.initializeFromAttributeOverrideContainer(oldMapping.getAttributeOverrideContainer()); - } - - public OrmAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - protected JavaAttributeOverride getJavaAttributeOverrideNamed(String attributeName) { - if (getJavaEmbeddedMapping() != null) { - return getJavaEmbeddedMapping().getAttributeOverrideContainer().getAttributeOverrideNamed(attributeName); - } - return null; - } - - public Embeddable getTargetEmbeddable() { - return this.targetEmbeddable; - } - - protected void setTargetEmbeddable_(Embeddable newTargetEmbeddable) { - Embeddable oldTargetEmbeddable = this.targetEmbeddable; - this.targetEmbeddable = newTargetEmbeddable; - firePropertyChanged(TARGET_EMBEDDABLE_PROPERTY, oldTargetEmbeddable, newTargetEmbeddable); - } - - protected Iterator<AttributeMapping> embeddableAttributeMappings() { - Embeddable targetEmbeddable = getTargetEmbeddable(); - if (targetEmbeddable != null && targetEmbeddable != getPersistentAttribute().getOwningTypeMapping()) { - return targetEmbeddable.attributeMappings(); - } - return EmptyIterator.instance(); - } - - @Override - public Iterator<String> allOverrideableAttributeMappingNames() { - return this.isJpa2_0Compatible() ? - this.embeddableOverrideableAttributeMappingNames() : - super.allOverrideableAttributeMappingNames(); - } - - protected Iterator<String> embeddableOverrideableAttributeMappingNames() { - return this.embeddableOverrideableMappingNames( - new Transformer<AttributeMapping, Iterator<String>>() { - public Iterator<String> transform(AttributeMapping mapping) { - return mapping.allOverrideableAttributeMappingNames(); - } - } - ); - } - - @Override - public Iterator<String> allOverrideableAssociationMappingNames() { - return this.isJpa2_0Compatible() ? - this.embeddableOverrideableAssociationMappingNames() : - super.allOverrideableAssociationMappingNames(); - } - - protected Iterator<String> embeddableOverrideableAssociationMappingNames() { - return this.embeddableOverrideableMappingNames( - new Transformer<AttributeMapping, Iterator<String>>() { - public Iterator<String> transform(AttributeMapping mapping) { - return mapping.allOverrideableAssociationMappingNames(); - } - } - ); - } - - protected Iterator<String> embeddableOverrideableMappingNames(Transformer<AttributeMapping, Iterator<String>> transformer) { - return new TransformationIterator<String, String>( - new CompositeIterator<String>( - new TransformationIterator<AttributeMapping, Iterator<String>>(this.embeddableAttributeMappings(), transformer))) - { - @Override - protected String transform(String next) { - return getName() + '.' + next; - } - }; - } - - @Override - public Column resolveOverriddenColumn(String attributeName) { - if (getName() == null) { - return null; - } - if (this.isJpa2_0Compatible()) { - int dotIndex = attributeName.indexOf('.'); - if (dotIndex != -1) { - if (getName().equals(attributeName.substring(0, dotIndex))) { - attributeName = attributeName.substring(dotIndex + 1); - AttributeOverride override = getAttributeOverrideContainer().getAttributeOverrideNamed(attributeName); - if (override != null && !override.isVirtual()) { - return override.getColumn(); - } - if (this.getTargetEmbeddable() == null) { - return null; - } - return this.getTargetEmbeddable().resolveOverriddenColumn(attributeName); - } - } - } - return null; - } - - public JavaBaseEmbeddedMapping getJavaEmbeddedMapping() { - JavaPersistentAttribute jpa = this.getJavaPersistentAttribute(); - if ((jpa != null) && this.valuesAreEqual(jpa.getMappingKey(), this.getKey())) { - return (JavaBaseEmbeddedMapping) jpa.getMapping(); - } - return null; - } - - - @Override - public void update() { - super.update(); - setTargetEmbeddable_(embeddableFor(this.getJavaPersistentAttribute())); - getAttributeOverrideContainer().update(); - } - - - //******** Validation ****************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (validateTargetEmbeddable(messages, reporter)) { - validateOverrides(messages, reporter); - } - } - - protected boolean validateTargetEmbeddable(List<IMessage> messages, IReporter reporter) { - if (getTargetEmbeddable() == null) { - String targetEmbeddableTypeName = getPersistentAttribute().getTypeName(); - // if the type isn't resolveable, there'll already be a java error - if (targetEmbeddableTypeName != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_NOT_AN_EMBEDDABLE, - new String[] {targetEmbeddableTypeName}, - this, - this.getValidationTextRange())); - } - return false; - } - return true; - } - - protected void validateOverrides(List<IMessage> messages, IReporter reporter) { - getAttributeOverrideContainer().validate(messages, reporter); - } - - //************ static methods ************ - - public static Embeddable embeddableFor(JavaPersistentAttribute javaPersistentAttribute) { - return (javaPersistentAttribute == null) ? null : javaPersistentAttribute.getEmbeddable(); - } - - - //********** AttributeOverrideContainer.Owner implementation ********* - - protected class AttributeOverrideContainerOwner - implements OrmAttributeOverrideContainer.Owner - { - public OrmTypeMapping getTypeMapping() { - return AbstractOrmBaseEmbeddedMapping.this.getTypeMapping(); - } - - public TypeMapping getOverridableTypeMapping() { - return AbstractOrmBaseEmbeddedMapping.this.getTargetEmbeddable(); - } - - public Iterator<String> allOverridableNames() { - TypeMapping typeMapping = getOverridableTypeMapping(); - return (typeMapping == null) ? - EmptyIterator.<String>instance() - : allOverridableAttributeNames_(typeMapping); - } - - /* assumes the type mapping is not null */ - protected Iterator<String> allOverridableAttributeNames_(TypeMapping typeMapping) { - return typeMapping.allOverridableAttributeNames(); - } - - public EList<XmlAttributeOverride> getResourceAttributeOverrides() { - return AbstractOrmBaseEmbeddedMapping.this.resourceAttributeMapping.getAttributeOverrides(); - } - - public Column resolveOverriddenColumn(String attributeOverrideName) { - if (getPersistentAttribute().isVirtual() && !getTypeMapping().isMetadataComplete()) { - JavaAttributeOverride javaAttributeOverride = getJavaAttributeOverrideNamed(attributeOverrideName); - if (javaAttributeOverride != null && !javaAttributeOverride.isVirtual()) { - return javaAttributeOverride.getColumn(); - } - } - return MappingTools.resolveOverridenColumn(getOverridableTypeMapping(), attributeOverrideName); - } - - public XmlColumn buildVirtualXmlColumn(Column overridableColumn, String attributeName, boolean isMetadataComplete) { - return new VirtualXmlAttributeOverrideColumn(overridableColumn); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public IMessage buildColumnUnresolvedNameMessage(BaseOverride override, NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualAttributeUnresolvedColumnTableNotValidMessage(override.getName(), column, textRange); - } - if (override.isVirtual()) { - return this.buildVirtualOverrideUnresolvedColumnNameMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualAttributeUnresolvedColumnTableNotValidMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] { - AbstractOrmBaseEmbeddedMapping.this.getName(), - overrideName, - column.getName(), - column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideUnresolvedColumnNameMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] { - overrideName, - column.getName(), - column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildColumnTableNotValidMessage(BaseOverride override, BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualAttributeColumnTableNotValidMessage(override.getName(), column, textRange); - } - if (override.isVirtual()) { - return this.buildVirtualOverrideColumnTableNotValidMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - protected IMessage buildVirtualAttributeColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID, - new String[] { - AbstractOrmBaseEmbeddedMapping.this.getName(), - overrideName, - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID, - new String[] { - overrideName, - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public TextRange getValidationTextRange() { - return AbstractOrmBaseEmbeddedMapping.this.getValidationTextRange(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java deleted file mode 100644 index abe63ea8df..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBasicMapping.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmBasicMapping<T extends XmlBasic> - extends AbstractOrmAttributeMapping<T> - implements OrmBasicMapping -{ - protected final OrmColumn column; - - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected OrmConverter converter; - - protected final OrmConverter nullConverter; - - protected AbstractOrmBasicMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.getResourceColumn());//TODO pass in to factory - this.specifiedFetch = this.getResourceFetch(); - this.specifiedOptional = this.getResourceOptional(); - this.nullConverter = this.getXmlContextNodeFactory().buildOrmNullConverter(this); - this.converter = this.buildConverter(this.getResourceConverterType()); - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getDefaultFetch() { - return BasicMapping.DEFAULT_FETCH_TYPE; - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.resourceAttributeMapping.setFetch(FetchType.toOrmResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public boolean isOptional() { - return (this.getSpecifiedOptional() == null) ? this.isDefaultOptional() : this.getSpecifiedOptional().booleanValue(); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.resourceAttributeMapping.setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldOptional, newSpecifiedOptional); - } - - public OrmConverter getConverter() { - return this.converter; - } - - protected String getConverterType() { - return this.converter.getType(); - } - - public void setConverter(String converterType) { - if (this.valuesAreEqual(getConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.converter; - OrmConverter newConverter = buildConverter(converterType); - this.converter = this.nullConverter; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.converter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.converter; - this.converter = newConverter; - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmBasicMapping(this); - } - - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public int getXmlSequence() { - return 20; - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - public OrmColumn getColumn() { - return this.column; - } - - public String getDefaultColumnName() { - return getName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); - } - - @Override - public void update() { - super.update(); - this.setSpecifiedFetch_(this.getResourceFetch()); - this.setSpecifiedOptional_(this.getResourceOptional()); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getConverterType())) { - getConverter().update(); - } - else { - setConverter(buildConverter(getResourceConverterType())); - } - } - - protected Boolean getResourceOptional() { - return this.resourceAttributeMapping.getOptional(); - } - - protected FetchType getResourceFetch() { - return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); - } - - protected OrmConverter buildConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.NO_CONVERTER)) { - return this.nullConverter; - } - if (this.valuesAreEqual(converterType, Converter.ENUMERATED_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmEnumeratedConverter(this, this.resourceAttributeMapping); - } - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - if (this.valuesAreEqual(converterType, Converter.LOB_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmLobConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getEnumerated() != null) { - return Converter.ENUMERATED_CONVERTER; - } - else if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - else if (this.resourceAttributeMapping.isLob()) { - return Converter.LOB_CONVERTER; - } - - return Converter.NO_CONVERTER; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getBasics().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getBasics().remove(this.resourceAttributeMapping); - } - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - getColumn().validate(messages, reporter); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualUnresolvedNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualTableNotValidMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public IMessage buildVirtualTableNotValidMessage(BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID, - new String[] { - getName(), - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java deleted file mode 100644 index 67f61d556c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEmbeddable.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractOrmEmbeddable - extends AbstractOrmTypeMapping<XmlEmbeddable> - implements OrmEmbeddable -{ - protected AbstractOrmEmbeddable(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - super(parent, resourceMapping); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public int getXmlSequence() { - return 2; - } - - public JavaEmbeddable getJavaEmbeddable() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - return (JavaEmbeddable) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaEmbeddable. - * As far as defaults are concerned, if metadataComplete is true, the JavaEmbeddable is ignored. - */ - protected JavaEmbeddable getJavaEmbeddableForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaEmbeddable(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().remove(this.resourceTypeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java deleted file mode 100644 index e25a980363..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java +++ /dev/null @@ -1,2134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.JpaPlatformVariation.Supported; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaIdClassReference; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmIdClassReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; -import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.SingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheableHolder2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.Inheritance; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ClassName; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.SubIterableWrapper; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmEntity - extends AbstractOrmTypeMapping<XmlEntity> - implements OrmEntity, OrmCacheableHolder2_0 -{ - protected String specifiedName; - - protected String defaultName; - - protected final OrmIdClassReference idClassReference; - - protected final OrmTable table; - - protected boolean specifiedTableIsAllowed; - - protected boolean tableIsUndefined; - - protected final List<OrmSecondaryTable> specifiedSecondaryTables; - - protected final List<OrmSecondaryTable> virtualSecondaryTables; - - protected final List<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected final List<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected String specifiedDiscriminatorValue; - - protected boolean specifiedDiscriminatorValueIsAllowed; - - protected boolean discriminatorValueIsUndefined; - - protected final OrmDiscriminatorColumn discriminatorColumn; - - protected boolean specifiedDiscriminatorColumnIsAllowed; - - protected boolean discriminatorColumnIsUndefined; - - protected final OrmGeneratorContainer generatorContainer; - - protected final OrmAttributeOverrideContainer attributeOverrideContainer; - - protected final OrmAssociationOverrideContainer associationOverrideContainer; - - protected final OrmQueryContainer queryContainer; - - protected Entity rootEntity; - - protected AbstractOrmEntity(OrmPersistentType parent, XmlEntity resourceMapping) { - super(parent, resourceMapping); - this.idClassReference = buildIdClassReference(); - this.table = getXmlContextNodeFactory().buildOrmTable(this); - this.specifiedSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.virtualSecondaryTables = new ArrayList<OrmSecondaryTable>(); - this.discriminatorColumn = buildDiscriminatorColumn(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.defaultPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - this.associationOverrideContainer = buildAssociationOverrideContainer(); - this.attributeOverrideContainer = buildAttributeOverrideContainer(); - this.queryContainer = this.buildQueryContainer(); - this.generatorContainer = this.buildGeneratorContainer(); - this.specifiedName = this.resourceTypeMapping.getName(); - this.defaultName = this.buildDefaultName(); - this.rootEntity = this.calculateRootEntity(); - this.initializeInheritance(this.getResourceInheritance()); - this.specifiedDiscriminatorColumnIsAllowed = this.buildSpecifiedDiscriminatorColumnIsAllowed(); - this.discriminatorColumnIsUndefined = this.buildDiscriminatorColumnIsUndefined(); - this.discriminatorColumn.initialize(this.resourceTypeMapping); //TODO pass in to constructor - this.specifiedDiscriminatorValueIsAllowed = this.buildSpecifiedDiscriminatorValueIsAllowed(); - this.discriminatorValueIsUndefined = this.buildDiscriminatorValueIsUndefined(); - this.specifiedDiscriminatorValue = this.resourceTypeMapping.getDiscriminatorValue(); - this.defaultDiscriminatorValue = this.buildDefaultDiscriminatorValue(); - this.specifiedTableIsAllowed = this.buildSpecifiedTableIsAllowed(); - this.tableIsUndefined = this.buildTableIsUndefined(); - this.table.initialize(this.resourceTypeMapping);//TODO pass in to constructor - this.initializeSpecifiedSecondaryTables(); - this.initializeVirtualSecondaryTables(); - this.initializeSpecifiedPrimaryKeyJoinColumns(); - this.initializeDefaultPrimaryKeyJoinColumns(); - } - - protected OrmIdClassReference buildIdClassReference() { - return new GenericOrmIdClassReference(this, getJavaIdClassReferenceForDefaults()); - } - - protected OrmDiscriminatorColumn buildDiscriminatorColumn() { - return getXmlContextNodeFactory().buildOrmDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected OrmDiscriminatorColumn.Owner buildDiscriminatorColumnOwner() { - return new OrmDiscriminatorColumn.Owner(){ - public String getDefaultTableName() { - return AbstractOrmEntity.this.getPrimaryTableName(); - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public TypeMapping getTypeMapping() { - return AbstractOrmEntity.this; - } - - public String getDefaultColumnName() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedName() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedName(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getName() - : - isTablePerClass() ? - null - : - DiscriminatorColumn.DEFAULT_NAME; - } - - public int getDefaultLength() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedLength() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedLength().intValue(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getLength() - : - isTablePerClass() ? - 0//TODO think i want to return null here - : - DiscriminatorColumn.DEFAULT_LENGTH; - } - - public DiscriminatorType getDefaultDiscriminatorType() { - if (getResourceTypeMapping().getDiscriminatorColumn() == null) { - if (!isMetadataComplete()) { - if (getJavaEntity() != null && getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType() != null) { - return getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType(); - } - } - } - return isDescendant() ? - getRootEntity().getDiscriminatorColumn().getDiscriminatorType() - : - isTablePerClass() ? - null - : - DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.DISCRIMINATOR_COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public TextRange getValidationTextRange() { - return AbstractOrmEntity.this.getValidationTextRange(); - } - }; - } - - protected OrmAssociationOverrideContainer buildAssociationOverrideContainer() { - return getXmlContextNodeFactory().buildOrmAssociationOverrideContainer( - this, - new AssociationOverrideContainerOwner()); - } - - protected OrmAttributeOverrideContainer buildAttributeOverrideContainer() { - return getXmlContextNodeFactory().buildOrmAttributeOverrideContainer( - this, - new AttributeOverrideContainerOwner()); - } - - protected OrmGeneratorContainer buildGeneratorContainer() { - return getXmlContextNodeFactory().buildOrmGeneratorContainer(this, this.resourceTypeMapping); - } - - protected OrmQueryContainer buildQueryContainer() { - return getXmlContextNodeFactory().buildOrmQueryContainer(this, this.resourceTypeMapping); - } - - - // ******************* TypeMapping implementation ******************** - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - @Override - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - @Override - public String getPrimaryTableName() { - return this.table.getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return this.table.getDbTable(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - // matching database objects and identifiers is database platform-specific - return this.getDataSource().selectDatabaseObjectForIdentifier(this.getAssociatedDbTablesIncludingInherited(), tableName); - } - - private Iterable<org.eclipse.jpt.db.Table> getAssociatedDbTablesIncludingInherited() { - return new FilteringIterable<org.eclipse.jpt.db.Table>(this.getAssociatedDbTablesIncludingInherited_()) { - @Override - protected boolean accept(org.eclipse.jpt.db.Table t) { - return t != null; - } - }; - } - - private Iterable<org.eclipse.jpt.db.Table> getAssociatedDbTablesIncludingInherited_() { - return new TransformationIterable<Table, org.eclipse.jpt.db.Table>(this.getAssociatedTablesIncludingInherited()) { - @Override - protected org.eclipse.jpt.db.Table transform(Table t) { - return t.getDbTable(); - } - }; - } - - @Override - public Schema getDbSchema() { - return this.table.getDbSchema(); - } - - public JavaEntity getJavaEntity() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (JavaEntity) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaEntity. - * As far as defaults are concerned, if metadataComplete is true, the JavaEntity is ignored. - */ - protected JavaEntity getJavaEntityForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaEntity(); - } - - protected JavaIdClassReference getJavaIdClassReferenceForDefaults() { - JavaEntity entity = getJavaEntityForDefaults(); - return (entity == null) ? null : entity.getIdClassReference(); - } - - - //****************** OrmAttributeOverrideContainer.Owner implementation ******************* - - public TypeMapping getOverridableTypeMapping() { - PersistentType superPersistentType = getPersistentType().getSuperPersistentType(); - return superPersistentType == null ? null : superPersistentType.getMapping(); - } - - public OrmTypeMapping getTypeMapping() { - return this; - } - - protected JavaAttributeOverride getJavaAttributeOverrideNamed(String attributeName) { - if (getJavaEntity() != null) { - return getJavaEntity().getAttributeOverrideContainer().getAttributeOverrideNamed(attributeName); - } - return null; - } - - @Override - public RelationshipReference resolveRelationshipReference(String name) { - if (this.isJpa2_0Compatible()) { - int dotIndex = name.indexOf('.'); - if (dotIndex != -1) { - AssociationOverride override = getAssociationOverrideContainer().getAssociationOverrideNamed(name.substring(dotIndex + 1)); - if (override != null && !override.isVirtual()) { - return override.getRelationshipReference(); - } - } - } - return super.resolveRelationshipReference(name); - } - - protected JavaAssociationOverride getJavaAssociationOverrideNamed(String attributeName) { - if (getJavaEntity() != null) { - return getJavaEntity().getAssociationOverrideContainer().getAssociationOverrideNamed(attributeName); - } - return null; - } - - // **************** name ************************************************** - - public String getName() { - return (this.getSpecifiedName() == null) ? getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - this.resourceTypeMapping.setName(newSpecifiedName); - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - - // **************** id class ********************************************** - - public OrmIdClassReference getIdClassReference() { - return this.idClassReference; - } - - - // **************** table ************************************************* - - public OrmTable getTable() { - return this.table; - } - - public ListIterator<OrmSecondaryTable> secondaryTables() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTables(); - } - return virtualSecondaryTables(); - } - - public int secondaryTablesSize() { - if (specifiedSecondaryTablesSize() > 0) { - return specifiedSecondaryTablesSize(); - } - return virtualSecondaryTablesSize(); - } - - public ListIterator<OrmSecondaryTable> virtualSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.virtualSecondaryTables); - } - - public int virtualSecondaryTablesSize() { - return this.virtualSecondaryTables.size(); - } - - protected void addVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - addItemToList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - protected void removeVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.virtualSecondaryTables, OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST); - } - - public ListIterator<OrmSecondaryTable> specifiedSecondaryTables() { - return new CloneListIterator<OrmSecondaryTable>(this.specifiedSecondaryTables); - } - - public int specifiedSecondaryTablesSize() { - return this.specifiedSecondaryTables.size(); - } - - public OrmSecondaryTable addSpecifiedSecondaryTable(int index) { - if (!secondaryTablesDefinedInXml()) { - throw new IllegalStateException("Virtual secondary tables exist, must first call setSecondaryTablesDefinedInXml(true)"); //$NON-NLS-1$ - } - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTable(); - OrmSecondaryTable secondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(index, secondaryTable); - this.resourceTypeMapping.getSecondaryTables().add(index, secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - public OrmSecondaryTable addSpecifiedSecondaryTable() { - return this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size()); - } - - protected void addSpecifiedSecondaryTable(int index, OrmSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - protected void addSpecifiedSecondaryTable(OrmSecondaryTable secondaryTable) { - this.addSpecifiedSecondaryTable(this.specifiedSecondaryTables.size(), secondaryTable); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - OrmSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - this.resourceTypeMapping.getSecondaryTables().remove(index); - fireItemRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(OrmSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.resourceTypeMapping.getSecondaryTables().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public boolean containsSecondaryTable(String name) { - return containsSecondaryTable(name, secondaryTables()); - } - - public boolean containsSpecifiedSecondaryTable(String name) { - return containsSecondaryTable(name, specifiedSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(String name) { - return containsSecondaryTable(name, virtualSecondaryTables()); - } - - public boolean containsVirtualSecondaryTable(OrmSecondaryTable secondaryTable) { - return this.virtualSecondaryTables.contains(secondaryTable); - } - - protected boolean containsSecondaryTable(String name, ListIterator<OrmSecondaryTable> secondaryTables) { - for (OrmSecondaryTable secondaryTable : CollectionTools.iterable(secondaryTables)) { - String secondaryTableName = secondaryTable.getName(); - if (secondaryTableName != null && secondaryTableName.equals(name)) { - return true; - } - } - return false; - } - - public boolean secondaryTablesDefinedInXml() { - return virtualSecondaryTablesSize() == 0; - } - - public void setSecondaryTablesDefinedInXml(boolean defineInXml) { - if (defineInXml == secondaryTablesDefinedInXml()) { - return; - } - if (defineInXml) { - specifySecondaryTablesInXml(); - } - else { - removeSecondaryTablesFromXml(); - } - } - - /** - * This is used to take all the java secondary tables and specify them in the xml. You must - * use setSecondaryTablesDefinedInXml(boolean) before calling addSpecifiedSecondaryTable(). - * - * Yes this code looks odd, but be careful making changes to it - */ - protected void specifySecondaryTablesInXml() { - if (virtualSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> virtualSecondaryTables1 = CollectionTools.list(this.virtualSecondaryTables()); - List<OrmSecondaryTable> virtualSecondaryTables2 = CollectionTools.list(this.virtualSecondaryTables()); - //remove all the virtual secondary tables without firing change notification. - for (OrmSecondaryTable virtualSecondaryTable : CollectionTools.iterable(virtualSecondaryTables())) { - this.virtualSecondaryTables.remove(virtualSecondaryTable); - } - //add specified secondary tables for each virtual secondary table. If the virtual secondary tables - //are not removed first, they will be removed as a side effect of adding the first specified secondary table. - //This screws up the change notification to the UI, since that change notification is in a different thread - for (OrmSecondaryTable virtualSecondaryTable : virtualSecondaryTables2) { - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTable(); - OrmSecondaryTable specifiedSecondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(specifiedSecondaryTable); - this.resourceTypeMapping.getSecondaryTables().add(secondaryTableResource); - specifiedSecondaryTable.initializeFrom(virtualSecondaryTable); - } - //fire change notification at the end - fireItemsRemoved(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, virtualSecondaryTables1); - fireItemsAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, this.specifiedSecondaryTables); - } - } - - protected void removeSecondaryTablesFromXml() { - if (specifiedSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> specifiedSecondaryTablesCopy = CollectionTools.list(this.specifiedSecondaryTables()); - for (OrmSecondaryTable specifiedSecondaryTable : CollectionTools.iterable(specifiedSecondaryTables())) { - int index = this.specifiedSecondaryTables.indexOf(specifiedSecondaryTable); - this.specifiedSecondaryTables.remove(specifiedSecondaryTable); - if (this.specifiedSecondaryTables.size() == 0) { - initializeVirtualSecondaryTables(); - } - this.resourceTypeMapping.getSecondaryTables().remove(index); - } - fireItemsRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, specifiedSecondaryTablesCopy); - if (this.virtualSecondaryTables.size() != 0) { - fireItemsAdded(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, this.virtualSecondaryTables); - } - } - } - - protected Iterator<String> tableNames(Iterator<Table> tables) { - return new TransformationIterator<Table, String>(tables) { - @Override - protected String transform(Table t) { - return t.getName(); - } - }; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return this.nonNullTableNames(this.associatedTablesIncludingInherited()); - } - - protected Iterator<String> nonNullTableNames(Iterator<Table> tables) { - return new FilteringIterator<String>(this.tableNames(tables)) { - @Override - protected boolean accept(String o) { - return o != null; - } - }; - } - - public Iterator<Table> associatedTables() { - return new CompositeIterator<Table>(this.table, this.secondaryTables()); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return this.getAssociatedTablesIncludingInherited().iterator(); - } - - public Iterable<Table> getAssociatedTablesIncludingInherited() { - return new CompositeIterable<Table>(new TransformationIterable<TypeMapping, Iterable<Table>>(CollectionTools.iterable(this.inheritanceHierarchy())) { - @Override - protected Iterable<Table> transform(TypeMapping mapping) { - return new FilteringIterable<Table>(CollectionTools.iterable(mapping.associatedTables())) { - @Override - protected boolean accept(Table o) { - return true; - //TODO - //filtering these out so as to avoid the duplicate table, root and children share the same table - //return !(o instanceof SingleTableInheritanceChildTableImpl); - } - }; - } - }); - } - - public boolean tableNameIsInvalid(String tableName) { - if (tableIsUndefined()) { - return false; - } - return ! CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return super.shouldValidateAgainstDatabase() && ! isAbstractTablePerClass(); - } - - public InheritanceType getInheritanceStrategy() { - return (this.getSpecifiedInheritanceStrategy() == null) ? this.getDefaultInheritanceStrategy() : this.getSpecifiedInheritanceStrategy(); - } - - public InheritanceType getDefaultInheritanceStrategy() { - return this.defaultInheritanceStrategy; - } - - protected void setDefaultInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.defaultInheritanceStrategy; - this.defaultInheritanceStrategy = newInheritanceType; - firePropertyChanged(DEFAULT_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public InheritanceType getSpecifiedInheritanceStrategy() { - return this.specifiedInheritanceStrategy; - } - - public void setSpecifiedInheritanceStrategy(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - if (oldInheritanceType != newInheritanceType) { - if (this.getResourceInheritance() != null) { - this.getResourceInheritance().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - if (this.getResourceInheritance().isUnset()) { - removeResourceInheritance(); - } - } - else if (newInheritanceType != null) { - addResourceInheritance(); - getResourceInheritance().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - } - } - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected void setSpecifiedInheritanceStrategy_(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - protected Inheritance getResourceInheritance() { - return this.resourceTypeMapping.getInheritance(); - } - - protected void addResourceInheritance() { - this.resourceTypeMapping.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - } - - protected void removeResourceInheritance() { - this.resourceTypeMapping.setInheritance(null); - } - - public OrmDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - public OrmGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - public String getDefaultDiscriminatorValue() { - return this.defaultDiscriminatorValue; - } - - protected void setDefaultDiscriminatorValue(String newDefaultDiscriminatorValue) { - String oldDefaultDiscriminatorValue = this.defaultDiscriminatorValue; - this.defaultDiscriminatorValue = newDefaultDiscriminatorValue; - firePropertyChanged(DEFAULT_DISCRIMINATOR_VALUE_PROPERTY, oldDefaultDiscriminatorValue, newDefaultDiscriminatorValue); - } - - public String getSpecifiedDiscriminatorValue() { - return this.specifiedDiscriminatorValue; - } - - public void setSpecifiedDiscriminatorValue(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - this.resourceTypeMapping.setDiscriminatorValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean specifiedDiscriminatorValueIsAllowed() { - return this.specifiedDiscriminatorValueIsAllowed; - } - - protected void setSpecifiedDiscriminatorValueIsAllowed(boolean specifiedDiscriminatorValueIsAllowed) { - boolean old = this.specifiedDiscriminatorValueIsAllowed; - this.specifiedDiscriminatorValueIsAllowed = specifiedDiscriminatorValueIsAllowed; - firePropertyChanged(Entity.SPECIFIED_DISCRIMINATOR_VALUE_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorValueIsAllowed); - } - - public boolean discriminatorValueIsUndefined() { - return this.discriminatorValueIsUndefined; - } - - protected void setDiscriminatorValueIsUndefined(boolean discriminatorValueIsUndefined) { - boolean old = this.discriminatorValueIsUndefined; - this.discriminatorValueIsUndefined = discriminatorValueIsUndefined; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_IS_UNDEFINED_PROPERTY, old, discriminatorValueIsUndefined); - } - - public boolean specifiedDiscriminatorColumnIsAllowed() { - return this.specifiedDiscriminatorColumnIsAllowed; - } - - protected void setSpecifiedDiscriminatorColumnIsAllowed(boolean specifiedDiscriminatorColumnIsAllowed) { - boolean old = this.specifiedDiscriminatorColumnIsAllowed; - this.specifiedDiscriminatorColumnIsAllowed = specifiedDiscriminatorColumnIsAllowed; - firePropertyChanged(Entity.SPECIFIED_DISCRIMINATOR_COLUMN_IS_ALLOWED_PROPERTY, old, specifiedDiscriminatorColumnIsAllowed); - } - - public boolean discriminatorColumnIsUndefined() { - return this.discriminatorColumnIsUndefined; - } - - protected void setDiscriminatorColumnIsUndefined(boolean discriminatorColumnIsUndefined) { - boolean old = this.discriminatorColumnIsUndefined; - this.discriminatorColumnIsUndefined = discriminatorColumnIsUndefined; - firePropertyChanged(Entity.DISCRIMINATOR_COLUMN_IS_UNDEFINED_PROPERTY, old, discriminatorColumnIsUndefined); - } - - - public boolean specifiedTableIsAllowed() { - return this.specifiedTableIsAllowed; - } - - protected void setSpecifiedTableIsAllowed(boolean specifiedTableIsAllowed) { - boolean old = this.specifiedTableIsAllowed; - this.specifiedTableIsAllowed = specifiedTableIsAllowed; - firePropertyChanged(Entity.SPECIFIED_TABLE_IS_ALLOWED_PROPERTY, old, specifiedTableIsAllowed); - } - - public boolean tableIsUndefined() { - return this.tableIsUndefined; - } - - protected void setTableIsUndefined(boolean tableIsUndefined) { - boolean old = this.tableIsUndefined; - this.tableIsUndefined = tableIsUndefined; - firePropertyChanged(Entity.TABLE_IS_UNDEFINED_PROPERTY, old, tableIsUndefined); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumns); - } - - public int defaultPrimaryKeyJoinColumnsSize() { - return this.defaultPrimaryKeyJoinColumns.size(); - } - - public OrmPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - throw new UnsupportedOperationException("use defaultPrimaryKeyJoinColumns() instead"); //$NON-NLS-1$ - } - - protected void addDefaultPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn defaultPkJoinColumn) { - addItemToList(defaultPkJoinColumn, this.defaultPrimaryKeyJoinColumns, OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void removeDefaultPrimaryKeyJoinColumn(PrimaryKeyJoinColumn defaultPkJoinColumn) { - removeItemFromList(defaultPkJoinColumn, this.defaultPrimaryKeyJoinColumns, OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.specifiedPrimaryKeyJoinColumns.isEmpty() ? this.defaultPrimaryKeyJoinColumns() : this.specifiedPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.isEmpty() ? this.defaultPrimaryKeyJoinColumnsSize() : this.specifiedPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - if (!this.defaultPrimaryKeyJoinColumns.isEmpty()) { - this.defaultPrimaryKeyJoinColumns.clear(); - } - XmlPrimaryKeyJoinColumn resourcePkJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(); - OrmPrimaryKeyJoinColumn contextPkJoinColumn = buildPrimaryKeyJoinColumn(resourcePkJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, contextPkJoinColumn); - this.resourceTypeMapping.getPrimaryKeyJoinColumns().add(index, resourcePkJoinColumn); - - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, contextPkJoinColumn); - this.fireListCleared(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - return contextPkJoinColumn; - } - - protected OrmBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.addSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.size(), primaryKeyJoinColumn); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn primaryKeyJoinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(primaryKeyJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPrimaryKeyJoinColumn = this.specifiedPrimaryKeyJoinColumns.remove(index); - if (!containsSpecifiedPrimaryKeyJoinColumns()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - initializeDefaultPrimaryKeyJoinColumns(); - } - this.resourceTypeMapping.getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (!this.defaultPrimaryKeyJoinColumns.isEmpty()) { - fireListChanged(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST, this.defaultPrimaryKeyJoinColumns); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.resourceTypeMapping.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverrideContainer getAttributeOverrideContainer() { - return this.attributeOverrideContainer; - } - - public OrmAssociationOverrideContainer getAssociationOverrideContainer() { - return this.associationOverrideContainer; - } - - public OrmQueryContainer getQueryContainer() { - return this.queryContainer; - } - - public String getDefaultTableName() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedName() != null) { - return javaTable.getSpecifiedName(); - } - } - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getName() - : - this.isAbstractTablePerClass() ? - null - : - this.getName(); - } - - public String getDefaultSchema() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedSchema() != null) { - return javaTable.getSpecifiedSchema(); - } - } - - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getSchema() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultSchema(); - } - - public String getDefaultCatalog() { - JavaEntity javaEntity = this.getJavaEntity(); - if (javaEntity != null) { - JavaTable javaTable = javaEntity.getTable(); - if ( ! this.isMetadataComplete() - && ! this.table.isResourceSpecified() - && javaTable.getSpecifiedCatalog() != null) { - return javaTable.getSpecifiedCatalog(); - } - } - - return this.isSingleTableDescendant() ? - this.getRootEntity().getTable().getCatalog() - : - this.isAbstractTablePerClass() ? - null - : - this.getContextDefaultCatalog(); - } - - /** - * Return whether the entity is a descendant of the root entity - * of a "single table" inheritance hierarchy. - */ - protected boolean isSingleTableDescendant() { - return this.isDescendant() && (this.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> stream = getPersistentType().ancestors(); stream.hasNext();) { - TypeMapping tm = stream.next().getMapping(); - if (tm instanceof Entity) { - return (Entity) tm; - } - } - return null; - } - - public Entity getRootEntity() { - return this.rootEntity; - } - - public boolean isRoot() { - return this == this.getRootEntity(); - } - - /** - * Return whether the entity is a descendant in (as opposed to the root of) - * an inheritance hierarchy. - */ - protected boolean isDescendant() { - return ! this.isRoot(); - } - - /** - * Return whether the entity is the top of an inheritance hierarchy - * and has no descendants and no specified inheritance strategy has been defined. - */ - protected boolean isRootNoDescendantsNoStrategyDefined() { - return isRoot() && !getPersistenceUnit().entityIsRootWithSubEntities(this.getName()) && getSpecifiedInheritanceStrategy() == null; - } - - /** - * Return whether the entity is abstract and is a part of a - * "table per class" inheritance hierarchy. - */ - protected boolean isAbstractTablePerClass() { - return isAbstract() && isTablePerClass(); - } - - /** - * Return whether the entity is a part of a "table per class" - * inheritance hierarchy. - */ - protected boolean isTablePerClass() { - return (this.getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS); - } - - /** - * Return whether the type is abstract, false if no java type exists. - */ - protected boolean isAbstract() { - JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); - return javaResourcePersistentType == null ? false : javaResourcePersistentType.isAbstract(); - } - -// public String primaryKeyColumnName() { -// String pkColumnName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkColumnName; -// } -// -// public String primaryKeyAttributeName() { -// String pkColumnName = null; -// String pkAttributeName = null; -// for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { -// IPersistentAttribute attribute = stream.next(); -// String name = attribute.primaryKeyColumnName(); -// if (pkColumnName == null) { -// pkColumnName = name; -// pkAttributeName = attribute.getName(); -// } -// else if (name != null) { -// // if we encounter a composite primary key, return null -// return null; -// } -// } -// // if we encounter only a single primary key column name, return it -// return pkAttributeName; -// } -// - - - public int getXmlSequence() { - return 1; - } - - /** - * Return an iterator of Entities, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - protected Iterator<TypeMapping> ancestors() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().ancestors()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<String> overridableAttributeNames() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return super.overridableAttributeNames(); - } - - @Override - public Column resolveOverriddenColumn(String attributeName) { - if (this.isJpa2_0Compatible()) { - int dotIndex = attributeName.indexOf('.'); - if (dotIndex != -1) { - AttributeOverride override = getAttributeOverrideContainer().getAttributeOverrideNamed(attributeName.substring(dotIndex + 1)); - if (override != null && !override.isVirtual()) { - return override.getColumn(); - } - } - } - return super.resolveOverriddenColumn(attributeName); - } - - @Override - public Iterator<String> overridableAssociationNames() { - if (!isTablePerClass()) { - return EmptyIterator.instance(); - } - return super.overridableAssociationNames(); - } - - public AttributeMapping resolveAttributeMapping(String name) { - for (AttributeMapping attributeMapping : CollectionTools.iterable(this.allAttributeMappings())) { - AttributeMapping resolvedMapping = attributeMapping.resolveAttributeMapping(name); - if (resolvedMapping != null) { - return resolvedMapping; - } - } - return null; - } - -// -// public IAttributeOverride createAttributeOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAttributeOverride(new IEntity.AttributeOverrideOwner(this)); -// } -// -// public IAssociationOverride createAssociationOverride(int index) { -// return OrmFactory.eINSTANCE.createXmlAssociationOverride(new IEntity.AssociationOverrideOwner(this)); -// } -// -// public IAttributeOverride attributeOverrideNamed(String name) { -// return (IAttributeOverride) overrideNamed(name, getAttributeOverrides()); -// } -// -// public boolean containsAttributeOverride(String name) { -// return containsOverride(name, getAttributeOverrides()); -// } -// -// public boolean containsSpecifiedAttributeOverride(String name) { -// return containsOverride(name, getSpecifiedAttributeOverrides()); -// } -// -// public boolean containsAssociationOverride(String name) { -// return containsOverride(name, getAssociationOverrides()); -// } -// -// public boolean containsSpecifiedAssociationOverride(String name) { -// return containsOverride(name, getSpecifiedAssociationOverrides()); -// } -// -// private IOverride overrideNamed(String name, List<? extends IOverride> overrides) { -// for (IOverride override : overrides) { -// String overrideName = override.getName(); -// if (overrideName == null && name == null) { -// return override; -// } -// if (overrideName != null && overrideName.equals(name)) { -// return override; -// } -// } -// return null; -// } -// -// private boolean containsOverride(String name, List<? extends IOverride> overrides) { -// return overrideNamed(name, overrides) != null; -// } -// -// public boolean containsSpecifiedPrimaryKeyJoinColumns() { -// return !this.getSpecifiedPrimaryKeyJoinColumns().isEmpty(); -// } - - protected void initializeInheritance(Inheritance inheritanceResource) { - this.specifiedInheritanceStrategy = this.getResourceInheritanceStrategy(inheritanceResource); - //no need to initialize defaultInheritanceStrategy, need to get all the persistentTypes in the model first - } - - protected void initializeSpecifiedSecondaryTables() { - for (XmlSecondaryTable secondaryTable : this.resourceTypeMapping.getSecondaryTables()) { - this.specifiedSecondaryTables.add(buildSecondaryTable(secondaryTable)); - } - } - - protected void initializeVirtualSecondaryTables() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - return; - } - if (specifiedSecondaryTablesSize() > 0) { - return; - } - ListIterator<JavaSecondaryTable> javaSecondaryTables = getJavaEntity().secondaryTables(); - while(javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - if (javaSecondaryTable.getName() != null) { - this.virtualSecondaryTables.add(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - } - - protected void initializeDefaultPrimaryKeyJoinColumns() { - if (isMetadataComplete()) { - return; - } - if (getJavaEntity() == null) { - this.defaultPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(null)); - return; - } - if (specifiedPrimaryKeyJoinColumnsSize() > 0) { - return; - } - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - while(javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - if (javaPkJoinColumn.getName() != null) { - this.defaultPrimaryKeyJoinColumns.add(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - } - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns() { - for (XmlPrimaryKeyJoinColumn resourcePkJoinColumn : this.resourceTypeMapping.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(resourcePkJoinColumn)); - } - } - - @Override - public void update() { - super.update(); - this.setSpecifiedName(this.resourceTypeMapping.getName()); - this.setDefaultName(this.buildDefaultName()); - this.idClassReference.update(getJavaIdClassReferenceForDefaults()); - this.updateInheritance(this.getResourceInheritance()); - this.updateRootEntity(); - this.updateDiscriminatorColumn(); - this.updateDiscriminatorValue(); - this.setSpecifiedTableIsAllowed(this.buildSpecifiedTableIsAllowed()); - this.setTableIsUndefined(this.buildTableIsUndefined()); - this.table.update(this.resourceTypeMapping); - this.updateSpecifiedSecondaryTables(); - this.updateVirtualSecondaryTables(); - this.generatorContainer.update(); - this.updateSpecifiedPrimaryKeyJoinColumns(); - this.updateDefaultPrimaryKeyJoinColumns(); - getAttributeOverrideContainer().update(); - getAssociationOverrideContainer().update(); - getQueryContainer().update(); - } - - @Override - public void postUpdate() { - super.postUpdate(); - this.postUpdateDiscriminatorColumn(); - this.postUpdateDiscriminatorValue(); - } - - protected String buildDefaultName() { - if (!isMetadataComplete()) { - JavaEntity javaEntity = getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getName(); - } - } - String className = getClass_(); - return StringTools.stringIsEmpty(className) ? null : ClassName.getSimpleName(className); - } - - protected void updateDiscriminatorColumn() { - this.setSpecifiedDiscriminatorColumnIsAllowed(this.buildSpecifiedDiscriminatorColumnIsAllowed()); - getDiscriminatorColumn().update(this.resourceTypeMapping); - } - - protected void postUpdateDiscriminatorColumn() { - this.setDiscriminatorColumnIsUndefined(this.buildDiscriminatorColumnIsUndefined()); - this.getDiscriminatorColumn().postUpdate(); - } - - protected void updateDiscriminatorValue() { - this.setSpecifiedDiscriminatorValueIsAllowed(this.buildSpecifiedDiscriminatorValueIsAllowed()); - this.setSpecifiedDiscriminatorValue(this.resourceTypeMapping.getDiscriminatorValue()); - } - - protected void postUpdateDiscriminatorValue() { - this.setDiscriminatorValueIsUndefined(this.buildDiscriminatorValueIsUndefined()); - this.setDefaultDiscriminatorValue(this.buildDefaultDiscriminatorValue()); - } - - /** - * From the Spec: - * If the DiscriminatorValue annotation is not specified, a - * provider-specific function to generate a value representing - * the entity type is used for the value of the discriminator - * column. If the DiscriminatorType is STRING, the discriminator - * value default is the entity name. - * - * TODO extension point for provider-specific function? - */ - protected String buildDefaultDiscriminatorValue() { - if (!isMetadataComplete() && getJavaEntity() != null) { - return getJavaEntity().getDiscriminatorValue(); - } - if (discriminatorValueIsUndefined()) { - return null; - } - if (this.getDiscriminatorType() != DiscriminatorType.STRING) { - return null; - } - return this.getName(); - } - - protected DiscriminatorType getDiscriminatorType() { - return this.getDiscriminatorColumn().getDiscriminatorType(); - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - if (getPersistentType().getJavaPersistentType() != null) { - return getPersistentType().getJavaPersistentType().getResourcePersistentType(); - } - return null; - } - - protected boolean buildSpecifiedDiscriminatorValueIsAllowed() { - return !isTablePerClass() && !isAbstract(); - } - - protected boolean buildDiscriminatorValueIsUndefined() { - return isTablePerClass() || isAbstract() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedDiscriminatorColumnIsAllowed() { - return !isTablePerClass() && isRoot(); - } - - protected boolean buildDiscriminatorColumnIsUndefined() { - return isTablePerClass() || isRootNoDescendantsNoStrategyDefined(); - } - - protected boolean buildSpecifiedTableIsAllowed() { - return !isAbstractTablePerClass() && !isSingleTableDescendant(); - } - - protected boolean buildTableIsUndefined() { - return isAbstractTablePerClass(); - } - - - protected void updateInheritance(Inheritance inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.getResourceInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.buildDefaultInheritanceStrategy()); - } - - protected void updateRootEntity() { - //I am making an assumption here that we don't need property change notification for rootEntity, this might be wrong - this.rootEntity = calculateRootEntity(); - if (this.rootEntity != this) { - this.rootEntity.addSubEntity(this); - } - } - - protected Entity calculateRootEntity() { - Entity root = this; - for (Iterator<TypeMapping> stream = inheritanceHierarchy(); stream.hasNext();) { - TypeMapping typeMapping = stream.next(); - if (typeMapping instanceof Entity) { - root = (Entity) typeMapping; - } - } - return root; - } - - public void addSubEntity(Entity subEntity) { - getPersistenceUnit().addRootEntityWithSubEntities(getName()); - } - - protected void updateSpecifiedSecondaryTables() { - // make a copy of the XML tables (to prevent ConcurrentModificationException) - Iterator<XmlSecondaryTable> xmlTables = new CloneIterator<XmlSecondaryTable>(this.resourceTypeMapping.getSecondaryTables()); - - for (Iterator<OrmSecondaryTable> contextTables = this.specifiedSecondaryTables(); contextTables.hasNext(); ) { - OrmSecondaryTable contextTable = contextTables.next(); - if (xmlTables.hasNext()) { - contextTable.update(xmlTables.next()); - } - else { - removeSpecifiedSecondaryTable_(contextTable); - } - } - - while (xmlTables.hasNext()) { - addSpecifiedSecondaryTable(buildSecondaryTable(xmlTables.next())); - } - } - - //if any secondary-tables are specified in the xml file, then all of the java secondaryTables are overriden - protected void updateVirtualSecondaryTables() { - ListIterator<OrmSecondaryTable> secondaryTables = virtualSecondaryTables(); - ListIterator<JavaSecondaryTable> javaSecondaryTables = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedSecondaryTablesSize() == 0) { - javaSecondaryTables = getJavaEntity().secondaryTables(); - } - while (secondaryTables.hasNext()) { - OrmSecondaryTable virtualSecondaryTable = secondaryTables.next(); - if (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - virtualSecondaryTable.update(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - else { - removeVirtualSecondaryTable(virtualSecondaryTable); - } - } - - while (javaSecondaryTables.hasNext()) { - JavaSecondaryTable javaSecondaryTable = javaSecondaryTables.next(); - addVirtualSecondaryTable(buildVirtualSecondaryTable(javaSecondaryTable)); - } - } - - protected OrmSecondaryTable buildSecondaryTable(XmlSecondaryTable xmlSecondaryTable) { - return getXmlContextNodeFactory().buildOrmSecondaryTable(this, xmlSecondaryTable); - } - - protected OrmSecondaryTable buildVirtualSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - return buildSecondaryTable(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - - protected InheritanceType getResourceInheritanceStrategy(Inheritance inheritanceResource) { - if (inheritanceResource == null) { - return null; - } - return InheritanceType.fromOrmResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType buildDefaultInheritanceStrategy() { - if ((this.getResourceInheritance() == null) - && ! this.isMetadataComplete() - && (this.getJavaEntity() != null)) { - return this.getJavaEntity().getInheritanceStrategy(); - } - return this.isRoot() ? InheritanceType.SINGLE_TABLE : this.getRootEntity().getInheritanceStrategy(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns() { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - Iterator<XmlPrimaryKeyJoinColumn> xmlPkJoinColumns = new CloneIterator<XmlPrimaryKeyJoinColumn>(this.resourceTypeMapping.getPrimaryKeyJoinColumns()); - - for (Iterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = this.specifiedPrimaryKeyJoinColumns(); contextPkJoinColumns.hasNext(); ) { - OrmPrimaryKeyJoinColumn contextPkJoinColumn = contextPkJoinColumns.next(); - if (xmlPkJoinColumns.hasNext()) { - contextPkJoinColumn.update(xmlPkJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(contextPkJoinColumn); - } - } - - while (xmlPkJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(xmlPkJoinColumns.next())); - } - } - - //if there are any specified pkJoinColumns, then no default pkJoinColumns - //if the java has specified pkJoinColumns, then those are the default pkJoinColumns - //otherwise, just 1 pkJoinColumn, defaults being null if multiple primaryKey columns - protected void updateDefaultPrimaryKeyJoinColumns() { - ListIterator<OrmPrimaryKeyJoinColumn> defaultPkJoinColumns = defaultPrimaryKeyJoinColumns(); - ListIterator<JavaPrimaryKeyJoinColumn> javaPkJoinColumns = EmptyListIterator.instance(); - - if (getJavaEntity() != null && !isMetadataComplete() && specifiedPrimaryKeyJoinColumnsSize() == 0) { - javaPkJoinColumns = getJavaEntity().primaryKeyJoinColumns(); - } - while (defaultPkJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn defaultPkJoinColumn = defaultPkJoinColumns.next(); - if (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - defaultPkJoinColumn.update(new VirtualXmlPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - else { - if (defaultPrimaryKeyJoinColumnsSize() == 1) { - defaultPkJoinColumn.update(null); - } - else { - removeDefaultPrimaryKeyJoinColumn(defaultPkJoinColumn); - } - } - } - - while (javaPkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn javaPkJoinColumn = javaPkJoinColumns.next(); - addDefaultPrimaryKeyJoinColumn(buildVirtualPrimaryKeyJoinColumn(javaPkJoinColumn)); - } - - if (defaultPrimaryKeyJoinColumnsSize() == 0 && specifiedPrimaryKeyJoinColumnsSize() == 0) { - addDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(null)); - } - } - - protected OrmPrimaryKeyJoinColumn buildVirtualPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaSecondaryTable) { - return buildPrimaryKeyJoinColumn(new VirtualXmlPrimaryKeyJoinColumn(javaSecondaryTable)); - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - return getXmlContextNodeFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner(), resourcePkJoinColumn); - } - - - // ************************************************************************* - - public String getPrimaryKeyColumnName() { - return AbstractJavaEntity.getPrimaryKeyColumnName(this); - } - - public PersistentAttribute getIdAttribute() { - Iterable<AttributeMapping> idAttributeMappings = getAllAttributeMappings(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - if (CollectionTools.size(idAttributeMappings) != 1) { - return null; - } - return idAttributeMappings.iterator().next().getPersistentAttribute(); - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().remove(this.resourceTypeMapping); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - validatePrimaryKey(messages, reporter); - validateTable(messages, reporter); - for (Iterator<OrmSecondaryTable> stream = this.secondaryTables(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - validateInheritance(messages, reporter); - this.generatorContainer.validate(messages, reporter); - this.queryContainer.validate(messages, reporter); - this.attributeOverrideContainer.validate(messages, reporter); - this.associationOverrideContainer.validate(messages, reporter); - } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - buildPrimaryKeyValidator().validate(messages, reporter); - } - - protected PrimaryKeyValidator buildPrimaryKeyValidator() { - return new GenericEntityPrimaryKeyValidator(this, buildTextRangeResolver()); - // TODO - JPA 2.0 validation - } - - protected PrimaryKeyTextRangeResolver buildTextRangeResolver() { - return new OrmEntityTextRangeResolver(this); - } - - protected void validateTable(List<IMessage> messages, IReporter reporter) { - if (isAbstractTablePerClass()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange() - ) - ); - } - return; - } - if (isSingleTableDescendant()) { - if (this.table.isResourceSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE, - new String[] {this.getName()}, - this, - this.getTable().getValidationTextRange() - ) - ); - } - return; - } - this.table.validate(messages, reporter); - } - - protected void validateInheritance(List<IMessage> messages, IReporter reporter) { - validateInheritanceStrategy(messages); - validateDiscriminatorColumn(messages, reporter); - validateDiscriminatorValue(messages); - } - - protected void validateDiscriminatorColumn(List<IMessage> messages, IReporter reporter) { - if (specifiedDiscriminatorColumnIsAllowed() && !discriminatorColumnIsUndefined()) { - getDiscriminatorColumn().validate(messages, reporter); - } - else if (getDiscriminatorColumn().isResourceSpecified()) { - if (!isRoot()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange() - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorColumnTextRange() - ) - ); - - } - } - } - - protected void validateDiscriminatorValue(List<IMessage> messages) { - if (discriminatorValueIsUndefined() && getSpecifiedDiscriminatorValue() != null) { - if (isAbstract()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange() - ) - ); - } - else if (isTablePerClass()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED, - new String[] {this.getName()}, - this, - this.getDiscriminatorValueTextRange() - ) - ); - } - } - } - - protected void validateInheritanceStrategy(List<IMessage> messages) { - Supported tablePerConcreteClassInheritanceIsSupported = getJpaPlatformVariation().getTablePerConcreteClassInheritanceIsSupported(); - if (tablePerConcreteClassInheritanceIsSupported == Supported.YES) { - return; - } - if ((getInheritanceStrategy() == InheritanceType.TABLE_PER_CLASS) && isRoot()) { - if (tablePerConcreteClassInheritanceIsSupported == Supported.NO) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_SUPPORTED_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM, - new String[] {this.getName()}, - this, - this.getInheritanceStrategyTextRange() - ) - ); - } - } - } - - protected TextRange getDiscriminatorValueTextRange() { - return this.resourceTypeMapping.getDiscriminatorValueTextRange(); - } - - protected TextRange getDiscriminatorColumnTextRange() { - return this.resourceTypeMapping.getDiscriminatorColumn().getValidationTextRange(); - } - - protected TextRange getInheritanceStrategyTextRange() { - return this.resourceTypeMapping.getInheritanceStrategyTextRange(); - } - - protected class AssociationOverrideContainerOwner - implements OrmAssociationOverrideContainer.Owner - { - public OrmTypeMapping getTypeMapping() { - return AbstractOrmEntity.this.getTypeMapping(); - } - - public TypeMapping getOverridableTypeMapping() { - return AbstractOrmEntity.this.getOverridableTypeMapping(); - } - - public Iterator<String> allOverridableNames() { - TypeMapping typeMapping = getOverridableTypeMapping(); - return (typeMapping == null) ? - EmptyIterator.<String>instance() - : typeMapping.allOverridableAssociationNames(); - } - - public EList<XmlAssociationOverride> getResourceAssociationOverrides() { - return AbstractOrmEntity.this.resourceTypeMapping.getAssociationOverrides(); - } - - public RelationshipReference resolveRelationshipReference(String associationOverrideName) { - if (!isMetadataComplete()) { - JavaPersistentType javaPersistentType = getPersistentType().getJavaPersistentType(); - if (javaPersistentType != null) { - RelationshipReference relationshipReference = javaPersistentType.getMapping().resolveRelationshipReference(associationOverrideName); - if (relationshipReference != null) { - return relationshipReference; - } - } - } - return MappingTools.resolveRelationshipReference(getOverridableTypeMapping(), associationOverrideName); - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractOrmEntity.this.tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return AbstractOrmEntity.this.associatedTableNamesIncludingInherited(); - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public String getDefaultTableName() { - return AbstractOrmEntity.this.getPrimaryTableName(); - } - - public IMessage buildColumnTableNotValidMessage(BaseOverride override, BaseColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualOverrideColumnTableNotValidMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_TABLE_NOT_VALID, - new String[] { - overrideName, - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public IMessage buildColumnUnresolvedNameMessage(BaseOverride override, NamedColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualColumnUnresolvedNameMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualColumnUnresolvedNameMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {overrideName, column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildColumnUnresolvedReferencedColumnNameMessage(AssociationOverride override, BaseJoinColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualColumnUnresolvedReferencedColumnNameMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME, - new String[] {column.getReferencedColumnName(), column.getReferencedColumnDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualColumnUnresolvedReferencedColumnNameMessage(String overrideName, BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME, - new String[] {overrideName, column.getReferencedColumnName(), column.getReferencedColumnDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildUnspecifiedNameMultipleJoinColumnsMessage(AssociationOverride override, BaseJoinColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualUnspecifiedNameMultipleJoinColumnsMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[0], - column, - textRange - ); - } - - protected IMessage buildVirtualUnspecifiedNameMultipleJoinColumnsMessage(String overrideName, BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[] {overrideName}, - column, - textRange - ); - } - - public IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(AssociationOverride override, BaseJoinColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[0], - column, - textRange - ); - } - - protected IMessage buildVirtualUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(String overrideName, BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[] {overrideName}, - column, - textRange - ); - } - - public TextRange getValidationTextRange() { - return AbstractOrmEntity.this.getValidationTextRange(); - } - } - - - //********** OrmAttributeOverrideContainer.Owner implementation ********* - - protected class AttributeOverrideContainerOwner - implements OrmAttributeOverrideContainer.Owner - { - public OrmTypeMapping getTypeMapping() { - return AbstractOrmEntity.this.getTypeMapping(); - } - - public TypeMapping getOverridableTypeMapping() { - return AbstractOrmEntity.this.getOverridableTypeMapping(); - } - - public Iterator<String> allOverridableNames() { - TypeMapping typeMapping = getOverridableTypeMapping(); - return (typeMapping == null) ? - EmptyIterator.<String>instance() - : allOverridableAttributeNames_(typeMapping); - } - - /* assumes the type mapping is not null */ - protected Iterator allOverridableAttributeNames_(TypeMapping typeMapping) { - final Collection mappedByRelationshipAttributes = CollectionTools.collection( - new TransformationIterator<SingleRelationshipMapping2_0, String>(getMapsIdRelationships()) { - @Override - protected String transform(SingleRelationshipMapping2_0 next) { - return next.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getValue(); - } - }); - return new FilteringIterator<String>(typeMapping.allOverridableAttributeNames()) { - @Override - protected boolean accept(String o) { - if (mappedByRelationshipAttributes.isEmpty()) { - return true; - } - // overrideable names are (usually?) qualified with a container mapping, - // which may also be the one mapped by a relationship - String qualifier = - (o.indexOf('.') > 0) ? - o.substring(0, o.indexOf('.')) - : o; - return ! mappedByRelationshipAttributes.contains(qualifier); - } - }; - } - - protected Iterable<SingleRelationshipMapping2_0> getMapsIdRelationships() { - return new FilteringIterable<SingleRelationshipMapping2_0>( - new SubIterableWrapper<AttributeMapping, SingleRelationshipMapping2_0>( - new CompositeIterable<AttributeMapping>( - getTypeMapping().getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY), - getTypeMapping().getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)))) { - @Override - protected boolean accept(SingleRelationshipMapping2_0 o) { - return o.getDerivedIdentity().usesMapsIdDerivedIdentityStrategy(); - } - }; - } - - public EList<XmlAttributeOverride> getResourceAttributeOverrides() { - return AbstractOrmEntity.this.resourceTypeMapping.getAttributeOverrides(); - } - - public Column resolveOverriddenColumn(String attributeOverrideName) { - if (!isMetadataComplete()) { - JavaPersistentType javaPersistentType = getPersistentType().getJavaPersistentType(); - if (javaPersistentType != null) { - Column column = javaPersistentType.getMapping().resolveOverriddenColumn(attributeOverrideName); - if (column != null) { - return column; - } - } - } - return MappingTools.resolveOverridenColumn(getOverridableTypeMapping(), attributeOverrideName); - } - - public XmlColumn buildVirtualXmlColumn(Column overridableColumn, String attributeName, boolean isMetadataComplete) { - JavaAttributeOverride javaAttributeOverride = null; - if (!isMetadataComplete) { - javaAttributeOverride = getJavaAttributeOverrideNamed(attributeName); - } - if (javaAttributeOverride == null) { - //TODO not the greatest solution here, but things seems to work, so I'm stepping away slowly - if (overridableColumn instanceof JavaColumn) { - return new VirtualXmlColumn(AbstractOrmEntity.this, overridableColumn); - } - return new VirtualXmlAttributeOverrideColumn(overridableColumn); - } - return new VirtualXmlColumn(AbstractOrmEntity.this, javaAttributeOverride.getColumn()); - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractOrmEntity.this.tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return AbstractOrmEntity.this.associatedTableNamesIncludingInherited(); - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public String getDefaultTableName() { - return AbstractOrmEntity.this.getPrimaryTableName(); - } - - public IMessage buildColumnUnresolvedNameMessage(BaseOverride override, NamedColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualColumnUnresolvedNameMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildVirtualColumnUnresolvedNameMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {overrideName, column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildColumnTableNotValidMessage(BaseOverride override, BaseColumn column, TextRange textRange) { - if (override.isVirtual()) { - return this.buildVirtualOverrideColumnTableNotValidMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID, - new String[] {overrideName, - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public TextRange getValidationTextRange() { - return AbstractOrmEntity.this.getValidationTextRange(); - } - } - - - protected class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - public TypeMapping getTypeMapping() { - return AbstractOrmEntity.this; - } - - public String getDefaultTableName() { - return AbstractOrmEntity.this.getPrimaryTableName(); - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return AbstractOrmEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getReferencedColumnDbTable() { - Entity parentEntity = AbstractOrmEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return AbstractOrmEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractOrmEntity.this.defaultPrimaryKeyJoinColumns.contains(joinColumn); - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - Entity parentEntity = AbstractOrmEntity.this.getParentEntity(); - return (parentEntity == null) ? getPrimaryKeyColumnName() : parentEntity.getPrimaryKeyColumnName(); - } - - public TextRange getValidationTextRange() { - return null; - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet: bug 148262"); //$NON-NLS-1$ - } - - public IMessage buildUnresolvedReferencedColumnNameMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet: bug 148262"); //$NON-NLS-1$ - } - - public IMessage buildUnspecifiedNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet: bug 148262"); //$NON-NLS-1$ - } - - public IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet: bug 148262"); //$NON-NLS-1$ - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java deleted file mode 100644 index 696357b668..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.resource.orm.XmlGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * - */ -public abstract class AbstractOrmGenerator<T extends XmlGenerator> - extends AbstractOrmXmlContextNode - implements OrmGenerator -{ - - protected String name; - - protected Integer specifiedInitialValue; - protected int defaultInitialValue; - - protected Integer specifiedAllocationSize; - protected int defaultAllocationSize; - - protected T resourceGenerator; - - - protected AbstractOrmGenerator(XmlContextNode parent) { - super(parent); - } - - protected T getResourceGenerator() { - return this.resourceGenerator; - } - - - // ********** name ********** - - public String getName() { - return this.name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.getResourceGenerator().setName(name); - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - protected void setName_(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - - // ********** initial value ********** - - public int getInitialValue() { - return (this.specifiedInitialValue != null) ? this.specifiedInitialValue.intValue() : this.defaultInitialValue; - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.getResourceGenerator().setInitialValue(specifiedInitialValue); - this.firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer specifiedInitialValue) { - Integer old = this.specifiedInitialValue; - this.specifiedInitialValue = specifiedInitialValue; - this.firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, old, specifiedInitialValue); - } - - public int getDefaultInitialValue() { - return this.defaultInitialValue; - } - - protected void setDefaultInitialValue(int defaultInitialValue) { - int old = this.defaultInitialValue; - this.defaultInitialValue = defaultInitialValue; - this.firePropertyChanged(DEFAULT_INITIAL_VALUE_PROPERTY, old, defaultInitialValue); - } - - - // ********** allocation size ********** - - public int getAllocationSize() { - return (this.specifiedAllocationSize != null) ? this.specifiedAllocationSize.intValue() : this.defaultAllocationSize; - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.getResourceGenerator().setAllocationSize(specifiedAllocationSize); - this.firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer specifiedAllocationSize) { - Integer old = this.specifiedAllocationSize; - this.specifiedAllocationSize = specifiedAllocationSize; - this.firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, old, specifiedAllocationSize); - } - - public int getDefaultAllocationSize() { - return Generator.DEFAULT_ALLOCATION_SIZE; - } - - protected void setDefaultAllocationSize(int defaultAllocationSize) { - int old = this.defaultAllocationSize; - this.defaultAllocationSize = defaultAllocationSize; - this.firePropertyChanged(DEFAULT_ALLOCATION_SIZE_PROPERTY, old, defaultAllocationSize); - } - - - // ********** text ranges ********** - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.getResourceGenerator().getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - TextRange nameTextRange = this.getResourceGenerator().getNameTextRange(); - return nameTextRange != null ? nameTextRange : getValidationTextRange(); - } - - - // ********** resource => context ********** - - protected void initialize(T xmlResourceGenerator) { - this.resourceGenerator = xmlResourceGenerator; - this.name = xmlResourceGenerator.getName(); - this.specifiedInitialValue = xmlResourceGenerator.getInitialValue(); - this.specifiedAllocationSize = xmlResourceGenerator.getAllocationSize(); - //TODO defaults - } - - protected void update(T xmlResourceGenerator) { - this.resourceGenerator = xmlResourceGenerator; - this.setName_(xmlResourceGenerator.getName()); - this.setSpecifiedInitialValue_(xmlResourceGenerator.getInitialValue()); - this.setSpecifiedAllocationSize_(xmlResourceGenerator.getAllocationSize()); - getPersistenceUnit().addGenerator(this); - //TODO defaults - } - - - // ********** database stuff ********** - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - protected abstract String getSchema(); - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - protected abstract String getCatalog(); - - - // ********** misc ********** - - public boolean isVirtual() { - return getResourceGenerator().isVirtual(); - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - public boolean overrides(Generator other) { - // this isn't ideal, but it will have to do until we have further adopter input - return (this.name != null) - && this.name.equals(other.getName()) - && (other instanceof JavaGenerator); - } - - public boolean duplicates(Generator other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.isVirtual() - && ! this.overrides(other) - && ! other.overrides(this); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java deleted file mode 100644 index 6dc07edd24..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmIdMapping.java +++ /dev/null @@ -1,431 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.IdMapping2_0; -import org.eclipse.jpt.core.jpa2.context.SingleRelationshipMapping2_0; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterables.SubIterableWrapper; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmIdMapping<T extends XmlId> - extends AbstractOrmAttributeMapping<T> - implements OrmIdMapping, IdMapping2_0 -{ - protected final OrmColumn column; - - /* 2.0 feature - a relationship may map this id */ - protected boolean mappedByRelationship; - - protected OrmGeneratedValue generatedValue; - - protected OrmConverter converter; - - protected final OrmConverter nullConverter; - - protected final OrmGeneratorContainer generatorContainer; - - - protected AbstractOrmIdMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.resourceAttributeMapping.getColumn());//TODO pass in to constructor - this.mappedByRelationship = calculateMappedByRelationship(); - this.generatorContainer = buildGeneratorContainer(); - this.initializeGeneratedValue(); - this.nullConverter = this.getXmlContextNodeFactory().buildOrmNullConverter(this); - this.converter = this.buildConverter(this.getResourceConverterType()); - } - - - protected OrmGeneratorContainer buildGeneratorContainer() { - return getXmlContextNodeFactory().buildOrmGeneratorContainer(this, this.resourceAttributeMapping); - } - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public int getXmlSequence() { - return 0; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmIdMapping(this); - } - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public OrmColumn getColumn() { - return this.column; - } - - public OrmConverter getConverter() { - return this.converter; - } - - protected String getConverterType() { - return this.converter.getType(); - } - - public void setConverter(String converterType) { - if (this.valuesAreEqual(getConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.converter; - OrmConverter newConverter = buildConverter(converterType); - this.converter = this.nullConverter; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.converter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.converter; - this.converter = newConverter; - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public OrmGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); //$NON-NLS-1$ - } - XmlGeneratedValue resourceGeneratedValue = OrmFactory.eINSTANCE.createXmlGeneratedValue(); - this.generatedValue = buildGeneratedValue(resourceGeneratedValue); - this.resourceAttributeMapping.setGeneratedValue(resourceGeneratedValue); - firePropertyChanged(GENERATED_VALUE_PROPERTY, null, this.generatedValue); - return this.generatedValue; - } - - public void removeGeneratedValue() { - if (getGeneratedValue() == null) { - throw new IllegalStateException("gemeratedValue does not exist, cannot be removed"); //$NON-NLS-1$ - } - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - this.resourceAttributeMapping.setGeneratedValue(null); - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); - } - - public OrmGeneratedValue getGeneratedValue() { - return this.generatedValue; - } - - protected void setGeneratedValue(OrmGeneratedValue newGeneratedValue) { - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = newGeneratedValue; - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, newGeneratedValue); - } - - public OrmGeneratorContainer getGeneratorContainer() { - return this.generatorContainer; - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getIds().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getIds().remove(this.resourceAttributeMapping); - } - - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - protected boolean isColumnSpecified() { - if (! isVirtual()) { - return getResourceColumn() != null; - } - else { - return getJavaResourcePersistentAttribute().getAnnotation(JPA.COLUMN) != null; - } - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - - //************** NamedColumn.Owner implementation *************** - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public String getDefaultColumnName() { - return (isMappedByRelationship() && ! isColumnSpecified()) ? null : getName(); - } - - - //************** BaseColumn.Owner implementation *************** - - public String getDefaultTableName() { - return (isMappedByRelationship() && ! isColumnSpecified()) ? null : getTypeMapping().getPrimaryTableName(); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); - } - - - // **************** IdColumn2_0 impl ************************************** - - public boolean isMappedByRelationship() { - return this.mappedByRelationship; - } - - protected void setMappedByRelationship(boolean newValue) { - boolean oldValue = this.mappedByRelationship; - this.mappedByRelationship = newValue; - firePropertyChanged(MAPPED_BY_RELATIONSHIP_PROPERTY, oldValue, newValue); - } - - protected boolean calculateMappedByRelationship() { - for (SingleRelationshipMapping2_0 each : getMapsIdRelationships()) { - if (each.getDerivedIdentity().getMapsIdDerivedIdentityStrategy().getResolvedAttributeMappingValue() == this) { - return true; - } - } - return false; - } - - protected Iterable<SingleRelationshipMapping2_0> getMapsIdRelationships() { - return new FilteringIterable<SingleRelationshipMapping2_0>( - new SubIterableWrapper<AttributeMapping, SingleRelationshipMapping2_0>( - new CompositeIterable<AttributeMapping>( - getTypeMapping().getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY), - getTypeMapping().getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)))) { - @Override - protected boolean accept(SingleRelationshipMapping2_0 o) { - return o.getDerivedIdentity().usesMapsIdDerivedIdentityStrategy(); - } - }; - } - - - protected void initializeGeneratedValue() { - if (this.resourceAttributeMapping.getGeneratedValue() != null) { - this.generatedValue = buildGeneratedValue(this.resourceAttributeMapping.getGeneratedValue()); - } - } - - protected OrmGeneratedValue buildGeneratedValue(XmlGeneratedValue resourceGeneratedValue) { - return getXmlContextNodeFactory().buildOrmGeneratedValue(this, resourceGeneratedValue); - } - - @Override - public void update() { - super.update(); - this.column.update(getResourceColumn()); - setMappedByRelationship(calculateMappedByRelationship()); - this.generatorContainer.update(); - this.updateGeneratedValue(); - if (this.valuesAreEqual(getResourceConverterType(), getConverterType())) { - getConverter().update(); - } - else { - setConverter(buildConverter(getResourceConverterType())); - } - } - - protected void updateGeneratedValue() { - if (this.resourceAttributeMapping.getGeneratedValue() == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(this.resourceAttributeMapping.getGeneratedValue())); - } - else { - getGeneratedValue().update(this.resourceAttributeMapping.getGeneratedValue()); - } - } - } - - protected OrmConverter buildConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.NO_CONVERTER)) { - return this.nullConverter; - } - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - return Converter.NO_CONVERTER; - } - - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - // [JPA 2.0] if the column is specified, or if the id is not mapped by a relationship, - // then the column is validated. - // (In JPA 1.0, the column will always be validated, since the id is never mapped by a - // relationship) - if (isColumnSpecified() || ! isMappedByRelationship()) { - getColumn().validate(messages, reporter); - } - - // [JPA 2.0] if the column is specified and the id is mapped by a relationship, - // then that is an error - // (In JPA 1.0, this will never be the case, since the id is never mapped by a relationship) - if (isColumnSpecified() && isMappedByRelationship()) { - messages.add( - buildMessage( - JpaValidationMessages.ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_COLUMN_SPECIFIED, - new String[] {}, - getColumn().getValidationTextRange())); - } - - if (this.generatedValue != null) { - this.generatedValue.validate(messages, reporter); - } - this.generatorContainer.validate(messages, reporter); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualUnresolvedNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualTableNotValidMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public IMessage buildVirtualTableNotValidMessage(BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID, - new String[] { - getName(), - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - /* TODO - move to AbstractOrmAttributeMapping? */ - protected IMessage buildMessage(String msgID, String[] params, TextRange textRange) { - String attributeDescString; - PersistentAttribute attribute = getPersistentAttribute(); - if (attribute.isVirtual()) { - attributeDescString = NLS.bind(JpaValidationDescriptionMessages.VIRTUAL_ATTRIBUTE_DESC, attribute.getName()); - } - else { - attributeDescString = NLS.bind(JpaValidationDescriptionMessages.ATTRIBUTE_DESC, attribute.getName()); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, msgID, ArrayTools.add(params, 0, attributeDescString), this, textRange); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.java deleted file mode 100644 index 670a504acd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn.Owner; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumnsMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy - extends AbstractOrmJoinColumnJoiningStrategy -{ - - protected AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy( - OrmJoinColumnEnabledRelationshipReference parent, - XmlJoinColumnsMapping resource) { - super(parent, resource); - } - - @Override - protected Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - @Override - public OrmJoinColumnEnabledRelationshipReference getRelationshipReference() { - return (OrmJoinColumnEnabledRelationshipReference) super.getRelationshipReference(); - } - - protected abstract Entity getRelationshipTargetEntity(); - - public String getColumnTableNotValidDescription() { - return JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY; - } - - public boolean isOverridableAssociation() { - return true; - } - - public TextRange getValidationTextRange() { - return this.getRelationshipReference().getValidationTextRange(); - } - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getTableName(); - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public String getAttributeName() { - return getRelationshipMapping().getName(); - } - - public PersistentAttribute getPersistentAttribute() { - return getRelationshipMapping().getPersistentAttribute(); - } - - public TypeMapping getTypeMapping() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getRelationshipSource(); - } - - public Entity getRelationshipTarget() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getRelationshipTargetEntity(); - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.candidateTableNames(); - } - - public Table getDbTable(String tableName) { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getReferencedColumnDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.defaultJoinColumn == joinColumn; - } - - public int joinColumnsSize() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy.this.getValidationTextRange(); - } - - protected boolean isPersistentAttributeVirtual() { - return getPersistentAttribute().isVirtual(); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualTableNotValidMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - protected IMessage buildVirtualTableNotValidMessage(BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_TABLE_NOT_VALID, - new String[] { - this.getAttributeName(), - column.getTable(), column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualUnresolvedNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {this.getAttributeName(), column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildUnresolvedReferencedColumnNameMessage(BaseJoinColumn column, TextRange textRange) { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualUnresolvedReferencedColumnNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME, - new String[] {column.getReferencedColumnName(), column.getReferencedColumnDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedReferencedColumnNameMessage(BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_REFERENCED_COLUMN_NAME, - new String[] {this.getAttributeName(), column.getReferencedColumnName(), column.getReferencedColumnDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildUnspecifiedNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualUnspecifiedNameMultipleJoinColumnsMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[0], - column, - textRange - ); - } - - protected IMessage buildVirtualUnspecifiedNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[] {this.getAttributeName()}, - column, - textRange - ); - } - - public IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[0], - column, - textRange - ); - } - - protected IMessage buildVirtualUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS, - new String[] {this.getAttributeName()}, - column, - textRange - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java deleted file mode 100644 index 7c1f778da8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Vector; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumnsMapping; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmJoinColumnJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmJoinColumnJoiningStrategy -{ - protected OrmJoinColumn defaultJoinColumn; - - protected final Vector<OrmJoinColumn> specifiedJoinColumns = new Vector<OrmJoinColumn>(); - - protected final OrmJoinColumn.Owner joinColumnOwner; - - protected XmlJoinColumnsMapping resource; - - - protected AbstractOrmJoinColumnJoiningStrategy( - JoinColumnEnabledRelationshipReference parent, - XmlJoinColumnsMapping resource) { - super(parent); - this.resource = resource; - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.initializeSpecifiedJoinColumns(); - this.initializeDefaultJoinColumn(); - } - - public void initializeFrom(JoinColumnJoiningStrategy oldStrategy) { - for (JoinColumn joinColumn : CollectionTools.iterable(oldStrategy.joinColumns())) { - JoinColumn newJoinColumn = this.addSpecifiedJoinColumn(this.specifiedJoinColumnsSize()); - newJoinColumn.setSpecifiedName(joinColumn.getName()); - newJoinColumn.setSpecifiedReferencedColumnName(joinColumn.getReferencedColumnName()); - } - } - - protected abstract OrmJoinColumn.Owner buildJoinColumnOwner(); - - protected void initializeSpecifiedJoinColumns() { - for (XmlJoinColumn resourceJoinColumn : this.resource.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(resourceJoinColumn)); - } - } - - protected void initializeDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - this.defaultJoinColumn = this.buildJoinColumn(null); - } - } - - @Override - public JoinColumnEnabledRelationshipReference getParent() { - return (JoinColumnEnabledRelationshipReference) super.getParent(); - } - - public JoinColumnEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public String getTableName() { - TypeMapping typeMapping = getRelationshipSource(); - return typeMapping == null ? null : getRelationshipSource().getPrimaryTableName(); - } - - public Table getDbTable(String tableName) { - TypeMapping typeMapping = getRelationshipSource(); - return typeMapping == null ? null : typeMapping.getDbTable(tableName); - } - - public boolean tableNameIsInvalid(String tableName) { - TypeMapping typeMapping = getRelationshipSource(); - return typeMapping == null ? false : typeMapping.tableNameIsInvalid(tableName); - } - - protected Iterator<String> candidateTableNames() { - TypeMapping typeMapping = getRelationshipSource(); - return typeMapping == null ? EmptyIterator.<String> instance() : typeMapping.associatedTableNamesIncludingInherited(); - } - - public void addStrategy() { - if (specifiedJoinColumnsSize() == 0) { - addSpecifiedJoinColumn(0); - } - } - - public void removeStrategy() { - for (JoinColumn each : CollectionTools.iterable(specifiedJoinColumns())) { - removeSpecifiedJoinColumn(each); - } - } - - public Table getReferencedColumnDbTable() { - TypeMapping relationshipTarget = getRelationshipTarget(); - return (relationshipTarget == null) ? null : relationshipTarget.getPrimaryDbTable(); - } - - - // **************** join columns ******************************************* - - public ListIterator<OrmJoinColumn> joinColumns() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.hasSpecifiedJoinColumns() ? - this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - - // **************** default join column ************************************ - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn joinColumn) { - OrmJoinColumn old = this.defaultJoinColumn; - this.defaultJoinColumn = joinColumn; - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, old, joinColumn); - } - - protected ListIterator<OrmJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - - // **************** specified join columns ********************************* - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean hasSpecifiedJoinColumns() { - return ! this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn oldDefaultJoinColumn = this.defaultJoinColumn; - if (oldDefaultJoinColumn != null) { - //null the default join column now if one already exists. - //if one does not exist, there is already a specified join column. - //Remove it now so that it doesn't get removed during an update and - //cause change notifications to be sent to the UI in the wrong order - this.defaultJoinColumn = null; - } - XmlJoinColumn resourceJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumn(); - OrmJoinColumn contextJoinColumn = this.buildJoinColumn(resourceJoinColumn); - this.specifiedJoinColumns.add(index, contextJoinColumn); - this.resource.getJoinColumns().add(index, resourceJoinColumn); - this.fireItemAdded(SPECIFIED_JOIN_COLUMNS_LIST, index, contextJoinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, oldDefaultJoinColumn, null); - } - return contextJoinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - protected void addSpecifiedJoinColumn(OrmJoinColumn joinColumn) { - this.addSpecifiedJoinColumn(this.specifiedJoinColumns.size(), joinColumn); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (this.specifiedJoinColumns.isEmpty()) { - //create the defaultJoinColumn now or this will happen during project update - //after removing the join column from the resource model. That causes problems - //in the UI because the change notifications end up in the wrong order. - this.defaultJoinColumn = this.buildJoinColumn(null); - } - this.resource.getJoinColumns().remove(index); - this.fireItemRemoved(SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(DEFAULT_JOIN_COLUMN_PROPERTY, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.resource.getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn resourceJoinColumn) { - return this.getXmlContextNodeFactory().buildOrmJoinColumn(this, this.joinColumnOwner, resourceJoinColumn); - } - - // **************** resource => context ************************************ - - public void update() { - updateSpecifiedJoinColumns(); - updateDefaultJoinColumn(); - } - - protected void updateSpecifiedJoinColumns() { - // make a copy of the XML join columns (to prevent ConcurrentModificationException) - Iterator<XmlJoinColumn> xmlJoinColumns = - new CloneIterator<XmlJoinColumn>(this.resource.getJoinColumns()); - - for (Iterator<OrmJoinColumn> contextJoinColumns = this.specifiedJoinColumns(); - contextJoinColumns.hasNext(); ) { - OrmJoinColumn contextJoinColumn = contextJoinColumns.next(); - if (xmlJoinColumns.hasNext()) { - contextJoinColumn.update(xmlJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(contextJoinColumn); - } - } - - while (xmlJoinColumns.hasNext()) { - addSpecifiedJoinColumn(buildJoinColumn(xmlJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn() { - if (mayHaveDefaultJoinColumn()) { - if (this.defaultJoinColumn == null) { - this.setDefaultJoinColumn(this.buildJoinColumn(null)); - } else { - this.defaultJoinColumn.update(null); - } - } else { - this.setDefaultJoinColumn(null); - } - } - - protected boolean mayHaveDefaultJoinColumn() { - return getRelationshipReference().mayHaveDefaultJoinColumn() - && ! hasSpecifiedJoinColumns(); - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - for (Iterator<OrmJoinColumn> stream = this.joinColumns(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java deleted file mode 100644 index 7cc5d7a7a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJoinTableJoiningStrategy.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.JoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.JoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmJoinTableJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmJoinTableJoiningStrategy -{ - protected OrmJoinTable joinTable; - - - protected AbstractOrmJoinTableJoiningStrategy( - JoinTableEnabledRelationshipReference parent) { - super(parent); - } - - public void initializeFrom(JoinTableJoiningStrategy oldStrategy) { - JoinTable oldJoinTable = (oldStrategy.getJoinTable()); - if (oldJoinTable != null) { - this.addStrategy(); - this.getJoinTable().setSpecifiedCatalog(oldJoinTable.getSpecifiedCatalog()); - this.getJoinTable().setSpecifiedSchema(oldJoinTable.getSpecifiedSchema()); - this.getJoinTable().setSpecifiedName(oldJoinTable.getSpecifiedName()); - } - } - - @Override - public JoinTableEnabledRelationshipReference getParent() { - return (JoinTableEnabledRelationshipReference) super.getParent(); - } - - public JoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public RelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public String getTableName() { - return getJoinTable().getName(); - } - - public Table getDbTable(String tableName) { - return getJoinTable().getDbTable(); - } - - public boolean tableNameIsInvalid(String tableName) { - return !StringTools.stringsAreEqual(getTableName(), tableName); - } - - public String getColumnTableNotValidDescription() { - return JpaValidationDescriptionMessages.DOES_NOT_MATCH_JOIN_TABLE; - } - - public String getJoinTableDefaultName() { - return MappingTools.buildJoinTableDefaultName(this.getRelationshipReference()); - } - - public void addStrategy() { - if (this.joinTable == null) { - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - this.joinTable = getXmlContextNodeFactory().buildOrmJoinTable(this, resourceJoinTable); - setResourceJoinTable(resourceJoinTable); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, null, this.joinTable); - } - } - - public void removeStrategy() { - if (this.joinTable != null) { - OrmJoinTable oldJoinTable = this.joinTable; - this.joinTable = null; - removeResourceJoinTable(); - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, null); - } - } - - protected abstract void setResourceJoinTable(XmlJoinTable resourceJoinTable); - - - // **************** join table ********************************************* - - public OrmJoinTable getJoinTable() { - return this.joinTable; - } - - public OrmJoinTable addJoinTable() { - addStrategy(); - return this.joinTable; - } - - protected void setJoinTable_(OrmJoinTable newJoinTable) { - OrmJoinTable oldJoinTable = this.joinTable; - this.joinTable = newJoinTable; - this.firePropertyChanged(JOIN_TABLE_PROPERTY, oldJoinTable, newJoinTable); - } - - public XmlJoinTable addResourceJoinTable() { - XmlJoinTable resourceJoinTable = OrmFactory.eINSTANCE.createXmlJoinTable(); - setResourceJoinTable(resourceJoinTable); - return resourceJoinTable; - } - - protected boolean mayHaveJoinTable() { - return getResourceJoinTable() != null - || getRelationshipReference().mayHaveDefaultJoinTable(); - } - - - // **************** resource -> context ************************************ - - protected void initialize() { - if (mayHaveJoinTable()) { - this.joinTable = getXmlContextNodeFactory().buildOrmJoinTable(this, getResourceJoinTable()); - } - } - - public void update() { - if (mayHaveJoinTable()) { - if (this.joinTable == null) { - setJoinTable_(getXmlContextNodeFactory().buildOrmJoinTable(this, getResourceJoinTable())); - } - this.joinTable.update(); - } - else { - if (this.joinTable != null) { - // no resource, so no clean up - setJoinTable_(null); - } - } - } - - - // **************** validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - if (this.joinTable != null) { - this.joinTable.validate(messages, reporter); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java deleted file mode 100644 index 51be06cd62..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToManyMapping.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToManyMapping2_0; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; - -public abstract class AbstractOrmManyToManyMapping<T extends XmlManyToMany> - extends AbstractOrmMultiRelationshipMapping<T> - implements OrmManyToManyMapping2_0 -{ - protected AbstractOrmManyToManyMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - - @Override - protected OrmRelationshipReference buildRelationshipReference() { - return new GenericOrmManyToManyRelationshipReference(this, this.resourceAttributeMapping); - } - - public int getXmlSequence() { - return 70; - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToManyMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToManys().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToManys().remove(this.resourceAttributeMapping); - } - - @Override - public OrmManyToManyRelationshipReference getRelationshipReference() { - return (OrmManyToManyRelationshipReference) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java deleted file mode 100644 index 086df36c77..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneMapping.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneRelationshipReference2_0; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - - -public abstract class AbstractOrmManyToOneMapping<T extends XmlManyToOne> - extends AbstractOrmSingleRelationshipMapping<T> - implements OrmManyToOneMapping2_0 -{ - protected AbstractOrmManyToOneMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - } - - - public int getXmlSequence() { - return 40; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToOneMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToOnes().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getManyToOnes().remove(this.resourceAttributeMapping); - } - - @Override - public OrmManyToOneRelationshipReference2_0 getRelationshipReference() { - return (OrmManyToOneRelationshipReference2_0) super.getRelationshipReference(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneRelationshipReference.java deleted file mode 100644 index b4cd104670..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmManyToOneRelationshipReference.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneRelationshipReference2_0; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmManyToOneRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmManyToOneRelationshipReference2_0 -{ - protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - protected AbstractOrmManyToOneRelationshipReference( - OrmManyToOneMapping parent, XmlManyToOne resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericOrmJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - protected abstract OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy(); - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromJoinColumnEnabledRelationshipReference(this); - } - - @Override - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - int index = 0; - for (JoinColumn joinColumn : - CollectionTools.iterable( - oldRelationshipReference.getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - @Override - public OrmManyToOneMapping getRelationshipMapping() { - return (OrmManyToOneMapping) getParent(); - } - - public XmlManyToOne getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return true; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return false; - } - - - // **************** join columns ******************************************* - - public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - // join columns are default (only strategy in fact) so no need to add to resource - setPredominantJoiningStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return this.getJoinTableJoiningStrategy().getJoinTable() == null; - } - - // **************** join table ********************************************* - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public final void setJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public final void unsetJoinTableJoiningStrategy() { - unsetJoinTableJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void unsetJoinTableJoiningStrategy_() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return false; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.joinTableJoiningStrategy.update(); - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java deleted file mode 100644 index bd30ea7c6b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaIdClassReference; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmIdClassReference; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; -import org.eclipse.jpt.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmMappedSuperclass extends AbstractOrmTypeMapping<XmlMappedSuperclass> - implements OrmMappedSuperclass -{ - protected final OrmIdClassReference idClassReference; - - - protected AbstractOrmMappedSuperclass(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { - super(parent, resourceMapping); - this.idClassReference = buildIdClassReference(); - } - - - protected OrmIdClassReference buildIdClassReference() { - return new GenericOrmIdClassReference(this, getJavaIdClassReferenceForDefaults()); - } - - public int getXmlSequence() { - return 0; - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - @Override - public JavaPersistentType getIdClass() { - return this.idClassReference.getIdClass(); - } - - - // **************** id class ********************************************** - - public OrmIdClassReference getIdClassReference() { - return this.idClassReference; - } - - - // ************************************************************************ - - public JavaMappedSuperclass getJavaMappedSuperclass() { - JavaPersistentType javaPersistentType = this.getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY) { - return (JavaMappedSuperclass) javaPersistentType.getMapping(); - } - return null; - } - - /** - * This checks metaDataComplete before returning the JavaMappedSuperclass. - * As far as defaults are concerned, if metadataComplete is true, the JavaMappedSuperclass is ignored. - */ - protected JavaMappedSuperclass getJavaMappedSuperclassForDefaults() { - if (isMetadataComplete()) { - return null; - } - return getJavaMappedSuperclass(); - } - - protected JavaIdClassReference getJavaIdClassReferenceForDefaults() { - JavaMappedSuperclass javaMappedSuperclass = getJavaMappedSuperclassForDefaults(); - return (javaMappedSuperclass == null) ? null : javaMappedSuperclass.getIdClassReference(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - @Override - public boolean shouldValidateAgainstDatabase() { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public void addToResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().add(this.resourceTypeMapping); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().remove(this.resourceTypeMapping); - } - - @Override - public void update() { - super.update(); - this.idClassReference.update(getJavaIdClassReferenceForDefaults()); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - validatePrimaryKey(messages, reporter); - } - - protected void validatePrimaryKey(List<IMessage> messages, IReporter reporter) { - buildPrimaryKeyValidator().validate(messages, reporter); - } - - protected PrimaryKeyValidator buildPrimaryKeyValidator() { - return new GenericMappedSuperclassPrimaryKeyValidator(this, buildTextRangeResolver()); - // TODO - JPA 2.0 validation - } - - protected PrimaryKeyTextRangeResolver buildTextRangeResolver() { - return new OrmMappedSuperclassTextRangeResolver(this); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java deleted file mode 100644 index e460f4a76a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ /dev/null @@ -1,869 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.CollectionMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.Orderable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmOrderable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.Orderable2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmPersistentAttribute2_0; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.orm.AbstractXmlMultiRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlClassReference; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * ORM multi-relationship (m:m, 1:m) mapping - */ -public abstract class AbstractOrmMultiRelationshipMapping<T extends AbstractXmlMultiRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmMultiRelationshipMapping, OrmCollectionMapping2_0 -{ - protected final OrmOrderable orderable; - - protected String specifiedMapKey; - protected boolean noMapKey = false; - protected boolean pkMapKey = false; - protected boolean customMapKey = false; - - protected String specifiedMapKeyClass; - protected String defaultMapKeyClass; - protected PersistentType resolvedMapKeyType; - protected Embeddable resolvedMapKeyEmbeddable; - protected Entity resolvedMapKeyEntity; - - protected Embeddable resolvedTargetEmbeddable; - - protected Type valueType; - protected Type keyType; - - protected final OrmColumn mapKeyColumn; - - protected final OrmAttributeOverrideContainer mapKeyAttributeOverrideContainer; - - protected AbstractOrmMultiRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.orderable = this.buildOrderable(); - this.resolvedTargetEmbeddable = this.resolveTargetEmbeddable(); - this.valueType = this.buildValueType(); - this.resolvedMapKeyType = this.resolveMapKeyType(); - this.resolvedMapKeyEmbeddable = this.resolveMapKeyEmbeddable(); - this.resolvedMapKeyEntity = this.resolveMapKeyEntity(); - this.initializeMapKey(); - this.defaultMapKeyClass = this.buildDefaultMapKeyClass(); - this.specifiedMapKeyClass = this.getResourceMapKeyClass(); - this.mapKeyColumn = getXmlContextNodeFactory().buildOrmColumn(this, this.buildMapKeyColumnOwner()); - this.mapKeyAttributeOverrideContainer = buildMapKeyAttributeOverrideContainer(); - } - - @Override - public void update() { - super.update(); - this.orderable.update(); - this.resolvedTargetEmbeddable = this.resolveTargetEmbeddable(); - this.updateValueType(); - this.setSpecifiedMapKeyClass_(this.getResourceMapKeyClass()); - this.setDefaultMapKeyClass(this.buildDefaultMapKeyClass()); - this.resolvedMapKeyType = this.resolveMapKeyType();//no need for change notification, use resolved target embeddable change notification instead? - this.setResolvedMapKeyEmbeddable(this.resolveMapKeyEmbeddable()); - this.setResolvedMapKeyEntity(this.resolveMapKeyEntity()); - this.updateKeyType(); - this.updateMapKey(); - this.setDefaultMapKeyClass(this.buildDefaultMapKeyClass()); - this.setSpecifiedMapKeyClass_(this.getResourceMapKeyClass()); - this.mapKeyColumn.update(getResourceMapKeyColumn()); - this.mapKeyColumn.update(getResourceMapKeyColumn()); - this.mapKeyAttributeOverrideContainer.update(); -} - - @Override - protected String getResourceDefaultTargetEntity() { - return this.getJavaPersistentAttribute().getMultiReferenceTargetTypeName(); - } - - public FetchType getDefaultFetch() { - return CollectionMapping.DEFAULT_FETCH_TYPE; - } - - // **************** order by *********************************************** - - protected OrmOrderable buildOrderable() { - return this.isJpa2_0Compatible() ? - this.getXmlContextNodeFactory().buildOrmOrderable(this, this.buildOrderableOwner()) : - this.getXmlContextNodeFactory().buildOrmOrderable(this, new Orderable.Owner() {/*nothing*/}); - } - - public OrmOrderable getOrderable() { - return this.orderable; - } - - protected Orderable2_0.Owner buildOrderableOwner() { - return new Orderable2_0.Owner() { - public String getTableName() { - return getRelationshipReference().getPredominantJoiningStrategy().getTableName(); - } - public Table getDbTable(String tableName) { - return getRelationshipReference().getPredominantJoiningStrategy().getDbTable(tableName); - } - }; - } - - // ********** CollectionMapping implementation ********** - - protected Embeddable resolveTargetEmbeddable() { - if (this.resolvedTargetType == null) { - return null; - } - TypeMapping typeMapping = this.resolvedTargetType.getMapping(); - return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; - } - - public Embeddable getResolvedMapKeyEmbeddable() { - return this.resolvedMapKeyEmbeddable; - } - - protected void setResolvedMapKeyEmbeddable(Embeddable embeddable) { - Embeddable old = this.resolvedMapKeyEmbeddable; - this.resolvedMapKeyEmbeddable = embeddable; - this.firePropertyChanged(RESOLVED_MAP_KEY_EMBEDDABLE_PROPERTY, old, embeddable); - } - - public Entity getResolvedMapKeyEntity() { - return this.resolvedMapKeyEntity; - } - - protected void setResolvedMapKeyEntity(Entity entity) { - Entity old = this.resolvedMapKeyEntity; - this.resolvedMapKeyEntity = entity; - this.firePropertyChanged(RESOLVED_MAP_KEY_ENTITY_PROPERTY, old, entity); - } - - public PersistentType getResolvedMapKeyType() { - return getResolvedMapKeyEmbeddable() == null ? null : getResolvedMapKeyEmbeddable().getPersistentType(); - } - - protected PersistentType resolveMapKeyType() { - return this.resolvePersistentType(this.getMapKeyClass()); - } - - protected Embeddable resolveMapKeyEmbeddable() { - if (this.resolvedMapKeyType == null) { - return null; - } - TypeMapping typeMapping = this.resolvedMapKeyType.getMapping(); - return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; - } - - protected Entity resolveMapKeyEntity() { - if (this.resolvedMapKeyType == null) { - return null; - } - TypeMapping typeMapping = this.resolvedMapKeyType.getMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - // **************** value type ************************************************ - - public Type getValueType() { - return this.valueType; - } - - protected void setValueType(Type newValueType) { - Type old = this.valueType; - this.valueType = newValueType; - firePropertyChanged(VALUE_TYPE_PROPERTY, old, newValueType); - } - - protected Type buildValueType() { - if (this.getResolvedTargetEntity() != null) { - return Type.ENTITY_TYPE; - } - else if (this.resolvedTargetEmbeddable != null) { - return Type.EMBEDDABLE_TYPE; - } - else if (getTargetEntity() == null) { - return Type.NO_TYPE; - } - return Type.BASIC_TYPE; - } - - protected void initializeValueType() { - this.valueType = this.buildValueType(); - } - - protected void updateValueType() { - this.setValueType(this.buildValueType()); - } - - // **************** key type ************************************************ - - public Type getKeyType() { - return this.keyType; - } - - protected void setKeyType(Type newKeyType) { - Type old = this.keyType; - this.keyType = newKeyType; - firePropertyChanged(KEY_TYPE_PROPERTY, old, newKeyType); - } - - protected Type buildKeyType() { - if (getResolvedMapKeyEmbeddable() != null) { - return Type.EMBEDDABLE_TYPE; - } - if (getResolvedMapKeyEntity() != null) { - return Type.ENTITY_TYPE; - } - else if (getMapKeyClass() == null) { - return Type.NO_TYPE; - } - return Type.BASIC_TYPE; - } - - protected void initializeKeyType() { - this.keyType = this.buildKeyType(); - } - - protected void updateKeyType() { - this.setKeyType(this.buildKeyType()); - } - - // **************** map key ************************************************ - - public String getMapKey() { - if (this.noMapKey) { - return null; - } - if (this.pkMapKey) { - return this.getTargetEntityIdAttributeName(); - } - if (this.customMapKey) { - return this.specifiedMapKey; - } - throw new IllegalStateException("unknown map key"); //$NON-NLS-1$ - } - - public String getSpecifiedMapKey() { - return this.specifiedMapKey; - } - - public void setSpecifiedMapKey(String mapKey) { - String old = this.specifiedMapKey; - this.specifiedMapKey = mapKey; - if (this.attributeValueHasChanged(old, mapKey)) { - MapKey xmlMapKey = this.getXmlMapKey(); - if (mapKey == null) { - if (xmlMapKey != null) { - this.removeXmlMapKey(); - } - } else { - if (xmlMapKey == null) { - xmlMapKey = this.addXmlMapKey(); - } - xmlMapKey.setName(mapKey); - } - } - this.firePropertyChanged(SPECIFIED_MAP_KEY_PROPERTY, old, mapKey); - } - - protected void setSpecifiedMapKey_(String mapKey) { - String old = this.specifiedMapKey; - this.specifiedMapKey = mapKey; - this.firePropertyChanged(SPECIFIED_MAP_KEY_PROPERTY, old, mapKey); - } - - protected void initializeMapKey() { - MapKey xmlMapKey = this.getXmlMapKey(); - if (xmlMapKey == null) { - this.noMapKey = true; - } else { - this.specifiedMapKey = xmlMapKey.getName(); - if (this.specifiedMapKey == null) { - this.pkMapKey = true; - } else { - this.customMapKey = true; - } - } - } - - protected void updateMapKey() { - MapKey xmlMapKey = this.getXmlMapKey(); - if (xmlMapKey == null) { - this.setSpecifiedMapKey_(null); - this.setNoMapKey_(true); - this.setPkMapKey_(false); - this.setCustomMapKey_(false); - } else { - String mk = xmlMapKey.getName(); - this.setSpecifiedMapKey_(mk); - this.setNoMapKey_(false); - this.setPkMapKey_(mk == null); - this.setCustomMapKey_(mk != null); - } - } - - protected MapKey getXmlMapKey() { - return this.resourceAttributeMapping.getMapKey(); - } - - protected MapKey addXmlMapKey() { - MapKey mapKey = OrmFactory.eINSTANCE.createMapKey(); - this.resourceAttributeMapping.setMapKey(mapKey); - return mapKey; - } - - protected void removeXmlMapKey() { - this.resourceAttributeMapping.setMapKey(null); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - - - // **************** no map key *********************************************** - - public boolean isNoMapKey() { - return this.noMapKey; - } - - public void setNoMapKey(boolean noMapKey) { - boolean old = this.noMapKey; - this.noMapKey = noMapKey; - if (noMapKey) { - if (this.getXmlMapKey() != null) { - this.removeXmlMapKey(); - } - } - this.firePropertyChanged(NO_MAP_KEY_PROPERTY, old, noMapKey); - } - - protected void setNoMapKey_(boolean noMapKey) { - boolean old = this.noMapKey; - this.noMapKey = noMapKey; - this.firePropertyChanged(NO_MAP_KEY_PROPERTY, old, noMapKey); - } - - - // **************** pk map key *********************************************** - - public boolean isPkMapKey() { - return this.pkMapKey; - } - - public void setPkMapKey(boolean pkMapKey) { - boolean old = this.pkMapKey; - this.pkMapKey = pkMapKey; - MapKey xmlMapKey = this.getXmlMapKey(); - if (pkMapKey) { - if (xmlMapKey == null) { - this.addXmlMapKey(); - } else { - xmlMapKey.setName(null); - } - } - this.firePropertyChanged(PK_MAP_KEY_PROPERTY, old, pkMapKey); - } - - protected void setPkMapKey_(boolean pkMapKey) { - boolean old = this.pkMapKey; - this.pkMapKey = pkMapKey; - this.firePropertyChanged(PK_MAP_KEY_PROPERTY, old, pkMapKey); - } - - - // **************** custom map key *********************************************** - - public boolean isCustomMapKey() { - return this.customMapKey; - } - - public void setCustomMapKey(boolean customMapKey) { - boolean old = this.customMapKey; - this.customMapKey = customMapKey; - if (customMapKey) { - this.setSpecifiedMapKey(""); //$NON-NLS-1$ - } - this.firePropertyChanged(CUSTOM_MAP_KEY_PROPERTY, old, customMapKey); - } - - protected void setCustomMapKey_(boolean customMapKey) { - boolean old = this.customMapKey; - this.customMapKey = customMapKey; - this.firePropertyChanged(CUSTOM_MAP_KEY_PROPERTY, old, customMapKey); - } - - - // **************** map key class ****************************************** - - public char getMapKeyClassEnclosingTypeSeparator() { - return '$'; - } - - public String getMapKeyClass() { - return (this.specifiedMapKeyClass != null) ? this.specifiedMapKeyClass : this.defaultMapKeyClass; - } - - public String getSpecifiedMapKeyClass() { - return this.specifiedMapKeyClass; - } - - public void setSpecifiedMapKeyClass(String mapKeyClass) { - String old = this.specifiedMapKeyClass; - this.specifiedMapKeyClass = mapKeyClass; - if (this.attributeValueHasChanged(old, mapKeyClass)) { - XmlClassReference xmlMapKeyClass = this.getXmlMapKeyClass(); - if (mapKeyClass == null) { - if (xmlMapKeyClass != null) { - this.removeXmlMapKeyClass(); - } - } else { - if (xmlMapKeyClass == null) { - xmlMapKeyClass = this.addXmlMapKeyClass(); - } - xmlMapKeyClass.setClassName(mapKeyClass); - } - } - this.firePropertyChanged(SPECIFIED_MAP_KEY_CLASS_PROPERTY, old, mapKeyClass); - } - - protected void setSpecifiedMapKeyClass_(String mapKeyClass) { - String old = this.specifiedMapKeyClass; - this.specifiedMapKeyClass = mapKeyClass; - this.firePropertyChanged(SPECIFIED_MAP_KEY_CLASS_PROPERTY, old, mapKeyClass); - } - - protected XmlClassReference getXmlMapKeyClass() { - return this.resourceAttributeMapping.getMapKeyClass(); - } - - protected XmlClassReference addXmlMapKeyClass() { - XmlClassReference mapKeyClass = OrmFactory.eINSTANCE.createXmlClassReference(); - this.resourceAttributeMapping.setMapKeyClass(mapKeyClass); - return mapKeyClass; - } - - protected void removeXmlMapKeyClass() { - this.resourceAttributeMapping.setMapKeyClass(null); - } - - public String getDefaultMapKeyClass() { - return this.defaultMapKeyClass; - } - - protected void setDefaultMapKeyClass(String mapKeyClass) { - String old = this.defaultMapKeyClass; - this.defaultMapKeyClass = mapKeyClass; - this.firePropertyChanged(DEFAULT_MAP_KEY_CLASS_PROPERTY, old, mapKeyClass); - } - - protected String getResourceMapKeyClass() { - XmlClassReference mapKeyClass = this.resourceAttributeMapping.getMapKeyClass(); - return mapKeyClass == null ? null : mapKeyClass.getClassName(); - } - - protected String buildDefaultMapKeyClass() { - if (this.getJavaPersistentAttribute() != null) { - return this.getJavaPersistentAttribute().getMultiReferenceMapKeyTypeName(); - } - return null; - } - - // ************** value column ******************************************** - - public OrmColumn getMapKeyColumn() { - return this.mapKeyColumn; - } - - protected XmlColumn getResourceMapKeyColumn() { - return this.resourceAttributeMapping.getMapKeyColumn(); - } - - protected OrmColumn.Owner buildMapKeyColumnOwner() { - return new MapKeyColumnOwner(); - } - - public OrmAttributeOverrideContainer getMapKeyAttributeOverrideContainer() { - return this.mapKeyAttributeOverrideContainer; - } - - protected OrmAttributeOverrideContainer buildMapKeyAttributeOverrideContainer() { - return getXmlContextNodeFactory().buildOrmAttributeOverrideContainer(this, new MapKeyAttributeOverrideContainerOwner()); - } - - protected JavaAttributeOverride getJavaMapKeyAttributeOverrideNamed(String attributeName) { - if (getJavaMultiRelationshipMapping() != null) { - return getJavaMultiRelationshipMapping().getMapKeyAttributeOverrideContainer().getAttributeOverrideNamed(attributeName); - } - return null; - } - - protected JavaCollectionMapping2_0 getJavaMultiRelationshipMapping() { - if (this.getJavaPersistentAttribute() == null) { - return null; - } - AttributeMapping javaAttributeMapping = this.getJavaPersistentAttribute().getMapping(); - if (javaAttributeMapping.getKey() == this.getKey()) { - return ((JavaCollectionMapping2_0) javaAttributeMapping); - } - return null; - } - - // ********** metamodel ********** - - @Override - protected String getMetamodelFieldTypeName() { - return ((OrmPersistentAttribute2_0) getPersistentAttribute()).getMetamodelContainerFieldTypeName(); - } - - @Override - protected void addMetamodelFieldTypeArgumentNamesTo(ArrayList<String> typeArgumentNames) { - this.addMetamodelFieldMapKeyTypeArgumentNameTo(typeArgumentNames); - super.addMetamodelFieldTypeArgumentNamesTo(typeArgumentNames); - } - - protected void addMetamodelFieldMapKeyTypeArgumentNameTo(ArrayList<String> typeArgumentNames) { - String keyTypeName = ((OrmPersistentAttribute2_0) this.getPersistentAttribute()).getMetamodelContainerFieldMapKeyTypeName(); - if (keyTypeName != null) { - typeArgumentNames.add(keyTypeName); - } - } - - public String getMetamodelFieldMapKeyTypeName() { - return MappingTools.getMetamodelFieldMapKeyTypeName(this); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.orderable.validate(messages, reporter); - this.validateMapKey(messages, reporter); - } - - public void validateMapKey(List<IMessage> messages, IReporter reporter) { - if (getMapKey() != null || getMapKeyAnnotation() != null) { - //TODO validate that the map key refers to an existing attribute - return; - } - if (getKeyType() == Type.BASIC_TYPE) { - this.getMapKeyColumn().validate(messages, reporter); - //validate map key converter - } - else if (getKeyType() == Type.ENTITY_TYPE) { - //validate map key join columns - } - else if (getKeyType() == Type.EMBEDDABLE_TYPE) { - getMapKeyAttributeOverrideContainer().validate(messages, reporter); - //validate map key association overrides - } - } - protected MapKeyAnnotation getMapKeyAnnotation() { - if (!isVirtual()) { - return null; - } - JavaResourcePersistentAttribute jrpa = getJavaResourcePersistentAttribute(); - return jrpa == null ? null : (MapKeyAnnotation) jrpa.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - - protected class MapKeyColumnOwner implements OrmColumn.Owner { - public TypeMapping getTypeMapping() { - return AbstractOrmMultiRelationshipMapping.this.getTypeMapping(); - } - - protected OrmJoiningStrategy getPredominantJoiningStrategy() { - return getRelationshipReference().getPredominantJoiningStrategy(); - } - - public String getDefaultTableName() { - return getPredominantJoiningStrategy().getTableName(); - } - - public Table getDbTable(String tableName) { - return getPredominantJoiningStrategy().getDbTable(tableName); - } - - public String getDefaultColumnName() { - return AbstractOrmMultiRelationshipMapping.this.getName() + "_KEY"; //$NON-NLS-1$ - } - - public boolean tableNameIsInvalid(String tableName) { - return getRelationshipReference().getPredominantJoiningStrategy().tableNameIsInvalid(tableName); - } - - public java.util.Iterator<String> candidateTableNames() { - return EmptyIterator.instance(); - } - - public XmlColumn getResourceColumn() { - return AbstractOrmMultiRelationshipMapping.this.resourceAttributeMapping.getMapKeyColumn(); - } - - public void addResourceColumn() { - AbstractOrmMultiRelationshipMapping.this.resourceAttributeMapping.setMapKeyColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - AbstractOrmMultiRelationshipMapping.this.resourceAttributeMapping.setMapKeyColumn(null); - } - - public TextRange getValidationTextRange() { - return AbstractOrmMultiRelationshipMapping.this.getValidationTextRange(); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualTableNotValidMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAP_KEY_COLUMN_TABLE_NOT_VALID, - new String[] {column.getTable(), column.getName(), getPredominantJoiningStrategy().getColumnTableNotValidDescription()}, - column, - textRange - ); - } - - protected IMessage buildVirtualTableNotValidMessage(BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_TABLE_NOT_VALID, - new String[] {getName(), column.getTable(), column.getName(), getPredominantJoiningStrategy().getColumnTableNotValidDescription()}, - column, - textRange - ); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualUnresolvedNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAP_KEY_COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - } - - protected class MapKeyAttributeOverrideContainerOwner - implements OrmAttributeOverrideContainer.Owner - { - public OrmTypeMapping getTypeMapping() { - return AbstractOrmMultiRelationshipMapping.this.getTypeMapping(); - } - - public TypeMapping getOverridableTypeMapping() { - return AbstractOrmMultiRelationshipMapping.this.getResolvedMapKeyEmbeddable(); - } - - public Iterator<String> allOverridableNames() { - TypeMapping typeMapping = getOverridableTypeMapping(); - return (typeMapping == null) ? - EmptyIterator.<String>instance() - : typeMapping.allOverridableAttributeNames(); - } - - protected JavaAttributeOverride getJavaAttributeOverrideNamed(String attributeName) { - return AbstractOrmMultiRelationshipMapping.this.getJavaMapKeyAttributeOverrideNamed(attributeName); - } - - public EList<XmlAttributeOverride> getResourceAttributeOverrides() { - return AbstractOrmMultiRelationshipMapping.this.resourceAttributeMapping.getMapKeyAttributeOverrides(); - } - - public Column resolveOverriddenColumn(String attributeOverrideName) { - if (getPersistentAttribute().isVirtual() && !getTypeMapping().isMetadataComplete()) { - JavaAttributeOverride javaAttributeOverride = getJavaAttributeOverrideNamed(attributeOverrideName); - if (javaAttributeOverride != null && !javaAttributeOverride.isVirtual()) { - return javaAttributeOverride.getColumn(); - } - } - return MappingTools.resolveOverridenColumn(getOverridableTypeMapping(), attributeOverrideName); - } - - - public XmlColumn buildVirtualXmlColumn(Column overridableColumn, String attributeName, boolean isMetadataComplete) { - return new VirtualXmlAttributeOverrideColumn(overridableColumn); - } - - protected OrmJoiningStrategy getPredominantJoiningStrategy() { - return getRelationshipReference().getPredominantJoiningStrategy(); - } - - public String getDefaultTableName() { - return getPredominantJoiningStrategy().getTableName(); - } - - public Table getDbTable(String tableName) { - return getPredominantJoiningStrategy().getDbTable(tableName); - } - - public java.util.Iterator<String> candidateTableNames() { - return EmptyIterator.instance(); - } - - /** - * If there is a specified table name it needs to be the same - * the default table name. the table is always the collection table - */ - public boolean tableNameIsInvalid(String tableName) { - return !StringTools.stringsAreEqual(getDefaultTableName(), tableName); - } - - public IMessage buildColumnUnresolvedNameMessage(BaseOverride override, NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualAttributeColumnUnresolvedNameMessage(override.getName(), column, textRange); - } - if (override.isVirtual()) { - return this.buildVirtualOverrideColumnUnresolvedNameMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] { - column.getName(), - column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualAttributeColumnUnresolvedNameMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] { - AbstractOrmMultiRelationshipMapping.this.getName(), - overrideName, - column.getName(), - column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideColumnUnresolvedNameMessage(String overrideName, NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] { - overrideName, - column.getName(), - column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildColumnTableNotValidMessage(BaseOverride override, BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualAttributeColumnTableNotValidMessage(override.getName(), column, textRange); - } - if (override.isVirtual()) { - return this.buildVirtualOverrideColumnTableNotValidMessage(override.getName(), column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - getPredominantJoiningStrategy().getColumnTableNotValidDescription()}, - column, - textRange - ); - } - - protected IMessage buildVirtualAttributeColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID, - new String[] { - AbstractOrmMultiRelationshipMapping.this.getName(), - overrideName, - column.getTable(), - column.getName(), - getPredominantJoiningStrategy().getColumnTableNotValidDescription()}, - column, - textRange - ); - } - - protected IMessage buildVirtualOverrideColumnTableNotValidMessage(String overrideName, BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_MAP_KEY_ATTRIBUTE_OVERRIDE_COLUMN_TABLE_NOT_VALID, - new String[] { - overrideName, - column.getTable(), - column.getName(), - getPredominantJoiningStrategy().getColumnTableNotValidDescription()}, - column, - textRange - ); - } - - public TextRange getValidationTextRange() { - return AbstractOrmMultiRelationshipMapping.this.getValidationTextRange(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java deleted file mode 100644 index cca8d0cb49..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.AbstractXmlNamedColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmNamedColumn<T extends AbstractXmlNamedColumn> extends AbstractOrmXmlContextNode - implements OrmNamedColumn -{ - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractOrmNamedColumn(XmlContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - public void initializeFrom(NamedColumn oldColumn) { - setSpecifiedName(oldColumn.getSpecifiedName()); - setColumnDefinition(oldColumn.getColumnDefinition()); - } - - protected abstract T getResourceColumn(); - - protected abstract void removeResourceColumn(); - - protected abstract void addResourceColumn(); - - protected void removeResourceColumnIfFeaturesUnset() { - if (this.getResourceColumn().isUnset()) { - removeResourceColumn(); - } - } - - public Owner getOwner() { - return this.owner; - } - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - if (this.attributeValueHasChanged(oldSpecifiedName, newSpecifiedName)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setName(newSpecifiedName); - this.removeResourceColumnIfFeaturesUnset(); - } - else if (newSpecifiedName != null) { - addResourceColumn(); - getResourceColumn().setName(newSpecifiedName); - } - } - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - if (this.attributeValueHasChanged(oldColumnDefinition, newColumnDefinition)) { - if (this.getResourceColumn() != null) { - this.getResourceColumn().setColumnDefinition(newColumnDefinition); - this.removeResourceColumnIfFeaturesUnset(); - } - else if (newColumnDefinition != null) { - addResourceColumn(); - getResourceColumn().setColumnDefinition(newColumnDefinition); - } - } - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - protected void setColumnDefinition_(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.getColumnForIdentifier(getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.getTable()); - } - - /** - * Return the name of the column's table. This is overridden - * in AbstractOrmBaseColumn where a table can be defined. - */ - public String getTable() { - return this.getOwner().getTypeMapping().getPrimaryTableName(); - } - - public boolean isResolved() { - return getDbColumn() != null; - } - - public TextRange getNameTextRange() { - if (getResourceColumn() != null) { - TextRange textRange = getResourceColumn().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - TextRange textRange = getResourceColumn().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - return getOwner().getValidationTextRange(); - } - - - // ******************* initialization from orm xml resource model ******************** - - protected void initialize(T column) { - this.specifiedName = this.getResourceColumnName(column); - this.defaultName = this.buildDefaultName(); - this.columnDefinition = this.getResourceColumnDefinition(column); - } - - protected void update(T column) { - setSpecifiedName_(this.getResourceColumnName(column)); - setDefaultName(this.buildDefaultName()); - setColumnDefinition_(this.getResourceColumnDefinition(column)); - } - - protected String getResourceColumnName(T column) { - return column == null ? null : column.getName(); - } - - protected String getResourceColumnDefinition(T column) { - return column == null ? null : column.getColumnDefinition(); - } - - /** - * Return the default column name. - */ - protected String buildDefaultName() { - return this.getOwner().getDefaultColumnName(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateName(messages); - } - - protected void validateName(List<IMessage> messages) { - Table dbTable = this.getDbTable(); - if (dbTable != null && ! this.isResolved()) { - messages.add(this.getOwner().buildUnresolvedNameMessage(this, this.getNameTextRange())); - } - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java deleted file mode 100644 index e10221dabb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyMapping.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - - -public abstract class AbstractOrmOneToManyMapping<T extends XmlOneToMany> - extends AbstractOrmMultiRelationshipMapping<T> - implements OrmOneToManyMapping2_0, OrmOrphanRemovalHolder2_0 -{ - protected final OrmOrphanRemovable2_0 orphanRemoval; - - // ********** constructor ********** - protected AbstractOrmOneToManyMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.orphanRemoval = ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmOrphanRemoval(this, resourceMapping); - } - - // ********** update ********** - - @Override - public void update() { - super.update(); - this.getOrphanRemoval().update(); - } - - public int getXmlSequence() { - return 50; - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToManyMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToManys().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToManys().remove(this.resourceAttributeMapping); - } - - @Override - public OrmOneToManyRelationshipReference2_0 getRelationshipReference() { - return (OrmOneToManyRelationshipReference2_0) super.getRelationshipReference(); - } - - // ********** OrmOrphanRemovalHolder2_0 implementation ********** - - public OrmOrphanRemovable2_0 getOrphanRemoval() { - return this.orphanRemoval; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java deleted file mode 100644 index 9037e773e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToManyRelationshipReference.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyRelationshipReference2_0; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmOneToManyRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmOneToManyRelationshipReference2_0 -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - protected AbstractOrmOneToManyRelationshipReference( - OrmOneToManyMapping parent, XmlOneToMany resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - - // initialize join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericOrmJoinTableJoiningStrategy(this, getResourceMapping()); - } - - protected abstract OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy(); - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinTableEnabledRelationshipReference(this); - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - super.initializeFromOwnableRelationshipReference(oldRelationshipReference); - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - super.initializeFromJoinTableEnabledRelationshipReference(oldRelationshipReference); - OrmJoinTable oldTable = - oldRelationshipReference.getJoinTableJoiningStrategy().getJoinTable(); - if (oldTable != null) { - this.joinTableJoiningStrategy.addJoinTable().initializeFrom(oldTable); - } - } - - @Override - public OrmOneToManyMapping getRelationshipMapping() { - return (OrmOneToManyMapping) getParent(); - } - - public XmlOneToMany getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - public boolean isTargetForeignKeyRelationship() { - return getJoinColumnJoiningStrategy().isTargetForeignKeyRelationship(); - } - - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public final void setMappedByJoiningStrategy() { - setMappedByJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void setMappedByJoiningStrategy_() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public final void unsetMappedByJoiningStrategy() { - unsetMappedByJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void unsetMappedByJoiningStrategy_() { - this.mappedByJoiningStrategy.removeStrategy(); - } - - public boolean usesMappedByJoiningStrategy() { - return this.getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table ********************************************* - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public final void setJoinTableJoiningStrategy() { - setJoinTableJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void setJoinTableJoiningStrategy_() { - // join table is default, so no need to add to resource - this.mappedByJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - } - - public final void unsetJoinTableJoiningStrategy() { - unsetJoinTableJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void unsetJoinTableJoiningStrategy_() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null - && ! this.joinColumnJoiningStrategy.hasSpecifiedJoinColumns(); - } - - - // **************** join columns ******************************************* - - public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.addStrategy(); - this.mappedByJoiningStrategy.removeStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return false; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.joinColumnJoiningStrategy.update(); - - // update join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java deleted file mode 100644 index 277405cd38..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneMapping.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneRelationshipReference2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; - - -public abstract class AbstractOrmOneToOneMapping<T extends XmlOneToOne> - extends AbstractOrmSingleRelationshipMapping<T> - implements OrmOneToOneMapping2_0, OrmOrphanRemovalHolder2_0 -{ - protected final OrmOrphanRemovable2_0 orphanRemoval; - - // ********** constructor ********** - protected AbstractOrmOneToOneMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.orphanRemoval = ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()).buildOrmOrphanRemoval(this, resourceMapping); - } - - // ********** update ********** - - @Override - public void update() { - super.update(); - this.getOrphanRemoval().update(); - } - - public int getXmlSequence() { - return 60; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToOneMapping(this); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToOnes().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getOneToOnes().remove(this.resourceAttributeMapping); - } - - @Override - public OrmOneToOneRelationshipReference2_0 getRelationshipReference() { - return (OrmOneToOneRelationshipReference2_0) super.getRelationshipReference(); - } - - // ********** OrmOrphanRemovalHolder2_0 implementation ********** - - public OrmOrphanRemovable2_0 getOrphanRemoval() { - return this.orphanRemoval; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneRelationshipReference.java deleted file mode 100644 index 136371467a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmOneToOneRelationshipReference.java +++ /dev/null @@ -1,263 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToOneRelationshipReference2_0; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public abstract class AbstractOrmOneToOneRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmOneToOneRelationshipReference2_0 -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinColumnJoiningStrategy joinColumnJoiningStrategy; - - protected OrmPrimaryKeyJoinColumnJoiningStrategy primaryKeyJoinColumnJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - - protected AbstractOrmOneToOneRelationshipReference( - OrmOneToOneMapping parent, XmlOneToOne resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - this.primaryKeyJoinColumnJoiningStrategy = buildPrimaryKeyJoinColumnJoiningStrategy(); - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - - // initialize join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy = buildJoinColumnJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinColumnJoiningStrategy buildJoinColumnJoiningStrategy() { - return new GenericOrmJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - protected OrmPrimaryKeyJoinColumnJoiningStrategy buildPrimaryKeyJoinColumnJoiningStrategy() { - return new GenericOrmPrimaryKeyJoinColumnJoiningStrategy(this, getResourceMapping()); - } - - protected abstract OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy(); - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinColumnEnabledRelationshipReference(this); - // no other primary key reference as of yet, so no initialization based on pk join columns - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - int index = 0; - for (JoinColumn joinColumn : - CollectionTools.iterable( - oldRelationshipReference.getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - @Override - public OrmOneToOneMapping getRelationshipMapping() { - return (OrmOneToOneMapping) getParent(); - } - - public XmlOneToOne getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join columns ******************************************* - - public OrmJoinColumnJoiningStrategy getJoinColumnJoiningStrategy() { - return this.joinColumnJoiningStrategy; - } - - public boolean usesJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinColumnJoiningStrategy; - } - - public void setJoinColumnJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - // join columns are default, so no need to add annotations - setPredominantJoiningStrategy(); - } - - public void unsetJoinColumnJoiningStrategy() { - this.joinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayHaveDefaultJoinColumn() { - return this.getMappedByJoiningStrategy().getMappedByAttribute() == null - && this.getPrimaryKeyJoinColumnJoiningStrategy().primaryKeyJoinColumnsSize() == 0 - && this.getJoinTableJoiningStrategy().getJoinTable() == null; - } - - - // **************** primary key join columns ******************************* - - public OrmPrimaryKeyJoinColumnJoiningStrategy getPrimaryKeyJoinColumnJoiningStrategy() { - return this.primaryKeyJoinColumnJoiningStrategy; - } - - public boolean usesPrimaryKeyJoinColumnJoiningStrategy() { - return getPredominantJoiningStrategy() == this.primaryKeyJoinColumnJoiningStrategy; - } - - public void setPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.addStrategy(); - this.mappedByJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public void unsetPrimaryKeyJoinColumnJoiningStrategy() { - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayHaveDefaultPrimaryKeyJoinColumn() { - return false; - } - - - // **************** join table ********************************************* - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public final void setJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.addStrategy(); - this.mappedByJoiningStrategy.removeStrategy(); - this.joinColumnJoiningStrategy.removeStrategy(); - this.primaryKeyJoinColumnJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public final void unsetJoinTableJoiningStrategy() { - unsetJoinTableJoiningStrategy_(); - setPredominantJoiningStrategy(); - } - - protected void unsetJoinTableJoiningStrategy_() { - this.joinTableJoiningStrategy.removeStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return false; - } - - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - this.primaryKeyJoinColumnJoiningStrategy.update(); - this.joinTableJoiningStrategy.update(); - // update join columns last, as the existence of a default join - // column is dependent on the other mechanisms (mappedBy, join table) - // not being specified - this.joinColumnJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.primaryKeyJoinColumnJoiningStrategy.validate(messages, reporter); - this.joinColumnJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java deleted file mode 100644 index fb0eab8ee7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java +++ /dev/null @@ -1,316 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.CollectionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.MetamodelField; -import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmPersistentAttribute2_0; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -/** - * ORM persistent attribute - */ -public abstract class AbstractOrmPersistentAttribute - extends AbstractOrmXmlContextNode - implements OrmPersistentAttribute2_0 -{ - protected final Owner owner; - - protected OrmAttributeMapping attributeMapping; - - protected JavaPersistentAttribute javaPersistentAttribute; - - protected AccessType defaultAccess; - - protected AbstractOrmPersistentAttribute(OrmPersistentType parent, Owner owner, XmlAttributeMapping resourceMapping) { - super(parent); - this.owner = owner; - this.attributeMapping = buildAttributeMapping(resourceMapping); - this.javaPersistentAttribute = findJavaPersistentAttribute(); - this.defaultAccess = buildDefaultAccess(); - } - - public XmlAttributeMapping getResourceAttributeMapping() { - return this.attributeMapping.getResourceAttributeMapping(); - } - - public JavaPersistentAttribute getJavaPersistentAttribute() { - return this.javaPersistentAttribute; - } - - protected void setJavaPersistentAttribute(JavaPersistentAttribute javaPersistentAttribute) { - JavaPersistentAttribute old = this.javaPersistentAttribute; - this.javaPersistentAttribute = javaPersistentAttribute; - this.firePropertyChanged(JAVA_PERSISTENT_ATTRIBUTE_PROPERTY, old, javaPersistentAttribute); - } - - protected OrmAttributeMapping buildAttributeMapping(XmlAttributeMapping resourceMapping) { - OrmAttributeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmAttributeMappingDefinition(resourceMapping.getMappingKey()); - return mappingDefinition.buildContextMapping(this, resourceMapping, getXmlContextNodeFactory()); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public AccessType getAccess() { - return getSpecifiedAccess() != null ? getSpecifiedAccess() : getDefaultAccess(); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newAccess) { - AccessType old = this.defaultAccess; - this.defaultAccess = newAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, old, this.defaultAccess); - } - - public String getName() { - return this.attributeMapping.getName(); - } - - public void nameChanged(String oldName, String newName) { - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public OrmAttributeMapping getSpecifiedMapping() { - return this.attributeMapping; - } - - public OrmAttributeMapping getMapping() { - return this.attributeMapping; - } - - public String getMappingKey() { - return this.attributeMapping.getKey(); - } - - public String getDefaultMappingKey() { - return null; - } - - public void setSpecifiedMappingKey(String newMappingKey) { - if (this.valuesAreEqual(this.getMappingKey(), newMappingKey)) { - return; - } - OrmAttributeMapping oldMapping = this.attributeMapping; - OrmAttributeMappingDefinition mappingDefinition = - getMappingFileDefinition().getOrmAttributeMappingDefinition(newMappingKey); - XmlAttributeMapping resourceAttributeMapping = - mappingDefinition.buildResourceMapping(getResourceNodeFactory()); - this.attributeMapping = buildAttributeMapping(resourceAttributeMapping); - - getOwningPersistentType().changeMapping(this, oldMapping, this.attributeMapping); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - public OrmPersistentType getOwningPersistentType() { - return (OrmPersistentType) getParent(); - } - - public OrmTypeMapping getOwningTypeMapping() { - return getOwningPersistentType().getMapping(); - } - - public boolean isVirtual() { - return getOwningPersistentType().containsVirtualAttribute(this); - } - - public void makeVirtual() { - if (isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); //$NON-NLS-1$ - } - getOwningPersistentType().makeAttributeVirtual(this); - } - - public void makeSpecified() { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); //$NON-NLS-1$ - } - if (getMappingKey() == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makeSpecified(String) instead and specify a mapping type"); //$NON-NLS-1$ - } - getOwningPersistentType().makeAttributeSpecified(this); - } - - public void makeSpecified(String mappingKey) { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); //$NON-NLS-1$ - } - getOwningPersistentType().makeAttributeSpecified(this, mappingKey); - } - - public String getPrimaryKeyColumnName() { - return this.attributeMapping.getPrimaryKeyColumnName(); - } - - public String getTypeName() { - JavaPersistentAttribute javaAttribute = getJavaPersistentAttribute(); - return (javaAttribute == null) ? null : javaAttribute.getTypeName(); - } - - public void update() { - this.attributeMapping.update(); - this.setJavaPersistentAttribute(findJavaPersistentAttribute()); - this.owner.updateJavaPersistentAttribute(); - this.setDefaultAccess(buildDefaultAccess()); - } - - @Override - public void postUpdate() { - super.postUpdate(); - getMapping().postUpdate(); - } - - protected JavaPersistentAttribute findJavaPersistentAttribute() { - return this.owner.findJavaPersistentAttribute(this); - } - - protected AccessType buildDefaultAccess() { - return getOwningPersistentType().getAccess(); - } - - - // ********** JpaStructureNode implementation ********** - - public JpaStructureNode getStructureNode(int offset) { - return this; - } - - public boolean contains(int textOffset) { - if (isVirtual()) { - return false; - } - return this.attributeMapping.contains(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.attributeMapping.getSelectionTextRange(); - } - - public void dispose() { - //nothing to dispose - } - - - // ********** misc overrides ********** - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** validation ********** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.validateAttribute(messages); - this.validateModifiers(messages); - this.attributeMapping.validate(messages, reporter); - } - - protected void validateAttribute(List<IMessage> messages) { - if (this.javaPersistentAttribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME, - new String[] {this.getName(), this.getOwningPersistentType().getMapping().getClass_()}, - this.attributeMapping, - this.attributeMapping.getNameTextRange() - ) - ); - } - } - - protected void validateModifiers(List<IMessage> messages) { - if (this.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - if (this.javaPersistentAttribute == null) { - return; - } - - if (this.javaPersistentAttribute.isField()) { - if (this.javaPersistentAttribute.isFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); - } - if (this.javaPersistentAttribute.isPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); - } - } else { - //TODO validation : need to have a validation message for final methods as well. - //From the JPA spec : No methods or persistent instance variables of the entity class may be final. - } - } - - protected IMessage buildAttributeMessage(String msgID) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - msgID, - new String[] {this.getName()}, - this, - getValidationTextRange() - ); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getOwningPersistentType().getMapping().getAttributesTextRange(); - } - return this.attributeMapping.getValidationTextRange(); - } - - - // ********** metamodel ********** - - public String getMetamodelContainerFieldTypeName() { - return this.getJpaContainer().getMetamodelContainerFieldTypeName(); - } - - public String getMetamodelContainerFieldMapKeyTypeName() { - return this.getJpaContainer().getMetamodelContainerFieldMapKeyTypeName((CollectionMapping) this.getMapping()); - } - - public String getMetamodelTypeName() { - JavaPersistentAttribute2_0 javaAttribute = (JavaPersistentAttribute2_0) this.getJavaPersistentAttribute(); - return (javaAttribute == null) ? MetamodelField.DEFAULT_TYPE_NAME : javaAttribute.getMetamodelTypeName(); - } - - protected JavaPersistentAttribute.JpaContainer getJpaContainer() { - JavaPersistentAttribute2_0 javaAttribute = (JavaPersistentAttribute2_0) getJavaPersistentAttribute(); - return javaAttribute == null ? JavaPersistentAttribute.JpaContainer.Null.instance() : javaAttribute.getJpaContainer(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java deleted file mode 100644 index fe9aedf3e6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlQuery; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - - -public abstract class AbstractOrmQuery<E extends XmlQuery> extends AbstractOrmXmlContextNode - implements OrmQuery -{ - - protected String name; - - protected String query; - - protected final List<OrmQueryHint> hints; - - protected E resourceQuery; - - protected AbstractOrmQuery(XmlContextNode parent, E resourceQuery) { - super(parent); - this.hints = new ArrayList<OrmQueryHint>(); - this.initialize(resourceQuery); - } - - protected E getResourceQuery() { - return this.resourceQuery; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.getResourceQuery().setName(newName); - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - public String getQuery() { - return this.query; - } - - public void setQuery(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - this.getResourceQuery().setQuery(newQuery); - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<OrmQueryHint> hints() { - return new CloneListIterator<OrmQueryHint>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public OrmQueryHint addHint(int index) { - XmlQueryHint resourceQueryHint = OrmFactory.eINSTANCE.createXmlQueryHint(); - OrmQueryHint contextQueryHint = buildQueryHint(resourceQueryHint); - this.hints.add(index, contextQueryHint); - this.getResourceQuery().getHints().add(index, resourceQueryHint); - this.fireItemAdded(Query.HINTS_LIST, index, contextQueryHint); - return contextQueryHint; - } - - protected void addHint(int index, OrmQueryHint queryHint) { - addItemToList(index, queryHint, this.hints, Query.HINTS_LIST); - } - - protected void addHint(OrmQueryHint queryHint) { - this.addHint(this.hints.size(), queryHint); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - OrmQueryHint queryHint = this.hints.remove(index); - this.getResourceQuery().getHints().remove(index); - fireItemRemoved(Query.HINTS_LIST, index, queryHint); - } - - protected void removeHint_(OrmQueryHint queryHint) { - removeItemFromList(queryHint, this.hints, Query.HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - this.getResourceQuery().getHints().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.hints, Query.HINTS_LIST); - } - - - protected void initialize(E xmlQuery) { - this.resourceQuery = xmlQuery; - this.name = xmlQuery.getName(); - this.query = xmlQuery.getQuery(); - this.initializeHints(); - } - - protected void initializeHints() { - for (XmlQueryHint resourceQueryHint : this.resourceQuery.getHints()) { - this.hints.add(buildQueryHint(resourceQueryHint)); - } - } - - protected OrmQueryHint buildQueryHint(XmlQueryHint resourceQueryHint) { - return getXmlContextNodeFactory().buildOrmQueryHint(this, resourceQueryHint); - } - - public void update(E xmlQuery) { - this.resourceQuery = xmlQuery; - this.setName(xmlQuery.getName()); - this.setQuery(xmlQuery.getQuery()); - this.updateHints(); - getPersistenceUnit().addQuery(this); - } - - protected void updateHints() { - // make a copy of the XML hints (to prevent ConcurrentModificationException) - Iterator<XmlQueryHint> xmlHints = new CloneIterator<XmlQueryHint>(this.resourceQuery.getHints()); - - for (Iterator<OrmQueryHint> contextHints = this.hints(); contextHints.hasNext(); ) { - OrmQueryHint contextHint = contextHints.next(); - if (xmlHints.hasNext()) { - contextHint.update(xmlHints.next()); - } - else { - removeHint_(contextHint); - } - } - - while (xmlHints.hasNext()) { - addHint(buildQueryHint(xmlHints.next())); - } - } - - public boolean overrides(Query other) { - // this isn't ideal, but it will have to do until we have further adopter input - return (this.name != null) - && this.name.equals(other.getName()) - && (other instanceof JavaQuery); - } - - public boolean duplicates(Query other) { - return (this != other) - && ! StringTools.stringIsEmpty(this.name) - && this.name.equals(other.getName()) - && ! this.overrides(other) - && ! other.overrides(this); - } - - public TextRange getValidationTextRange() { - return this.getResourceQuery().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.getResourceQuery().getNameTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java deleted file mode 100644 index 975ffef534..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ /dev/null @@ -1,356 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmCascade; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.jpa2.context.MetamodelField; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCascade2_0; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmRelationshipMapping<T extends AbstractXmlRelationshipMapping> - extends AbstractOrmAttributeMapping<T> - implements OrmRelationshipMapping -{ - protected String specifiedTargetEntity; - protected String defaultTargetEntity; - protected PersistentType resolvedTargetType; - protected Entity resolvedTargetEntity; - - protected final OrmRelationshipReference relationshipReference; - - protected final OrmCascade2_0 cascade; - - protected FetchType specifiedFetch; - - - protected AbstractOrmRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.relationshipReference = buildRelationshipReference(); - this.cascade = buildCascade(); - this.specifiedTargetEntity = getResourceTargetEntity(); - this.defaultTargetEntity = buildDefaultTargetEntity(); - this.resolvedTargetType = this.resolveTargetType(); - this.resolvedTargetEntity = this.resolveTargetEntity(); - this.specifiedFetch = getResourceFetch(); - } - - @Override - public void update() { - super.update(); - this.relationshipReference.update(); - this.cascade.update(); - this.setSpecifiedTargetEntity_(this.getResourceTargetEntity()); - this.setDefaultTargetEntity(this.buildDefaultTargetEntity()); - this.resolvedTargetType = this.resolveTargetType(); - this.setResolvedTargetEntity(this.resolveTargetEntity()); - this.setSpecifiedFetch_(this.getResourceFetch()); - } - - protected abstract OrmRelationshipReference buildRelationshipReference(); - - @Override - public OrmPersistentAttribute getParent() { - return (OrmPersistentAttribute) super.getParent(); - } - - @Override - public boolean isRelationshipOwner() { - return this.relationshipReference.isRelationshipOwner(); - } - - @Override - public boolean isOwnedBy(AttributeMapping mapping) { - if (mapping.isRelationshipOwner()) { - return this.relationshipReference.isOwnedBy((RelationshipMapping) mapping); - } - return false; - } - - public RelationshipMapping getRelationshipOwner() { - Entity targetEntity = this.getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - for (PersistentAttribute each : - CollectionTools.iterable( - targetEntity.getPersistentType().allAttributes())) { - if (this.isOwnedBy(each.getMapping())) { - return (RelationshipMapping) each.getMapping(); - } - } - return null; - } - - @Override - public boolean isOverridableAssociationMapping() { - return this.relationshipReference.isOverridableAssociation(); - } - - - // **************** target entity ****************************************** - - public char getTargetEntityEnclosingTypeSeparator() { - return '$'; - } - - public String getTargetEntity() { - return (this.specifiedTargetEntity != null) ? this.specifiedTargetEntity : this.defaultTargetEntity; - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.resourceAttributeMapping.setTargetEntity(targetEntity); - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - protected void setSpecifiedTargetEntity_(String targetEntity) { - String old = this.specifiedTargetEntity; - this.specifiedTargetEntity = targetEntity; - this.firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String targetEntity) { - String old = this.defaultTargetEntity; - this.defaultTargetEntity = targetEntity; - this.firePropertyChanged(DEFAULT_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity targetEntity) { - Entity old = this.resolvedTargetEntity; - this.resolvedTargetEntity = targetEntity; - this.firePropertyChanged(RESOLVED_TARGET_ENTITY_PROPERTY, old, targetEntity); - } - - public PersistentType getResolvedTargetType() { - return this.resolvedTargetType; - } - - protected PersistentType resolveTargetType() { - return this.resolvePersistentType(this.getTargetEntity()); - } - - protected String getResourceTargetEntity() { - return this.resourceAttributeMapping.getTargetEntity(); - } - - protected String buildDefaultTargetEntity() { - if (this.getJavaPersistentAttribute() != null) { - return getResourceDefaultTargetEntity(); - } - return null; - } - - protected abstract String getResourceDefaultTargetEntity(); - - protected Entity resolveTargetEntity() { - if (this.resolvedTargetType == null) { - return null; - } - TypeMapping typeMapping = this.resolvedTargetType.getMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - - // **************** reference ********************************************** - - public OrmRelationshipReference getRelationshipReference() { - return this.relationshipReference; - } - - - // **************** cascade ************************************************ - - protected OrmCascade2_0 buildCascade() { - return new GenericOrmCascade(this, this.resourceAttributeMapping); - } - - public OrmCascade2_0 getCascade() { - return this.cascade; - } - - - // **************** fetch ************************************************** - - public FetchType getFetch() { - return (this.specifiedFetch != null) ? this.specifiedFetch : this.getDefaultFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.resourceAttributeMapping.setFetch(FetchType.toOrmResourceModel(fetch)); - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - - protected void setSpecifiedFetch_(FetchType fetch) { - FetchType old = this.specifiedFetch; - this.specifiedFetch = fetch; - this.firePropertyChanged(SPECIFIED_FETCH_PROPERTY, old, fetch); - } - protected FetchType getResourceFetch() { - return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); - } - - - // ********** RelationshipMapping implementation ********** - - @Override - public void initializeFromOrmRelationshipMapping(OrmRelationshipMapping oldMapping) { - super.initializeFromOrmRelationshipMapping(oldMapping); - setSpecifiedTargetEntity(oldMapping.getSpecifiedTargetEntity()); - setSpecifiedFetch(oldMapping.getSpecifiedFetch()); - oldMapping.getRelationshipReference().initializeOn(this.relationshipReference); - this.cascade.initializeFrom(oldMapping.getCascade()); - //TODO should we set the fetch type from a BasicMapping?? - } - - public Iterator<String> allTargetEntityAttributeNames() { - return new CompositeIterator<String>( - new TransformationIterator<AttributeMapping, Iterator<String>>(this.allTargetEntityAttributeMappings()) { - @Override - protected Iterator<String> transform(AttributeMapping mapping) { - return mapping.allMappingNames(); - } - }); - } - - public Iterator<AttributeMapping> allTargetEntityAttributeMappings() { - return (this.resolvedTargetEntity != null) ? - this.resolvedTargetEntity.allAttributeMappings() : - EmptyIterator.<AttributeMapping> instance(); - } - - protected String getTargetEntityIdAttributeName() { - PersistentAttribute attribute = this.getTargetEntityIdAttribute(); - return (attribute == null) ? null : attribute.getName(); - } - - protected PersistentAttribute getTargetEntityIdAttribute() { - return (this.resolvedTargetEntity == null) ? null : this.resolvedTargetEntity.getIdAttribute(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - validateTargetEntity(messages); - this.relationshipReference.validate(messages, reporter); - } - - protected void validateTargetEntity(List<IMessage> messages) { - if (getTargetEntity() == null) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_NOT_DEFINED, - new String[] {this.getName()}, - this, - this.getValidationTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_NOT_DEFINED, - new String[] {this.getName()}, - this, - this.getValidationTextRange() - ) - ); - } - } - else if (getResolvedTargetEntity() == null) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY, - new String[] {this.getName(), getTargetEntity()}, - this, - this.getValidationTextRange() - ) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY, - new String[] {getTargetEntity(), this.getName()}, - this, - this.getTargetEntityTextRange() - ) - ); - } - } - } - - protected TextRange getTextRange(TextRange textRange) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(); - } - - protected TextRange getTargetEntityTextRange() { - return this.getTextRange(this.getResourceAttributeMapping().getTargetEntityTextRange()); - } - - - // ********** metamodel ********** - - @Override - public String getMetamodelTypeName() { - if (this.resolvedTargetType == null) { - return MetamodelField.DEFAULT_TYPE_NAME; - } - String targetTypeName = this.resolvedTargetType.getName(); - return (targetTypeName != null) ? targetTypeName : MetamodelField.DEFAULT_TYPE_NAME; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java deleted file mode 100644 index 5f522255ae..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipReference.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public abstract class AbstractOrmRelationshipReference - extends AbstractOrmXmlContextNode - implements OrmRelationshipReference -{ - protected AbstractXmlRelationshipMapping resourceMapping; - - // cache the strategy for property change notification - protected OrmJoiningStrategy cachedPredominantJoiningStrategy; - - - protected AbstractOrmRelationshipReference( - OrmRelationshipMapping parent, AbstractXmlRelationshipMapping resourceMapping) { - - super(parent); - this.resourceMapping = resourceMapping; - this.initialize(); - } - - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - // no op - } - - public void initializeFromJoinColumnEnabledRelationshipReference( - OrmJoinColumnEnabledRelationshipReference oldRelationshipReference) { - // no op - } - - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - // no op - } - - public OrmRelationshipMapping getRelationshipMapping() { - return (OrmRelationshipMapping) getParent(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public Entity getEntity() { - TypeMapping typeMapping = getTypeMapping(); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public boolean isOverridableAssociation() { - return getPredominantJoiningStrategy().isOverridableAssociation(); - } - - public boolean isParentVirtual() { - return getRelationshipMapping().getPersistentAttribute().isVirtual(); - } - - public boolean isTargetForeignKeyRelationship() { - return false; - } - - - // **************** predominant joining strategy *************************** - - public OrmJoiningStrategy getPredominantJoiningStrategy() { - return this.cachedPredominantJoiningStrategy; - } - - protected void setPredominantJoiningStrategy() { - setPredominantJoiningStrategy(calculatePredominantJoiningStrategy()); - } - - protected void setPredominantJoiningStrategy(OrmJoiningStrategy newJoiningStrategy) { - JoiningStrategy oldJoiningStrategy = this.cachedPredominantJoiningStrategy; - this.cachedPredominantJoiningStrategy = newJoiningStrategy; - firePropertyChanged(PREDOMINANT_JOINING_STRATEGY_PROPERTY, oldJoiningStrategy, newJoiningStrategy); - } - - - // **************** resource -> context ************************************ - - protected void initialize() { - initializeJoiningStrategies(); - this.cachedPredominantJoiningStrategy = calculatePredominantJoiningStrategy(); - } - - protected abstract void initializeJoiningStrategies(); - - - public void update() { - updateJoiningStrategies(); - setPredominantJoiningStrategy(); - } - - protected abstract void updateJoiningStrategies(); - - protected abstract OrmJoiningStrategy calculatePredominantJoiningStrategy(); - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange() { - return getRelationshipMapping().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java deleted file mode 100644 index 4f3f6df0be..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSequenceGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; - -/** - * - */ -public abstract class AbstractOrmSequenceGenerator - extends AbstractOrmGenerator<XmlSequenceGenerator> - implements OrmSequenceGenerator -{ - - protected String specifiedSequenceName; - protected String defaultSequenceName; - - - protected AbstractOrmSequenceGenerator(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - super(parent); - this.initialize(resourceSequenceGenerator); - } - - - @Override - public int getDefaultInitialValue() { - return SequenceGenerator.DEFAULT_INITIAL_VALUE; - } - - // ********** sequence name ********** - - public String getSequenceName() { - return (this.specifiedSequenceName != null) ? this.specifiedSequenceName : this.defaultSequenceName; - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.getResourceGenerator().setSequenceName(specifiedSequenceName); - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String specifiedSequenceName) { - String old = this.specifiedSequenceName; - this.specifiedSequenceName = specifiedSequenceName; - this.firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, old, specifiedSequenceName); - } - - public String getDefaultSequenceName() { - return this.defaultSequenceName; - } - - protected void setDefaultSequenceName(String defaultSequenceName) { - String old = this.defaultSequenceName; - this.defaultSequenceName = defaultSequenceName; - this.firePropertyChanged(DEFAULT_SEQUENCE_NAME_PROPERTY, old, defaultSequenceName); - } - - - // ********** resource => context ********** - - @Override - protected void initialize(XmlSequenceGenerator sequenceGenerator) { - super.initialize(sequenceGenerator); - this.specifiedSequenceName = sequenceGenerator.getSequenceName(); - //TODO default sequence name - } - - @Override - public void update(XmlSequenceGenerator sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(sequenceGenerator.getSequenceName()); - //TODO default sequence name - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java deleted file mode 100644 index a4244858e4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.AbstractXmlSingleRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlSingleRelationshipMapping_2_0; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmSingleRelationshipMapping<T extends AbstractXmlSingleRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmSingleRelationshipMapping2_0 -{ - protected Boolean specifiedOptional; - - protected final OrmDerivedIdentity2_0 derivedIdentity; - - - protected AbstractOrmSingleRelationshipMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.specifiedOptional = this.getResourceOptional(); - //TODO defaultOptional - this.derivedIdentity = buildDerivedIdentity(); - } - - - @Override - public void initializeFromOrmSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - super.initializeFromOrmSingleRelationshipMapping(oldMapping); - getDerivedIdentity().initializeFrom(((OrmSingleRelationshipMapping2_0) oldMapping).getDerivedIdentity()); - } - - @Override - protected String getResourceDefaultTargetEntity() { - return this.getJavaPersistentAttribute().getSingleReferenceTargetTypeName(); - } - - public FetchType getDefaultFetch() { - return DEFAULT_FETCH_TYPE; - } - - - // **************** optional *********************************************** - - public boolean isOptional() { - return (this.specifiedOptional != null) ? this.specifiedOptional.booleanValue() : this.isDefaultOptional(); - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.resourceAttributeMapping.setOptional(optional); - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - protected void setSpecifiedOptional_(Boolean optional) { - Boolean old = this.specifiedOptional; - this.specifiedOptional = optional; - this.firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, old, optional); - } - - public boolean isDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - - // ********** 2.0 derived identity ********** - - protected OrmDerivedIdentity2_0 buildDerivedIdentity() { - return ((OrmXml2_0ContextNodeFactory) getXmlContextNodeFactory()). - buildOrmDerivedIdentity(this, (XmlSingleRelationshipMapping_2_0) this.resourceAttributeMapping); - } - - public OrmDerivedIdentity2_0 getDerivedIdentity() { - return this.derivedIdentity; - } - - - // **************** resource => context ************************************ - - @Override - public void update() { - super.update(); - this.setSpecifiedOptional_(this.getResourceOptional()); - this.derivedIdentity.update(); - } - - protected Boolean getResourceOptional() { - return this.resourceAttributeMapping.getOptional(); - } - - - // **************** validation ************************************ - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.derivedIdentity.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java deleted file mode 100644 index 41d1ff0535..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java +++ /dev/null @@ -1,475 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.SchemaContainer; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * - */ -public abstract class AbstractOrmTable - extends AbstractOrmXmlContextNode - implements Table, UniqueConstraint.Owner -{ - protected String specifiedName; - protected String defaultName; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - // ********** constructor ********** - - protected AbstractOrmTable(XmlContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - - // ********** abstract methods ********** - - /** - * Return null if no resource table exists. - */ - protected abstract AbstractXmlTable getResourceTable(); - - /** - * Return the added resource table. - */ - protected abstract AbstractXmlTable addResourceTable(); - - protected abstract void removeResourceTable(); - - protected abstract String buildDefaultName(); - - protected abstract String buildDefaultSchema(); - - protected abstract String buildDefaultCatalog(); - - - public boolean isResourceSpecified() { - return this.getResourceTable() != null; - } - - // ********** name ********** - - public String getName() { - return (this.specifiedName != null) ? this.specifiedName : this.defaultName; - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String name) { - String old = this.specifiedName; - this.specifiedName = name; - if (this.attributeValueHasChanged(old, name)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setName(name); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - } - - protected void setSpecifiedName_(String name) { - String old = this.specifiedName; - this.specifiedName = name; - this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String name) { - String old = this.defaultName; - this.defaultName = name; - this.firePropertyChanged(DEFAULT_NAME_PROPERTY, old, name); - } - - - // ********** schema ********** - - public String getSchema() { - return (this.specifiedSchema != null) ? this.specifiedSchema : this.defaultSchema; - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - if (this.attributeValueHasChanged(old, schema)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setSchema(schema); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - } - - protected void setSpecifiedSchema_(String schema) { - String old = this.specifiedSchema; - this.specifiedSchema = schema; - this.firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, old, schema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String schema) { - String old = this.defaultSchema; - this.defaultSchema = schema; - this.firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, old, schema); - } - - - // ********** catalog ********** - - public String getCatalog() { - return (this.specifiedCatalog != null) ? this.specifiedCatalog : this.defaultCatalog; - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String catalog) { - String old = this.specifiedCatalog; - this.specifiedCatalog = catalog; - if (this.attributeValueHasChanged(old, catalog)) { - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.setCatalog(catalog); - if (resourceTable.isUnset()) { - this.removeResourceTable(); - } - this.firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, old, catalog); - } - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - - // ********** unique constraints ********** - - public @SuppressWarnings("unchecked") ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint resourceConstraint = OrmFactory.eINSTANCE.createXmlUniqueConstraint(); - OrmUniqueConstraint contextConstraint = this.buildUniqueConstraint(resourceConstraint); - this.uniqueConstraints.add(index, contextConstraint); - - AbstractXmlTable resourceTable = this.getResourceTable(); - if (resourceTable == null) { - resourceTable = this.addResourceTable(); - } - resourceTable.getUniqueConstraints().add(index, resourceConstraint); - - this.fireItemAdded(UNIQUE_CONSTRAINTS_LIST, index, contextConstraint); - return contextConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - this.addItemToList(index, uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - protected void addUniqueConstraint(OrmUniqueConstraint uniqueConstraint) { - this.addUniqueConstraint(this.uniqueConstraints.size(), uniqueConstraint); - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getResourceTable().getUniqueConstraints().remove(index); - this.fireItemRemoved(UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - this.removeItemFromList(uniqueConstraint, this.uniqueConstraints, UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getResourceTable().getUniqueConstraints().move(targetIndex, sourceIndex); - this.fireItemMoved(UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - - // ********** convenience methods ********** - - protected TextRange getTextRange(TextRange textRange) { - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(); - } - - protected TextRange getNameTextRange() { - return this.getTextRange(this.getResourceTableNameTextRange()); - } - - protected TextRange getResourceTableNameTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getNameTextRange(); - } - - protected TextRange getSchemaTextRange() { - return this.getTextRange(this.getResourceTableSchemaTextRange()); - } - - protected TextRange getResourceTableSchemaTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getSchemaTextRange(); - } - - protected TextRange getCatalogTextRange() { - return this.getTextRange(this.getResourceTableCatalogTextRange()); - } - - protected TextRange getResourceTableCatalogTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getCatalogTextRange(); - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint resourceUniqueConstraint) { - return this.getXmlContextNodeFactory().buildOrmUniqueConstraint(this, this, resourceUniqueConstraint); - } - - - // ********** resource => context ********** - - protected void initialize(AbstractXmlTable xmlTable) { - this.defaultName = this.buildDefaultName(); - this.specifiedName = this.getResourceTableName(xmlTable); - - this.defaultSchema = this.buildDefaultSchema(); - this.specifiedSchema = this.getResourceTableSchema(xmlTable); - - this.defaultCatalog = this.buildDefaultCatalog(); - this.specifiedCatalog = this.getResourceTableCatalog(xmlTable); - - this.initializeUniqueContraints(xmlTable); - } - - protected void initializeUniqueContraints(AbstractXmlTable xmlTable) { - if (xmlTable == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : xmlTable.getUniqueConstraints()) { - this.uniqueConstraints.add(this.buildUniqueConstraint(uniqueConstraint)); - } - } - - protected void update(AbstractXmlTable xmlTable) { - this.setDefaultName(this.buildDefaultName()); - this.setSpecifiedName_(this.getResourceTableName(xmlTable)); - - this.setDefaultSchema(this.buildDefaultSchema()); - this.setSpecifiedSchema_(this.getResourceTableSchema(xmlTable)); - - this.setDefaultCatalog(this.buildDefaultCatalog()); - this.setSpecifiedCatalog_(this.getResourceTableCatalog(xmlTable)); - - this.updateUniqueConstraints(xmlTable); - } - - protected String getResourceTableName(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getName(); - } - - protected String getResourceTableSchema(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getSchema(); - } - - protected String getResourceTableCatalog(AbstractXmlTable xmlTable) { - return (xmlTable == null) ? null : xmlTable.getCatalog(); - } - - protected void updateUniqueConstraints(AbstractXmlTable xmlTable) { - Iterator<XmlUniqueConstraint> xmlConstraints = this.xmlUniqueConstraints(xmlTable); - - for (Iterator<OrmUniqueConstraint> contextConstraints = this.uniqueConstraints(); contextConstraints.hasNext(); ) { - OrmUniqueConstraint contextConstraint = contextConstraints.next(); - if (xmlConstraints.hasNext()) { - contextConstraint.update(xmlConstraints.next()); - } else { - this.removeUniqueConstraint_(contextConstraint); - } - } - - while (xmlConstraints.hasNext()) { - this.addUniqueConstraint(this.buildUniqueConstraint(xmlConstraints.next())); - } - } - - protected Iterator<XmlUniqueConstraint> xmlUniqueConstraints(AbstractXmlTable xmlTable) { - // make a copy of the XML constraints (to prevent ConcurrentModificationException) - return (xmlTable == null) ? EmptyIterator.<XmlUniqueConstraint>instance() - : new CloneIterator<XmlUniqueConstraint>(xmlTable.getUniqueConstraints()); - } - - public void initializeFrom(Table oldTable) { - this.setSpecifiedName(oldTable.getSpecifiedName()); - this.setSpecifiedCatalog(oldTable.getSpecifiedCatalog()); - this.setSpecifiedSchema(oldTable.getSpecifiedSchema()); - } - - - // ********** database stuff ********** - - public org.eclipse.jpt.db.Table getDbTable() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema == null) ? null : dbSchema.getTableForIdentifier(this.getName()); - } - - public Schema getDbSchema() { - SchemaContainer dbSchemaContainer = this.getDbSchemaContainer(); - return (dbSchemaContainer == null) ? null : dbSchemaContainer.getSchemaForIdentifier(this.getSchema()); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> catalog), - * then the database probably does not support catalogs; and we need to - * get the schema directly from the database. - */ - public SchemaContainer getDbSchemaContainer() { - String catalog = this.getCatalog(); - return (catalog != null) ? this.getDbCatalog(catalog) : this.getDatabase(); - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public Catalog getDbCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) ? null : this.getDbCatalog(catalog); - } - - public boolean isResolved() { - return this.getDbTable() != null; - } - - public boolean hasResolvedSchema() { - return this.getDbSchema() != null; - } - - /** - * If we don't have a catalog (i.e. we don't even have a <em>default</em> - * catalog), then the database probably does not support catalogs. - */ - public boolean hasResolvedCatalog() { - String catalog = this.getCatalog(); - return (catalog == null) || (this.getDbCatalog(catalog) != null); - } - - - // ********** UniqueConstraint.Owner implementation ********** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.getSortedColumnIdentifiers().iterator() : EmptyIterator.<String>instance(); - } - - - // ********** validation ********** - - public TextRange getValidationTextRange() { - return this.getTextRange(this.getResourceTableValidationTextRange()); - } - - protected TextRange getResourceTableValidationTextRange() { - AbstractXmlTable resourceTable = this.getResourceTable(); - return (resourceTable == null) ? null : resourceTable.getValidationTextRange(); - } - - - // ********** misc ********** - - /** - * covariant override - */ - @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getQualifiedName()); - } - - protected String getQualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java deleted file mode 100644 index 9b3eed9c54..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipReference; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmTypeMapping<T extends XmlTypeMapping> - extends AbstractOrmXmlContextNode - implements OrmTypeMapping -{ - protected String class_; - - public boolean defaultMetadataComplete; - - protected Boolean specifiedMetadataComplete; - - protected final T resourceTypeMapping; - - - protected AbstractOrmTypeMapping(OrmPersistentType parent, T resourceMapping) { - super(parent); - this.resourceTypeMapping = resourceMapping; - this.class_ = this.getResourceClassName(); - this.specifiedMetadataComplete = this.getResourceMetadataComplete(); - this.defaultMetadataComplete = this.getPersistentType().isDefaultMetadataComplete(); - } - - // **************** Type Mapping implementation ***************************** - - @Override - public OrmPersistentType getParent() { - return (OrmPersistentType) super.getParent(); - } - - public OrmPersistentType getPersistentType() { - return this.getParent(); - } - - protected JavaPersistentType getJavaPersistentType() { - return this.getPersistentType().getJavaPersistentType(); - } - - public boolean isMapped() { - return true; - } - - /* default implementation */ - public JavaPersistentType getIdClass() { - return null; - } - - public String getPrimaryTableName() { - return null; - } - - public String getClass_() { - return this.class_; - } - - public void setClass(String newClass) { - String oldClass = this.class_; - this.class_ = newClass; - this.resourceTypeMapping.setClassName(newClass); - firePropertyChanged(CLASS_PROPERTY, oldClass, newClass); - getPersistentType().classChanged(oldClass, newClass); - } - - - public boolean isMetadataComplete() { - if (isDefaultMetadataComplete()) { - //entity-mappings/persistence-unit-metadata/xml-mapping-metadata-complete is specified, then it overrides - //anything set here - return true; - } - return (this.getSpecifiedMetadataComplete() == null) ? this.isDefaultMetadataComplete() : this.getSpecifiedMetadataComplete().booleanValue(); - } - - public boolean isDefaultMetadataComplete() { - return this.defaultMetadataComplete; - } - - protected void setDefaultMetadataComplete(boolean newDefaultMetadataComplete) { - boolean oldMetadataComplete = this.defaultMetadataComplete; - this.defaultMetadataComplete = newDefaultMetadataComplete; - firePropertyChanged(DEFAULT_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newDefaultMetadataComplete); - } - - public Boolean getSpecifiedMetadataComplete() { - return this.specifiedMetadataComplete; - } - - public void setSpecifiedMetadataComplete(Boolean newSpecifiedMetadataComplete) { - Boolean oldMetadataComplete = this.specifiedMetadataComplete; - this.specifiedMetadataComplete = newSpecifiedMetadataComplete; - this.resourceTypeMapping.setMetadataComplete(newSpecifiedMetadataComplete); - firePropertyChanged(SPECIFIED_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newSpecifiedMetadataComplete); - } - - /** - * ITypeMapping is changed and various ITypeMappings may have - * common settings. In this method initialize the new ITypeMapping (this) - * fromthe old ITypeMapping (oldMapping) - */ - public void initializeFrom(OrmTypeMapping oldMapping) { - this.setClass(oldMapping.getClass_()); - this.setSpecifiedMetadataComplete(oldMapping.getSpecifiedMetadataComplete()); - this.setDefaultMetadataComplete(oldMapping.isDefaultMetadataComplete()); - } - - public Table getPrimaryDbTable() { - return null; - } - - public Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public Iterator<OrmAttributeMapping> attributeMappings() { - return new TransformationIterator<OrmPersistentAttribute, OrmAttributeMapping>(getPersistentType().attributes()) { - @Override - protected OrmAttributeMapping transform(OrmPersistentAttribute attribute) { - return attribute.getMapping(); - } - }; - } - - public Iterable<OrmAttributeMapping> getAttributeMappings(final String mappingKey) { - return new FilteringIterable<OrmAttributeMapping>(CollectionTools.collection(attributeMappings())) { - @Override - protected boolean accept(OrmAttributeMapping o) { - return StringTools.stringsAreEqual(o.getKey(), mappingKey); - } - }; - } - - public Iterator<AttributeMapping> allAttributeMappings() { - return new CompositeIterator<AttributeMapping>( - new TransformationIterator<TypeMapping, Iterator<AttributeMapping>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<AttributeMapping> transform(TypeMapping typeMapping) { - return typeMapping.attributeMappings(); - } - }); - } - - public Iterable<AttributeMapping> getAllAttributeMappings(final String mappingKey) { - return new FilteringIterable<AttributeMapping>(CollectionTools.collection(allAttributeMappings())) { - @Override - protected boolean accept(AttributeMapping o) { - return StringTools.stringsAreEqual(o.getKey(), mappingKey); - } - }; - } - - public TypeMapping getSuperTypeMapping() { - return (getPersistentType().getSuperPersistentType() == null) ? - null - : getPersistentType().getSuperPersistentType().getMapping(); - } - - /** - * Return an iterator of TypeMappings, each which inherits from the one before, - * and terminates at the root entity (or at the point of cyclicity). - */ - public Iterator<TypeMapping> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - public Iterator<String> overridableAttributeNames() { - return new CompositeIterator<String>( - new TransformationIterator<AttributeMapping, Iterator<String>>(this.attributeMappings()) { - @Override - protected Iterator<String> transform(AttributeMapping mapping) { - return mapping.allOverrideableAttributeMappingNames(); - } - }); - } - - public Iterator<String> allOverridableAttributeNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAttributeNames(); - } - }); - } - - public Column resolveOverriddenColumn(String attributeName) { - for (AttributeMapping attributeMapping : CollectionTools.iterable(attributeMappings())) { - Column resolvedColumn = attributeMapping.resolveOverriddenColumn(attributeName); - if (resolvedColumn != null) { - return resolvedColumn; - } - } - if (!isMetadataComplete()) { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - return javaPersistentType.getMapping().resolveOverriddenColumn(attributeName); - } - } - return null; - } - - public Iterator<String> overridableAssociationNames() { - return new CompositeIterator<String>( - new TransformationIterator<AttributeMapping, Iterator<String>>(this.attributeMappings()) { - @Override - protected Iterator<String> transform(AttributeMapping mapping) { - return mapping.allOverrideableAssociationMappingNames(); - } - }); - } - - public Iterator<String> allOverridableAssociationNames() { - return new CompositeIterator<String>(new TransformationIterator<TypeMapping, Iterator<String>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<String> transform(TypeMapping mapping) { - return mapping.overridableAssociationNames(); - } - }); - } - - public RelationshipReference resolveRelationshipReference(String attributeName) { - for (AttributeMapping attributeMapping : CollectionTools.iterable(attributeMappings())) { - RelationshipReference resolvedRelationshipReference = attributeMapping.resolveRelationshipReference(attributeName); - if (resolvedRelationshipReference != null) { - return resolvedRelationshipReference; - } - } - if (!isMetadataComplete()) { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - return javaPersistentType.getMapping().resolveRelationshipReference(attributeName); - } - } - return null; - } - - public T getResourceTypeMapping() { - return this.resourceTypeMapping; - } - - public void update() { - this.setClass(this.getResourceClassName()); - this.setSpecifiedMetadataComplete(this.getResourceMetadataComplete()); - this.setDefaultMetadataComplete(this.getPersistentType().isDefaultMetadataComplete()); - } - - protected String getResourceClassName() { - return this.resourceTypeMapping.getClassName(); - } - - protected Boolean getResourceMetadataComplete() { - return this.resourceTypeMapping.getMetadataComplete(); - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int offset) { - if (this.resourceTypeMapping.containsOffset(offset)) { - return getPersistentType(); - } - return null; - } - - public TextRange getSelectionTextRange() { - return this.resourceTypeMapping.getSelectionTextRange(); - } - - public TextRange getClassTextRange() { - return this.resourceTypeMapping.getClassTextRange(); - } - - public TextRange getAttributesTextRange() { - return this.resourceTypeMapping.getAttributesTextRange(); - } - - public boolean containsOffset(int textOffset) { - return (this.resourceTypeMapping != null) - && this.resourceTypeMapping.containsOffset(textOffset); - } - - //************************* 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.stringIsEmpty(this.class_)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CLASS, - this, - this.getClassTextRange() - ) - ); - return; - } - } - - public boolean shouldValidateAgainstDatabase() { - return getPersistenceUnit().shouldValidateAgainstDatabase(); - } - - public TextRange getValidationTextRange() { - return this.resourceTypeMapping.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getPersistentType().getName()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java deleted file mode 100644 index 609fb02d07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmVersionMapping.java +++ /dev/null @@ -1,245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmColumnMapping; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public abstract class AbstractOrmVersionMapping<T extends XmlVersion> - extends AbstractOrmAttributeMapping<T> - implements OrmVersionMapping -{ - protected final OrmColumn column; - - protected OrmConverter converter; - - protected final OrmConverter nullConverter; - - protected AbstractOrmVersionMapping(OrmPersistentAttribute parent, T resourceMapping) { - super(parent, resourceMapping); - this.column = getXmlContextNodeFactory().buildOrmColumn(this, this); - this.column.initialize(this.getResourceColumn());//TODO pass in to constructor - this.nullConverter = this.getXmlContextNodeFactory().buildOrmNullConverter(this); - this.converter = this.buildConverter(this.getResourceConverterType()); - } - - public int getXmlSequence() { - return 30; - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmVersionMapping(this); - } - - @Override - public void initializeFromOrmColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromOrmColumnMapping(oldMapping); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public OrmColumn getColumn() { - return this.column; - } - - public OrmConverter getConverter() { - return this.converter; - } - - protected String getConverterType() { - return this.converter.getType(); - } - - public void setConverter(String converterType) { - if (this.valuesAreEqual(getConverterType(), converterType)) { - return; - } - OrmConverter oldConverter = this.converter; - OrmConverter newConverter = buildConverter(converterType); - this.converter = this.nullConverter; - if (oldConverter != null) { - oldConverter.removeFromResourceModel(); - } - this.converter = newConverter; - if (newConverter != null) { - newConverter.addToResourceModel(); - } - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - protected void setConverter(OrmConverter newConverter) { - OrmConverter oldConverter = this.converter; - this.converter = newConverter; - firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter); - } - - public void addToResourceModel(Attributes resourceAttributes) { - resourceAttributes.getVersions().add(this.resourceAttributeMapping); - } - - public void removeFromResourceModel(Attributes resourceAttributes) { - resourceAttributes.getVersions().remove(this.resourceAttributeMapping); - } - - //************** NamedColumn.Owner implementation *************** - - public String getDefaultColumnName() { - return getName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - //************** BaseColumn.Owner implementation *************** - - public String getDefaultTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); - } - - @Override - public void update() { - super.update(); - this.column.update(this.getResourceColumn()); - if (this.valuesAreEqual(getResourceConverterType(), getConverterType())) { - getConverter().update(); - } - else { - setConverter(buildConverter(getResourceConverterType())); - } - } - - protected OrmConverter buildConverter(String converterType) { - if (this.valuesAreEqual(converterType, Converter.NO_CONVERTER)) { - return this.nullConverter; - } - if (this.valuesAreEqual(converterType, Converter.TEMPORAL_CONVERTER)) { - return getXmlContextNodeFactory().buildOrmTemporalConverter(this, this.resourceAttributeMapping); - } - return null; - } - - protected String getResourceConverterType() { - if (this.resourceAttributeMapping.getTemporal() != null) { - return Converter.TEMPORAL_CONVERTER; - } - return Converter.NO_CONVERTER; - } - - //***************** XmlColumn.Owner implementation **************** - - public XmlColumn getResourceColumn() { - return this.resourceAttributeMapping.getColumn(); - } - - public void addResourceColumn() { - this.resourceAttributeMapping.setColumn(OrmFactory.eINSTANCE.createXmlColumn()); - } - - public void removeResourceColumn() { - this.resourceAttributeMapping.setColumn(null); - } - - // ****************** validation **************** - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - this.getColumn().validate(messages, reporter); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualUnresolvedNameMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - protected IMessage buildVirtualUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName(), column.getDbTable().getName()}, - column, - textRange - ); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - if (isVirtual()) { - return this.buildVirtualTableNotValidMessage(column, textRange); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_TABLE_NOT_VALID, - new String[] { - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } - - public IMessage buildVirtualTableNotValidMessage(BaseColumn column, TextRange textRange) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID, - new String[] { - getName(), - column.getTable(), - column.getName(), - JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY}, - column, - textRange - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java deleted file mode 100644 index a6441f79c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNode.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; - -/** - * Use this abstract class for context nodes that are part of an - * <code>orm.xml</code> file. - * This will not work for a pure {@link org.eclipse.jpt.core.context.MappingFile} - * implementation. - */ -public abstract class AbstractOrmXmlContextNode - extends AbstractXmlContextNode -{ - // ********** constructor ********** - - protected AbstractOrmXmlContextNode(JpaContextNode parent) { - super(parent); - } - - - // ********** convenience methods ********** - - protected OrmXmlDefinition getMappingFileDefinition() { - return (OrmXmlDefinition) this.getJpaPlatform().getResourceDefinition(this.getResourceType()); - } - - protected EFactory getResourceNodeFactory() { - return this.getMappingFileDefinition().getResourceNodeFactory(); - } - - protected OrmXml2_0ContextNodeFactory getXmlContextNodeFactory() { - return (OrmXml2_0ContextNodeFactory) this.getMappingFileDefinition().getContextNodeFactory(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNodeFactory.java deleted file mode 100644 index 5fdcfc1c11..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlContextNodeFactory.java +++ /dev/null @@ -1,449 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.Orderable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverrideContainer; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmConverter; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGeneratorContainer; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryContainer; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericEntityMappings; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverride; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAttributeOverride; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmAttributeOverrideContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmBasicMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmDiscriminatorColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddedIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEmbeddedMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEntity; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmEnumeratedConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmGeneratedValue; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmGeneratorContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmJoinTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmLobConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmManyToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmManyToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmMappedSuperclass; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNamedNativeQuery; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNamedQuery; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNullAttributeMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmNullConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOneToManyMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOneToOneMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmOrderable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPersistentAttribute; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPersistentType; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmQueryContainer; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmQueryHint; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmSecondaryTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmSequenceGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTable; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTableGenerator; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTemporalConverter; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmTransientMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmUniqueConstraint; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericOrmVersionMapping; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericPersistenceUnitDefaults; -import org.eclipse.jpt.core.internal.jpa1.context.orm.GenericPersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.jpa1.context.orm.UnsupportedOrmAttributeMapping; -import org.eclipse.jpt.core.internal.jpa2.context.orm.GenericOrmOrderColumn2_0; -import org.eclipse.jpt.core.internal.jpa2.context.orm.NullOrmCacheable2_0; -import org.eclipse.jpt.core.internal.jpa2.context.orm.NullOrmDerivedIdentity2_0; -import org.eclipse.jpt.core.internal.jpa2.context.orm.NullOrmOrphanRemoval2_0; -import org.eclipse.jpt.core.jpa2.context.java.JavaElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheableHolder2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmCollectionTable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmEmbeddedMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrderColumn2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrderable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0; -import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlCollectionTable; -import org.eclipse.jpt.core.resource.orm.XmlConvertibleMapping; -import org.eclipse.jpt.core.resource.orm.XmlElementCollection; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlGeneratorContainer; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlQueryContainer; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlCacheable_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlOrphanRemovable_2_0; -import org.eclipse.jpt.core.resource.orm.v2_0.XmlSingleRelationshipMapping_2_0; - -public abstract class AbstractOrmXmlContextNodeFactory - implements OrmXml2_0ContextNodeFactory -{ - public EntityMappings buildEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - return new GenericEntityMappings(parent, xmlEntityMappings); - } - - public PersistenceUnitMetadata buildPersistenceUnitMetadata(EntityMappings parent) { - return new GenericPersistenceUnitMetadata(parent); - } - - public OrmPersistenceUnitDefaults buildPersistenceUnitDefaults(PersistenceUnitMetadata parent) { - return new GenericPersistenceUnitDefaults(parent); - } - - public OrmPersistentType buildOrmPersistentType(EntityMappings parent, XmlTypeMapping resourceMapping) { - return new GenericOrmPersistentType(parent, resourceMapping); - } - - public OrmEntity buildOrmEntity(OrmPersistentType parent, XmlEntity resourceMapping) { - return new GenericOrmEntity(parent, resourceMapping); - } - - public OrmMappedSuperclass buildOrmMappedSuperclass(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { - return new GenericOrmMappedSuperclass(parent, resourceMapping); - } - - public OrmEmbeddable buildOrmEmbeddable(OrmPersistentType parent, XmlEmbeddable resourceMapping) { - return new GenericOrmEmbeddable(parent, resourceMapping); - } - - public OrmPersistentAttribute buildOrmPersistentAttribute(OrmPersistentType parent, OrmPersistentAttribute.Owner owner, XmlAttributeMapping resourceMapping) { - return new GenericOrmPersistentAttribute(parent, owner, resourceMapping); - } - - public OrmTable buildOrmTable(OrmEntity parent) { - return new GenericOrmTable(parent); - } - - public OrmSecondaryTable buildOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - return new GenericOrmSecondaryTable(parent, xmlSecondaryTable); - } - - public OrmPrimaryKeyJoinColumn buildOrmPrimaryKeyJoinColumn(XmlContextNode parent, OrmBaseJoinColumn.Owner owner, XmlPrimaryKeyJoinColumn resourcePkJoinColumn) { - return new GenericOrmPrimaryKeyJoinColumn(parent, owner, resourcePkJoinColumn); - } - - public OrmJoinTable buildOrmJoinTable(OrmJoinTableJoiningStrategy parent, XmlJoinTable resourceJoinTable) { - return new GenericOrmJoinTable(parent, resourceJoinTable); - } - - public OrmJoinColumn buildOrmJoinColumn(XmlContextNode parent, OrmJoinColumn.Owner owner, XmlJoinColumn resourceJoinColumn) { - return new GenericOrmJoinColumn(parent, owner, resourceJoinColumn); - } - - public OrmAttributeOverrideContainer buildOrmAttributeOverrideContainer(XmlContextNode parent, OrmAttributeOverrideContainer.Owner owner) { - return new GenericOrmAttributeOverrideContainer(parent, owner); - } - - public OrmAssociationOverrideContainer buildOrmAssociationOverrideContainer(XmlContextNode parent, OrmAssociationOverrideContainer.Owner owner) { - return new GenericOrmAssociationOverrideContainer(parent, owner); - } - - public OrmAssociationOverrideContainer buildOrmAssociationOverrideContainer(OrmEmbeddedMapping2_0 parent, OrmAssociationOverrideContainer.Owner owner) { - return new NullOrmAssociationOverrideContainer(parent, owner); - } - - public OrmAttributeOverride buildOrmAttributeOverride(OrmAttributeOverrideContainer parent, AttributeOverride.Owner owner, XmlAttributeOverride xmlAttributeOverride) { - return new GenericOrmAttributeOverride(parent, owner, xmlAttributeOverride); - } - - public OrmAssociationOverride buildOrmAssociationOverride(OrmAssociationOverrideContainer parent, AssociationOverride.Owner owner, XmlAssociationOverride xmlAssociationOverride) { - return new GenericOrmAssociationOverride(parent, owner, xmlAssociationOverride); - } - - public OrmAssociationOverrideRelationshipReference buildOrmAssociationOverrideRelationshipReference(OrmAssociationOverride parent, XmlAssociationOverride associationOverride) { - return new GenericOrmAssociationOverrideRelationshipReference(parent, associationOverride); - } - - public OrmDiscriminatorColumn buildOrmDiscriminatorColumn(OrmEntity parent, OrmDiscriminatorColumn.Owner owner) { - return new GenericOrmDiscriminatorColumn(parent, owner); - } - - public OrmColumn buildOrmColumn(XmlContextNode parent, OrmColumn.Owner owner) { - return new GenericOrmColumn(parent, owner); - } - - public OrmGeneratedValue buildOrmGeneratedValue(XmlContextNode parent, XmlGeneratedValue resourceGeneratedValue) { - return new GenericOrmGeneratedValue(parent, resourceGeneratedValue); - } - - public OrmGeneratorContainer buildOrmGeneratorContainer(XmlContextNode parent, XmlGeneratorContainer resourceGeneratorContainer) { - return new GenericOrmGeneratorContainer(parent, resourceGeneratorContainer); - } - - public OrmSequenceGenerator buildOrmSequenceGenerator(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { - return new GenericOrmSequenceGenerator(parent, resourceSequenceGenerator); - } - - public OrmTableGenerator buildOrmTableGenerator(XmlContextNode parent, XmlTableGenerator resourceTableGenerator) { - return new GenericOrmTableGenerator(parent, resourceTableGenerator); - } - - public OrmQueryContainer buildOrmQueryContainer(XmlContextNode parent, XmlQueryContainer resourceQueryContainer) { - return new GenericOrmQueryContainer(parent, resourceQueryContainer); - } - - public OrmNamedNativeQuery buildOrmNamedNativeQuery(XmlContextNode parent, XmlNamedNativeQuery resourceNamedNativeQuery) { - return new GenericOrmNamedNativeQuery(parent, resourceNamedNativeQuery); - } - - public OrmNamedQuery buildOrmNamedQuery(XmlContextNode parent, XmlNamedQuery resourceNamedQuery) { - return new GenericOrmNamedQuery(parent, resourceNamedQuery); - } - - public OrmQueryHint buildOrmQueryHint(OrmQuery parent, XmlQueryHint resourceQueryHint) { - return new GenericOrmQueryHint(parent, resourceQueryHint); - } - - public OrmBasicMapping buildOrmBasicMapping(OrmPersistentAttribute parent, XmlBasic resourceMapping) { - return new GenericOrmBasicMapping(parent, resourceMapping); - } - - public OrmEmbeddedMapping buildOrmEmbeddedMapping(OrmPersistentAttribute parent, XmlEmbedded resourceMapping) { - return new GenericOrmEmbeddedMapping(parent, resourceMapping); - } - - public OrmEmbeddedIdMapping buildOrmEmbeddedIdMapping(OrmPersistentAttribute parent, XmlEmbeddedId resourceMapping) { - return new GenericOrmEmbeddedIdMapping(parent, resourceMapping); - } - - public OrmIdMapping buildOrmIdMapping(OrmPersistentAttribute parent, XmlId resourceMapping) { - return new GenericOrmIdMapping(parent, resourceMapping); - } - - public OrmManyToManyMapping buildOrmManyToManyMapping(OrmPersistentAttribute parent, XmlManyToMany resourceMapping) { - return new GenericOrmManyToManyMapping(parent, resourceMapping); - } - - public OrmManyToOneMapping buildOrmManyToOneMapping(OrmPersistentAttribute parent, XmlManyToOne resourceMapping) { - return new GenericOrmManyToOneMapping(parent, resourceMapping); - } - - public OrmOneToManyMapping buildOrmOneToManyMapping(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { - return new GenericOrmOneToManyMapping(parent, resourceMapping); - } - - public OrmOneToOneMapping buildOrmOneToOneMapping(OrmPersistentAttribute parent, XmlOneToOne resourceMapping) { - return new GenericOrmOneToOneMapping(parent, resourceMapping); - } - - public OrmTransientMapping buildOrmTransientMapping(OrmPersistentAttribute parent, XmlTransient resourceMapping) { - return new GenericOrmTransientMapping(parent, resourceMapping); - } - - public OrmVersionMapping buildOrmVersionMapping(OrmPersistentAttribute parent, XmlVersion resourceMapping) { - return new GenericOrmVersionMapping(parent, resourceMapping); - } - - public OrmAttributeMapping buildOrmNullAttributeMapping(OrmPersistentAttribute parent, XmlNullAttributeMapping resourceMapping) { - return new GenericOrmNullAttributeMapping(parent, resourceMapping); - } - - public OrmAttributeMapping buildUnsupportedOrmAttributeMapping(OrmPersistentAttribute parent, XmlNullAttributeMapping resourceMapping) { - return new UnsupportedOrmAttributeMapping(parent, resourceMapping); - } - - public OrmUniqueConstraint buildOrmUniqueConstraint(XmlContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint resourceUniqueConstraint) { - return new GenericOrmUniqueConstraint(parent, owner, resourceUniqueConstraint); - } - - public OrmConverter buildOrmEnumeratedConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmEnumeratedConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmLobConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmLobConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmTemporalConverter(OrmAttributeMapping parent, XmlConvertibleMapping resourceMapping) { - return new GenericOrmTemporalConverter(parent, resourceMapping); - } - - public OrmConverter buildOrmNullConverter(OrmAttributeMapping parent) { - return new GenericOrmNullConverter(parent); - } - - public OrmOrderable2_0 buildOrmOrderable(OrmAttributeMapping parent, Orderable.Owner owner) { - return new GenericOrmOrderable(parent, owner); - } - - public OrmOrderColumn2_0 buildOrmOrderColumn(OrmOrderable2_0 parent, OrmNamedColumn.Owner owner) { - return new GenericOrmOrderColumn2_0(parent, owner); - } - - public OrmDerivedIdentity2_0 buildOrmDerivedIdentity( - OrmSingleRelationshipMapping2_0 parent, XmlSingleRelationshipMapping_2_0 resource) { - return new NullOrmDerivedIdentity2_0(parent); - } - - public OrmElementCollectionMapping2_0 buildOrmElementCollectionMapping2_0( - OrmPersistentAttribute parent, XmlElementCollection resourceMapping) { - - throw new UnsupportedOperationException(); - } - - public OrmCacheable2_0 buildOrmCacheable(OrmCacheableHolder2_0 parent, XmlCacheable_2_0 resource) { - return new NullOrmCacheable2_0(parent); - } - - public OrmOrphanRemovable2_0 buildOrmOrphanRemoval(OrmOrphanRemovalHolder2_0 parent, XmlOrphanRemovable_2_0 resource) { - return new NullOrmOrphanRemoval2_0(parent); - } - - public OrmCollectionTable2_0 buildOrmCollectionTable(OrmElementCollectionMapping2_0 parent, XmlCollectionTable resource) { - throw new UnsupportedOperationException(); - } - - // ********** ORM Virtual Resource Model ********** - - public XmlAssociationOverride buildVirtualXmlAssociationOverride(String name, OrmTypeMapping parent, JoiningStrategy joiningStrategy) { - return new VirtualXmlAssociationOverride(name, parent, joiningStrategy); - } - - public XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - return new VirtualXmlBasic(ormTypeMapping, javaBasicMapping); - } - - public XmlEmbeddedId buildVirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - return new VirtualXmlEmbeddedId(ormTypeMapping, javaEmbeddedIdMapping); - } - - public XmlEmbedded buildVirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - return new VirtualXmlEmbedded(ormTypeMapping, javaEmbeddedMapping); - } - - public XmlId buildVirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - return new VirtualXmlId(ormTypeMapping, javaIdMapping); - } - - public XmlManyToMany buildVirtualXmlManyToMany(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - return new VirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); - } - - public XmlManyToOne buildVirtualXmlManyToOne(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - return new VirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); - } - - public XmlOneToMany buildVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - return new VirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); - } - - public XmlOneToOne buildVirtualXmlOneToOne(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - return new VirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); - } - - public XmlTransient buildVirtualXmlTransient(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - return new VirtualXmlTransient(ormTypeMapping, javaTransientMapping); - } - - public XmlVersion buildVirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - return new VirtualXmlVersion(ormTypeMapping, javaVersionMapping); - } - - public XmlNullAttributeMapping buildVirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - return new VirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - - public XmlElementCollection buildVirtualXmlElementCollection2_0(OrmTypeMapping ormTypeMapping, JavaElementCollectionMapping2_0 javaMapping) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java deleted file mode 100644 index 367f38c895..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmXmlDefinition.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.context.orm.OrmXmlDefinition; -import org.eclipse.jpt.core.context.orm.UnsupportedOrmAttributeMappingDefinition; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Tools; -import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; - -/** - * All the state in the definition should be "static" (i.e. unchanging once it is initialized). - */ -public abstract class AbstractOrmXmlDefinition - implements OrmXmlDefinition -{ - private OrmTypeMappingDefinition[] ormTypeMappingDefinitions; - - private OrmAttributeMappingDefinition[] ormAttributeMappingDefinitions; - - private final OrmXmlContextNodeFactory factory; - - - /** - * zero-argument constructor - */ - protected AbstractOrmXmlDefinition() { - super(); - this.factory = buildContextNodeFactory(); - } - - - protected abstract OrmXmlContextNodeFactory buildContextNodeFactory(); - - public OrmXmlContextNodeFactory getContextNodeFactory() { - return this.factory; - } - - - // ********** ORM type mappings ********** - - public OrmTypeMappingDefinition getOrmTypeMappingDefinition(String mappingKey) { - for (OrmTypeMappingDefinition definition : CollectionTools.iterable(ormTypeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$ - } - - public ListIterator<OrmTypeMappingDefinition> ormTypeMappingDefinitions() { - return new ArrayListIterator<OrmTypeMappingDefinition>(getOrmTypeMappingDefinitions()); - } - - protected synchronized OrmTypeMappingDefinition[] getOrmTypeMappingDefinitions() { - if (this.ormTypeMappingDefinitions == null) { - this.ormTypeMappingDefinitions = this.buildOrmTypeMappingDefinitions(); - } - return this.ormTypeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for types in mapping files of this type. - * The order is unimportant. - */ - protected abstract OrmTypeMappingDefinition[] buildOrmTypeMappingDefinitions(); - - - // ********** ORM attribute mappings ********** - - public OrmAttributeMappingDefinition getOrmAttributeMappingDefinition(String mappingKey) { - for (OrmAttributeMappingDefinition definition : CollectionTools.iterable(ormAttributeMappingDefinitions())) { - if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) { - return definition; - } - } - return UnsupportedOrmAttributeMappingDefinition.instance(); - } - - public ListIterator<OrmAttributeMappingDefinition> ormAttributeMappingDefinitions() { - return new ArrayListIterator<OrmAttributeMappingDefinition>(getOrmAttributeMappingDefinitions()); - } - - protected synchronized OrmAttributeMappingDefinition[] getOrmAttributeMappingDefinitions() { - if (this.ormAttributeMappingDefinitions == null) { - this.ormAttributeMappingDefinitions = this.buildOrmAttributeMappingDefinitions(); - } - return this.ormAttributeMappingDefinitions; - } - - /** - * Return an array of mapping definitions to use for attributes in mapping files of this type. - * The order is unimportant. - */ - protected abstract OrmAttributeMappingDefinition[] buildOrmAttributeMappingDefinitions(); -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java deleted file mode 100644 index 5b9a999399..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.java.JavaIdClassReference; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmIdClassReference; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlClassReference; -import org.eclipse.jpt.core.resource.orm.XmlIdClassContainer; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmIdClassReference - extends AbstractXmlContextNode - implements OrmIdClassReference -{ - protected String specifiedIdClassName; - - protected String defaultIdClassName; - - protected JavaPersistentType idClass; - - - public GenericOrmIdClassReference(OrmTypeMapping parent, JavaIdClassReference javaIdClassReference) { - super(parent); - this.specifiedIdClassName = buildSpecifiedIdClassName(); - this.defaultIdClassName = buildDefaultIdClassName(javaIdClassReference); - this.idClass = buildIdClass(); - } - - - protected OrmTypeMapping getTypeMapping() { - return (OrmTypeMapping) getParent(); - } - - protected OrmPersistentType getPersistentType() { - return getTypeMapping().getPersistentType(); - } - - - // **************** PersistentType.Owner impl ***************************** - - public AccessType getOverridePersistentTypeAccess() { - return getPersistentType().getAccess(); - } - - public AccessType getDefaultPersistentTypeAccess() { - // this shouldn't be needed, since we've specified an override access, but just to be safe ... - return getPersistentType().getAccess(); - } - - - // **************** IdClassReference impl ********************************* - - public String getSpecifiedIdClassName() { - return this.specifiedIdClassName; - } - - public void setSpecifiedIdClassName(String newClassName) { - String oldClassName = this.specifiedIdClassName; - this.specifiedIdClassName = newClassName; - if (valuesAreDifferent(oldClassName, newClassName)) { - if (getIdXmlClassRef() != null) { - getIdXmlClassRef().setClassName(newClassName); - if (getIdXmlClassRef().isUnset()) { - removeIdClassElement(); - } - } - else if (newClassName != null) { - addIdClassElement(); - getIdXmlClassRef().setClassName(newClassName); - } - } - firePropertyChanged(SPECIFIED_ID_CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - protected void setSpecifiedIdClassName_(String newClassName) { - String oldClassName = this.specifiedIdClassName; - this.specifiedIdClassName = newClassName; - firePropertyChanged(SPECIFIED_ID_CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - protected String buildSpecifiedIdClassName() { - XmlClassReference idXmlClassRef = this.getIdXmlClassRef(); - return (idXmlClassRef == null) ? null : idXmlClassRef.getClassName(); - } - - public String getDefaultIdClassName() { - return this.defaultIdClassName; - } - - protected void setDefaultIdClassName_(String newClassName) { - String oldClassName = this.defaultIdClassName; - this.defaultIdClassName = newClassName; - firePropertyChanged(DEFAULT_ID_CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - protected String buildDefaultIdClassName(JavaIdClassReference javaIdClassReference) { - return (javaIdClassReference == null) ? null : javaIdClassReference.getFullyQualifiedIdClassName(); - } - - public String getIdClassName() { - return (this.specifiedIdClassName == null) ? this.defaultIdClassName : this.specifiedIdClassName; - } - - public boolean isSpecified() { - return getIdClassName() != null; - } - - public JavaPersistentType getIdClass() { - return this.idClass; - } - - protected void setIdClass_(JavaPersistentType newIdClass) { - JavaPersistentType oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected JavaPersistentType buildIdClass() { - JavaResourcePersistentType resourceIdClass = getResourceIdClass(); - return (resourceIdClass == null) ? - null : this.buildIdClass(resourceIdClass); - } - - protected JavaPersistentType buildIdClass(JavaResourcePersistentType resourceClass) { - return getJpaFactory().buildJavaPersistentType(this, resourceClass); - } - - protected XmlTypeMapping getResourceTypeMapping() { - return getTypeMapping().getResourceTypeMapping(); - } - - protected XmlIdClassContainer getResourceIdClassContainer() { - return (XmlIdClassContainer) getResourceTypeMapping(); - } - - protected XmlClassReference getIdXmlClassRef() { - return this.getResourceIdClassContainer().getIdClass(); - } - - protected void addIdClassElement() { - getResourceIdClassContainer().setIdClass(OrmFactory.eINSTANCE.createXmlClassReference()); - } - - protected void removeIdClassElement() { - getResourceIdClassContainer().setIdClass(null); - } - - protected JavaResourcePersistentType getResourceIdClass() { - XmlClassReference idXmlClassRef = this.getIdXmlClassRef(); - if (idXmlClassRef == null) { - return null; - } - - String className = idXmlClassRef.getClassName(); - if (className == null) { - return null; - } - - return this.getEntityMappings().resolveJavaResourcePersistentType(className); - } - - protected EntityMappings getEntityMappings() { - return (EntityMappings) getMappingFileRoot(); - } - - public char getIdClassEnclosingTypeSeparator() { - return '$'; - } - - public void update(JavaIdClassReference javaIdClassReference) { - setDefaultIdClassName_(buildDefaultIdClassName(javaIdClassReference)); - setSpecifiedIdClassName_(buildSpecifiedIdClassName()); - updateIdClass(); - } - - protected void updateIdClass() { - JavaResourcePersistentType resourceIdClass = getResourceIdClass(); - if (resourceIdClass == null) { - setIdClass_(null); - } - else { - if (this.idClass == null || this.idClass.getResourcePersistentType() != resourceIdClass) { - setIdClass_(buildIdClass(resourceIdClass)); - } - else { - this.idClass.update(resourceIdClass); - } - } - } - - - // **************** validation ******************************************** - - public TextRange getValidationTextRange() { - XmlClassReference idXmlClassRef = getIdXmlClassRef(); - return (idXmlClassRef == null) ? - this.getTypeMapping().getValidationTextRange() : - idXmlClassRef.getClassNameTextRange(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - // most validation is done "holistically" from the type mapping level - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java deleted file mode 100644 index d82061ceca..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnInAssociationOverrideJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn.Owner; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmJoinColumnInAssociationOverrideJoiningStrategy - extends AbstractOrmJoinColumnJoiningStrategy - implements OrmJoinColumnInAssociationOverrideJoiningStrategy -{ - - public GenericOrmJoinColumnInAssociationOverrideJoiningStrategy(OrmAssociationOverrideRelationshipReference parent, XmlAssociationOverride xao) { - super(parent, xao); - } - - @Override - protected Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - public boolean isTargetForeignKeyRelationship() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - if (relationshipMapping != null) { - return relationshipMapping.getRelationshipReference().isTargetForeignKeyRelationship(); - } - return false; - } - - public TypeMapping getRelationshipSource() { - if (isTargetForeignKeyRelationship()) { - return getRelationshipMapping().getResolvedTargetEntity(); - } - return getAssociationOverrideOwner().getTypeMapping(); - } - - public TypeMapping getRelationshipTarget() { - if (isTargetForeignKeyRelationship()) { - return getAssociationOverrideOwner().getTypeMapping(); - } - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - protected Entity getRelationshipTargetEntity() { - TypeMapping relationshipTarget = getRelationshipTarget(); - return (relationshipTarget != null) && (relationshipTarget.getKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) ? (Entity) relationshipTarget : null; - } - - @Override - public RelationshipMapping getRelationshipMapping() { - return getAssociationOverrideOwner().getRelationshipMapping(getAttributeName()); - } - - protected String getAttributeName() { - return this.getAssociationOverride().getName(); - } - - @Override - public String getTableName() { - if (isTargetForeignKeyRelationship()) { - return super.getTableName(); - } - return getAssociationOverrideOwner().getDefaultTableName(); - } - - @Override - public Table getDbTable(String tableName) { - if (isTargetForeignKeyRelationship()) { - return super.getDbTable(tableName); - } - return getAssociationOverrideOwner().getDbTable(tableName); - } - - @Override - public boolean tableNameIsInvalid(String tableName) { - if (isTargetForeignKeyRelationship()) { - return super.tableNameIsInvalid(tableName); - } - return getAssociationOverrideOwner().tableNameIsInvalid(tableName); - } - - @Override - public Iterator<String> candidateTableNames() { - if (isTargetForeignKeyRelationship()) { - return super.candidateTableNames(); - } - return getAssociationOverrideOwner().candidateTableNames(); - } - - public String getColumnTableNotValidDescription() { - return null; - } - - public boolean isOverridableAssociation() { - return false; - } - - protected OrmAssociationOverride getAssociationOverride() { - return this.getRelationshipReference().getAssociationOverride(); - } - - protected OrmAssociationOverride.Owner getAssociationOverrideOwner() { - return getAssociationOverride().getOwner(); - } - - @Override - public OrmAssociationOverrideRelationshipReference getRelationshipReference() { - return (OrmAssociationOverrideRelationshipReference) super.getRelationshipReference(); - } - - public TextRange getValidationTextRange() { - return getRelationshipReference().getValidationTextRange(); - } - - public void update(XmlAssociationOverride xao) { - //TODO can we make resource final and then just have an update() method? - //would need to update the association overrides with the same resource association override - this.resource = xao; - super.update(); - } - - - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - public String getDefaultTableName() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getTableName(); - } - - public String getDefaultColumnName() { - //built in MappingTools.buildJoinColumnDefaultName() - return null; - } - - public String getAttributeName() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getAttributeName(); - } - - public PersistentAttribute getPersistentAttribute() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getPersistentAttribute(); - } - - public TypeMapping getTypeMapping() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipSource(); - } - - public Entity getRelationshipTarget() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getRelationshipTargetEntity(); - } - - public boolean tableNameIsInvalid(String tableName) { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.tableNameIsInvalid(tableName); - } - - public Iterator<String> candidateTableNames() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.candidateTableNames(); - } - - public Table getDbTable(String tableName) { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getReferencedColumnDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public int joinColumnsSize() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return GenericOrmJoinColumnInAssociationOverrideJoiningStrategy.this.getValidationTextRange(); - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - return getAssociationOverrideOwner().buildColumnTableNotValidMessage(getAssociationOverride(), column, textRange); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - return getAssociationOverrideOwner().buildColumnUnresolvedNameMessage(getAssociationOverride(), column, textRange); - } - - public IMessage buildUnresolvedReferencedColumnNameMessage(BaseJoinColumn column, TextRange textRange) { - return getAssociationOverrideOwner().buildColumnUnresolvedReferencedColumnNameMessage(getAssociationOverride(), column, textRange); - } - - public IMessage buildUnspecifiedNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - return getAssociationOverrideOwner().buildUnspecifiedNameMultipleJoinColumnsMessage(getAssociationOverride(), column, textRange); - } - - public IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - return getAssociationOverrideOwner().buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(getAssociationOverride(), column, textRange); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java deleted file mode 100644 index 3f5775129d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumnsMapping; - -public class GenericOrmJoinColumnJoiningStrategy - extends AbstractOrmJoinColumnInRelationshipMappingJoiningStrategy -{ - - public GenericOrmJoinColumnJoiningStrategy( - OrmJoinColumnEnabledRelationshipReference parent, - XmlJoinColumnsMapping resource) { - super(parent, resource); - } - - public TypeMapping getRelationshipSource() { - return getRelationshipMapping().getTypeMapping(); - } - - public TypeMapping getRelationshipTarget() { - return getRelationshipTargetEntity(); - } - - @Override - protected Entity getRelationshipTargetEntity() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public boolean isTargetForeignKeyRelationship() { - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java deleted file mode 100644 index bb0882b662..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTableJoiningStrategy.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlJoinTableMapping; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmJoinTableJoiningStrategy - extends AbstractOrmJoinTableJoiningStrategy -{ - protected XmlJoinTableMapping resource; - - - public GenericOrmJoinTableJoiningStrategy( - OrmJoinTableEnabledRelationshipReference parent, - XmlJoinTableMapping resource) { - super(parent); - this.resource = resource; - this.initialize(); - } - - - @Override - public OrmJoinTableEnabledRelationshipReference getParent() { - return (OrmJoinTableEnabledRelationshipReference) super.getParent(); - } - - @Override - public OrmJoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - @Override - protected void setResourceJoinTable(XmlJoinTable resourceJoinTable) { - this.resource.setJoinTable(resourceJoinTable); - } - - public boolean isOverridableAssociation() { - return getJpaPlatformVariation().isJoinTableOverridable(); - } - - public boolean shouldValidateAgainstDatabase() { - return getRelationshipMapping().shouldValidateAgainstDatabase(); - } - - // **************** join table ********************************************* - - public void removeResourceJoinTable() { - this.resource.setJoinTable(null); - } - - public XmlJoinTable getResourceJoinTable() { - return this.resource.getJoinTable(); - } - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange() { - return getRelationshipReference().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java deleted file mode 100644 index 177b534ba7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyRelationshipReference.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.List; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipReference; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmManyToManyRelationshipReference - extends AbstractOrmRelationshipReference - implements OrmManyToManyRelationshipReference -{ - protected OrmMappedByJoiningStrategy mappedByJoiningStrategy; - - protected OrmJoinTableJoiningStrategy joinTableJoiningStrategy; - - - public GenericOrmManyToManyRelationshipReference( - OrmManyToManyMapping parent, XmlManyToMany resource) { - super(parent, resource); - } - - - @Override - protected void initializeJoiningStrategies() { - this.mappedByJoiningStrategy = buildMappedByJoiningStrategy(); - - // initialize join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy = buildJoinTableJoiningStrategy(); - } - - protected OrmMappedByJoiningStrategy buildMappedByJoiningStrategy() { - return new GenericOrmMappedByJoiningStrategy(this, getResourceMapping()); - } - - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new GenericOrmJoinTableJoiningStrategy(this, getResourceMapping()); - } - - public void initializeOn(OrmRelationshipReference newRelationshipReference) { - newRelationshipReference.initializeFromOwnableRelationshipReference(this); - newRelationshipReference.initializeFromJoinTableEnabledRelationshipReference(this); - } - - @Override - public void initializeFromOwnableRelationshipReference( - OrmOwnableRelationshipReference oldRelationshipReference) { - super.initializeFromOwnableRelationshipReference(oldRelationshipReference); - this.mappedByJoiningStrategy.setMappedByAttribute( - oldRelationshipReference.getMappedByJoiningStrategy().getMappedByAttribute()); - } - - @Override - public void initializeFromJoinTableEnabledRelationshipReference( - OrmJoinTableEnabledRelationshipReference oldRelationshipReference) { - super.initializeFromJoinTableEnabledRelationshipReference(oldRelationshipReference); - OrmJoinTable oldTable = - oldRelationshipReference.getJoinTableJoiningStrategy().getJoinTable(); - if (oldTable != null) { - this.joinTableJoiningStrategy.addJoinTable().initializeFrom(oldTable); - } - } - - - @Override - public OrmManyToManyMapping getRelationshipMapping() { - return (OrmManyToManyMapping) super.getRelationshipMapping(); - } - - public XmlManyToMany getResourceMapping() { - return getRelationshipMapping().getResourceAttributeMapping(); - } - - public boolean isRelationshipOwner() { - return this.mappedByJoiningStrategy.getMappedByAttribute() == null; - } - - public boolean isOwnedBy(RelationshipMapping mapping) { - return this.mappedByJoiningStrategy.relationshipIsOwnedBy(mapping); - } - - @Override - protected OrmJoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - return this.joinTableJoiningStrategy; - } - - - // **************** mapped by ********************************************** - - public OrmMappedByJoiningStrategy getMappedByJoiningStrategy() { - return this.mappedByJoiningStrategy; - } - - public boolean usesMappedByJoiningStrategy() { - return getPredominantJoiningStrategy() == this.mappedByJoiningStrategy; - } - - public void setMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.addStrategy(); - this.joinTableJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public void unsetMappedByJoiningStrategy() { - this.mappedByJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayBeMappedBy(AttributeMapping mappedByMapping) { - return mappedByMapping.getKey() == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - - // **************** join table joining strategy *************************** - - public OrmJoinTableJoiningStrategy getJoinTableJoiningStrategy() { - return this.joinTableJoiningStrategy; - } - - public boolean usesJoinTableJoiningStrategy() { - return getPredominantJoiningStrategy() == this.joinTableJoiningStrategy; - } - - public void setJoinTableJoiningStrategy() { - // join table is the default strategy, so no need to add to resource - this.mappedByJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public void unsetJoinTableJoiningStrategy() { - this.joinTableJoiningStrategy.removeStrategy(); - setPredominantJoiningStrategy(); - } - - public boolean mayHaveDefaultJoinTable() { - return getMappedByJoiningStrategy().getMappedByAttribute() == null; - } - - - // **************** resource => context ************************************ - - @Override - protected void updateJoiningStrategies() { - this.mappedByJoiningStrategy.update(); - - // update join table last, as the existence of a default join - // table is dependent on the other mechanisms (mappedBy) - // not being specified - this.joinTableJoiningStrategy.update(); - } - - - // **************** Validation ********************************************* - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - this.mappedByJoiningStrategy.validate(messages, reporter); - this.joinTableJoiningStrategy.validate(messages, reporter); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java deleted file mode 100644 index 26b5d5f573..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneRelationshipReference.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - -public class GenericOrmManyToOneRelationshipReference - extends AbstractOrmManyToOneRelationshipReference -{ - - public GenericOrmManyToOneRelationshipReference( - OrmManyToOneMapping parent, XmlManyToOne resource) { - super(parent, resource); - } - - @Override - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new NullOrmJoinTableJoiningStrategy(this); - } - - @Override - protected OrmJoiningStrategy calculatePredominantJoiningStrategy() { - // the only joining strategy - return this.joinColumnJoiningStrategy; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java deleted file mode 100644 index a637ac4280..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedByJoiningStrategy.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedByJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOwnableRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.XmlMappedByMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class GenericOrmMappedByJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmMappedByJoiningStrategy -{ - protected XmlMappedByMapping resource; - - protected String mappedByAttribute; - - - public GenericOrmMappedByJoiningStrategy( - OrmOwnableRelationshipReference parent, - XmlMappedByMapping resource) { - super(parent); - this.resource = resource; - this.mappedByAttribute = this.resource.getMappedBy(); - } - - - @Override - public OrmOwnableRelationshipReference getParent() { - return (OrmOwnableRelationshipReference) super.getParent(); - } - - public OrmOwnableRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public String getTableName() { - RelationshipMapping owner = getRelationshipOwner(); - return owner == null ? null : owner.getRelationshipReference().getPredominantJoiningStrategy().getTableName(); - } - - public Table getDbTable(String tableName) { - RelationshipMapping owner = getRelationshipOwner(); - return owner == null ? null : owner.getRelationshipReference().getPredominantJoiningStrategy().getDbTable(tableName); - } - - public boolean tableNameIsInvalid(String tableName) { - RelationshipMapping owner = getRelationshipOwner(); - return owner == null ? false : owner.getRelationshipReference().getPredominantJoiningStrategy().tableNameIsInvalid(tableName); - } - - public String getColumnTableNotValidDescription() { - //this will not be called if getRelationshipOwner() is null - return getRelationshipOwner().getRelationshipReference().getPredominantJoiningStrategy().getColumnTableNotValidDescription(); - } - - protected RelationshipMapping getRelationshipOwner() { - return getRelationshipMapping().getRelationshipOwner(); - } - - public boolean isOverridableAssociation() { - return false; - } - - public OrmRelationshipMapping getRelationshipMapping() { - return getParent().getRelationshipMapping(); - } - - public boolean relationshipIsOwnedBy(RelationshipMapping otherMapping) { - String thisEntity = - (getRelationshipReference().getEntity()) == null ? - null : getRelationshipReference().getEntity().getName(); - String targetEntity = - (otherMapping.getResolvedTargetEntity() == null) ? - null : otherMapping.getResolvedTargetEntity().getName(); - return StringTools.stringsAreEqual( - thisEntity, - targetEntity) - && StringTools.stringsAreEqual( - getMappedByAttribute(), - otherMapping.getName()); - } - - public String getMappedByAttribute() { - return this.mappedByAttribute; - } - - public void setMappedByAttribute(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - this.resource.setMappedBy(newMappedByAttribute); - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - protected void setMappedByAttribute_(String newMappedByAttribute) { - String oldMappedByAttribute = this.mappedByAttribute; - this.mappedByAttribute = newMappedByAttribute; - firePropertyChanged(MAPPED_BY_ATTRIBUTE_PROPERTY, oldMappedByAttribute, newMappedByAttribute); - } - - public void addStrategy() { - if (this.mappedByAttribute == null) { - setMappedByAttribute(""); //$NON-NLS-1$ - } - } - - public void removeStrategy() { - if (this.mappedByAttribute != null) { - setMappedByAttribute(null); - } - } - - public void update() { - setMappedByAttribute_(this.resource.getMappedBy()); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return getRelationshipMapping().allTargetEntityAttributeNames(); - } - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange() { - TextRange mappedByTextRange = this.resource.getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getRelationshipReference().getValidationTextRange(); - } - - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (getMappedByAttribute() == null) { - return; - } - - Entity targetEntity = this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return; // null target entity is validated elsewhere - } - - AttributeMapping mappedByMapping = targetEntity.resolveAttributeMapping(this.mappedByAttribute); - - if (mappedByMapping == null) { - messages.add( - buildMessage( - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {this.mappedByAttribute})); - return; - } - - if (! this.getRelationshipReference().mayBeMappedBy(mappedByMapping)) { - messages.add( - buildMessage( - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {this.mappedByAttribute})); - return; - } - - // if mappedByMapping is not a relationship owner, then it should have - // been flagged in above rule (mappedByIsValid) - if (! ((RelationshipMapping) mappedByMapping).isRelationshipOwner()) { - messages.add(buildMessage( - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - new String[] {this.mappedByAttribute})); - } - } - - protected IMessage buildMessage(String msgID, String[] params) { - String attributeDescString; - PersistentAttribute attribute = getRelationshipMapping().getPersistentAttribute(); - if (attribute.isVirtual()) { - attributeDescString = NLS.bind(JpaValidationDescriptionMessages.VIRTUAL_ATTRIBUTE_DESC, attribute.getName()); - } - else { - attributeDescString = NLS.bind(JpaValidationDescriptionMessages.ATTRIBUTE_DESC, attribute.getName()); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, msgID, ArrayTools.add(params, 0, attributeDescString), this, getValidationTextRange()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java deleted file mode 100644 index 86673561c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneRelationshipReference.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJoinTableJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; - -public class GenericOrmOneToOneRelationshipReference - extends AbstractOrmOneToOneRelationshipReference -{ - - - public GenericOrmOneToOneRelationshipReference( - OrmOneToOneMapping parent, XmlOneToOne resource) { - super(parent, resource); - } - - - @Override - protected OrmJoinTableJoiningStrategy buildJoinTableJoiningStrategy() { - return new NullOrmJoinTableJoiningStrategy(this); - } - - @Override - protected OrmJoiningStrategy calculatePredominantJoiningStrategy() { - if (this.mappedByJoiningStrategy.getMappedByAttribute() != null) { - return this.mappedByJoiningStrategy; - } - else if (this.primaryKeyJoinColumnJoiningStrategy.primaryKeyJoinColumnsSize() > 0) { - return this.primaryKeyJoinColumnJoiningStrategy; - } - return this.joinColumnJoiningStrategy; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java deleted file mode 100644 index f1a1758182..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnJoiningStrategy.java +++ /dev/null @@ -1,305 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Vector; - -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.JpaValidationDescriptionMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmPrimaryKeyJoinColumnJoiningStrategy - extends AbstractOrmXmlContextNode - implements OrmPrimaryKeyJoinColumnJoiningStrategy -{ - protected XmlOneToOne resource; - - protected final Vector<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = new Vector<OrmPrimaryKeyJoinColumn>(); - - protected final OrmJoinColumn.Owner joinColumnOwner; - - - public GenericOrmPrimaryKeyJoinColumnJoiningStrategy( - OrmPrimaryKeyJoinColumnEnabledRelationshipReference parent, - XmlOneToOne resource) { - super(parent); - this.resource = resource; - this.joinColumnOwner = this.buildJoinColumnOwner(); - this.initializePrimaryKeyJoinColumns(); - } - - protected OrmJoinColumn.Owner buildJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void initializePrimaryKeyJoinColumns() { - if (this.resource != null) { - for (XmlPrimaryKeyJoinColumn resourceJoinColumn : this.resource.getPrimaryKeyJoinColumns()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(resourceJoinColumn)); - } - } - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn( - XmlPrimaryKeyJoinColumn resourceJoinColumn) { - return this.getXmlContextNodeFactory().buildOrmPrimaryKeyJoinColumn(this, this.joinColumnOwner, resourceJoinColumn); - } - - @Override - public OrmJoinColumnEnabledRelationshipReference getParent() { - return (OrmJoinColumnEnabledRelationshipReference) super.getParent(); - } - - public OrmJoinColumnEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - public OrmRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - public String getTableName() { - return getTypeMapping().getPrimaryTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - public String getColumnTableNotValidDescription() { - return JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY; - } - - protected TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public void addStrategy() { - if (primaryKeyJoinColumnsSize() == 0) { - addPrimaryKeyJoinColumn(0); - } - } - - public void removeStrategy() { - for (PrimaryKeyJoinColumn each : CollectionTools.iterable(primaryKeyJoinColumns())) { - removePrimaryKeyJoinColumn(each); - } - } - - public boolean isOverridableAssociation() { - return false; - } - - - // **************** primary key join columns ******************************* - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public boolean hasPrimaryKeyJoinColumns() { - return ! this.primaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - XmlPrimaryKeyJoinColumn resourcePkJoinColumn = - OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(); - OrmPrimaryKeyJoinColumn contextPkJoinColumn = - this.buildPrimaryKeyJoinColumn(resourcePkJoinColumn); - this.primaryKeyJoinColumns.add(index, contextPkJoinColumn); - this.resource.getPrimaryKeyJoinColumns().add(index, resourcePkJoinColumn); - this.fireItemAdded(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, contextPkJoinColumn); - return contextPkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn joinColumn) { - this.addItemToList(index, joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - protected void addPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn joinColumn) { - this.addPrimaryKeyJoinColumn(this.primaryKeyJoinColumns.size(), joinColumn); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - this.resource.getPrimaryKeyJoinColumns().remove(index); - this.fireItemRemoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - this.resource.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - // **************** resource -> context ************************************ - - public void update() { - updatePrimaryKeyJoinColumns(); - } - - protected void updatePrimaryKeyJoinColumns() { - // make a copy of the XML PK join columns (to prevent ConcurrentModificationException) - Iterator<XmlPrimaryKeyJoinColumn> xmlPkJoinColumns = - new CloneIterator<XmlPrimaryKeyJoinColumn>(this.resource.getPrimaryKeyJoinColumns()); - - for (Iterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = primaryKeyJoinColumns(); - contextPkJoinColumns.hasNext(); ) { - OrmPrimaryKeyJoinColumn contextPkJoinColumn = contextPkJoinColumns.next(); - if (xmlPkJoinColumns.hasNext()) { - contextPkJoinColumn.update(xmlPkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(contextPkJoinColumn); - } - } - - while (xmlPkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(xmlPkJoinColumns.next())); - } - } - - public TextRange getValidationTextRange() { - return this.getRelationshipReference().getValidationTextRange(); - } - - - // ********** join column owner adapter ********** - - protected class JoinColumnOwner - implements OrmJoinColumn.Owner - { - protected JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.getTableName(); - } - - public Entity getRelationshipTarget() { - return getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return getRelationshipMapping().getName(); - } - - public PersistentAttribute getPersistentAttribute() { - return getRelationshipMapping().getPersistentAttribute(); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public Iterator<String> candidateTableNames() { - return getTypeMapping().associatedTableNamesIncludingInherited(); - } - - public TypeMapping getTypeMapping() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getReferencedColumnDbTable() { - Entity relationshipTarget = getRelationshipTarget(); - return (relationshipTarget == null) ? null : relationshipTarget.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return false; - } - - public String getDefaultColumnName() { - return null; - } - - public int joinColumnsSize() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.primaryKeyJoinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return GenericOrmPrimaryKeyJoinColumnJoiningStrategy.this.getValidationTextRange(); - } - - public IMessage buildUnresolvedNameMessage(NamedColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet"); //$NON-NLS-1$ - } - - public IMessage buildTableNotValidMessage(BaseColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet"); //$NON-NLS-1$ - } - - public IMessage buildUnresolvedReferencedColumnNameMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet"); //$NON-NLS-1$ - } - - public IMessage buildUnspecifiedNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet"); //$NON-NLS-1$ - } - - public IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(BaseJoinColumn column, TextRange textRange) { - throw new UnsupportedOperationException("validation not supported yet"); //$NON-NLS-1$ - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java deleted file mode 100644 index 26b83ea43d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmXmlContextNodeFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - - -public class GenericOrmXmlContextNodeFactory extends AbstractOrmXmlContextNodeFactory -{ - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java deleted file mode 100644 index 10dd335a0d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmAssociationOverrideContainer.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverrideContainer; -import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public class NullOrmAssociationOverrideContainer extends AbstractOrmXmlContextNode - implements OrmAssociationOverrideContainer -{ - - protected final OrmAssociationOverrideContainer.Owner owner; - - public NullOrmAssociationOverrideContainer(XmlContextNode parent, OrmAssociationOverrideContainer.Owner owner) { - super(parent); - this.owner = owner; - } - - protected Owner getOwner() { - return this.owner; - } - - public ListIterator<OrmAssociationOverride> associationOverrides() { - return EmptyListIterator.instance(); - } - - public int associationOverridesSize() { - return 0; - } - - public ListIterator<OrmAssociationOverride> virtualAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int virtualAssociationOverridesSize() { - return 0; - } - - public ListIterator<OrmAssociationOverride> specifiedAssociationOverrides() { - return EmptyListIterator.instance(); - } - - public int specifiedAssociationOverridesSize() { - return 0; - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - throw new UnsupportedOperationException(); - } - - public OrmAssociationOverride getAssociationOverrideNamed(String name) { - return null; - } - - public void update() { - //no-op - } - - - public TextRange getValidationTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmJoinTableJoiningStrategy.java deleted file mode 100644 index 1c65fa9dd5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/NullOrmJoinTableJoiningStrategy.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmJoinTableEnabledRelationshipReference; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.utility.TextRange; - -public class NullOrmJoinTableJoiningStrategy - extends AbstractOrmJoinTableJoiningStrategy -{ - - - public NullOrmJoinTableJoiningStrategy(OrmJoinTableEnabledRelationshipReference parent) { - super(parent); - this.initialize(); - } - - - @Override - public OrmJoinTableEnabledRelationshipReference getParent() { - return (OrmJoinTableEnabledRelationshipReference) super.getParent(); - } - - @Override - public OrmJoinTableEnabledRelationshipReference getRelationshipReference() { - return this.getParent(); - } - - @Override - public OrmRelationshipMapping getRelationshipMapping() { - return this.getRelationshipReference().getRelationshipMapping(); - } - - @Override - protected void setResourceJoinTable(XmlJoinTable resourceJoinTable) { - throw new UnsupportedOperationException(); - } - - public boolean isOverridableAssociation() { - return false; - } - - public boolean shouldValidateAgainstDatabase() { - return false; - } - - // **************** join table ********************************************* - - - public void removeResourceJoinTable() { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean mayHaveJoinTable() { - return false; - } - - public XmlJoinTable getResourceJoinTable() { - return null; - } - - - // **************** validation ********************************************* - - public TextRange getValidationTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java deleted file mode 100644 index 210c6e2f79..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmBasicMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmBasicMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmBasicMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlBasic(), - XmlBasic.class); - } - - public OrmBasicMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmBasicMapping(parent, (XmlBasic) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlBasic(ormTypeMapping, (JavaBasicMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java deleted file mode 100644 index d908024b78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM Embeddable provider - */ -public class OrmEmbeddableDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmEmbeddableDefinition INSTANCE = - new OrmEmbeddableDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddableDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbeddable(), - XmlEmbeddable.class); - } - - public OrmEmbeddable buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddable(parent, (XmlEmbeddable) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java deleted file mode 100644 index 133bd4fbb2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmEmbeddedIdMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmEmbeddedIdMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddedIdMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbeddedId(), - XmlEmbeddedId.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddedIdMapping(parent, (XmlEmbeddedId) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlEmbeddedId(ormTypeMapping, (JavaEmbeddedIdMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java deleted file mode 100644 index 26cd121b1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmEmbeddedMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmEmbeddedMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEmbeddedMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEmbedded(), - XmlEmbedded.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEmbeddedMapping(parent, (XmlEmbedded) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlEmbedded(ormTypeMapping, (JavaEmbeddedMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java deleted file mode 100644 index cf734f64dc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM Entity provider - */ -public class OrmEntityDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmEntityDefinition INSTANCE = - new OrmEntityDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmEntityDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlEntity(), - XmlEntity.class); - } - - public OrmEntity buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmEntity(parent, (XmlEntity) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java deleted file mode 100644 index 76f6fada2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.utility.TextRange; - -public class OrmEntityTextRangeResolver - implements PrimaryKeyTextRangeResolver -{ - private OrmEntity entity; - - - public OrmEntityTextRangeResolver(OrmEntity entity) { - this.entity = entity; - } - - - public TextRange getTypeMappingTextRange() { - return this.entity.getValidationTextRange(); - } - - public TextRange getIdClassTextRange() { - return this.entity.getIdClassReference().getValidationTextRange(); - } - - public TextRange getAttributeMappingTextRange(String attributeName) { - return this.entity.getPersistentType(). - getAttributeNamed(attributeName).getMapping().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java deleted file mode 100644 index afedc490bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmIdMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmIdMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmIdMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlId(), - XmlId.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmIdMapping(parent, (XmlId) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlId(ormTypeMapping, (JavaIdMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java deleted file mode 100644 index c719454455..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmManyToManyMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmManyToManyMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmManyToManyMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlManyToMany(), - XmlManyToMany.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmManyToManyMapping(parent, (XmlManyToMany) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlManyToMany(ormTypeMapping, (JavaManyToManyMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java deleted file mode 100644 index 2098c673e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmManyToOneMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmManyToOneMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmManyToOneMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlManyToOne(), - XmlManyToOne.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmManyToOneMapping(parent, (XmlManyToOne) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlManyToOne(ormTypeMapping, (JavaManyToOneMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java deleted file mode 100644 index c0e2f67d6f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassDefinition.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -/** - * default ORM MappedSuperclass definition - */ -public class OrmMappedSuperclassDefinition - implements OrmTypeMappingDefinition -{ - // singleton - private static final OrmMappedSuperclassDefinition INSTANCE = - new OrmMappedSuperclassDefinition(); - - - /** - * Return the singleton - */ - public static OrmTypeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmMappedSuperclassDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public XmlTypeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlMappedSuperclass(), - XmlMappedSuperclass.class); - } - - public OrmMappedSuperclass buildContextMapping( - OrmPersistentType parent, - XmlTypeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmMappedSuperclass(parent, (XmlMappedSuperclass) resourceMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassTextRangeResolver.java deleted file mode 100644 index bb107bb5b0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassTextRangeResolver.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.utility.TextRange; - -public class OrmMappedSuperclassTextRangeResolver - implements PrimaryKeyTextRangeResolver -{ - private OrmMappedSuperclass mappedSuperclass; - - - public OrmMappedSuperclassTextRangeResolver(OrmMappedSuperclass mappedSuperclass) { - this.mappedSuperclass = mappedSuperclass; - } - - - public TextRange getTypeMappingTextRange() { - return this.mappedSuperclass.getValidationTextRange(); - } - - public TextRange getIdClassTextRange() { - return this.mappedSuperclass.getIdClassReference().getValidationTextRange(); - } - - public TextRange getAttributeMappingTextRange(String attributeName) { - return this.mappedSuperclass.getPersistentType(). - getAttributeNamed(attributeName).getMapping().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java deleted file mode 100644 index f7ea7d8ce8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmOneToManyMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmOneToManyMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmOneToManyMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlOneToMany(), - XmlOneToMany.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmOneToManyMapping(parent, (XmlOneToMany) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlOneToMany(ormTypeMapping, (JavaOneToManyMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java deleted file mode 100644 index 487b0497ea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmOneToOneMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmOneToOneMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmOneToOneMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlOneToOne(), - XmlOneToOne.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmOneToOneMapping(parent, (XmlOneToOne) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlOneToOne(ormTypeMapping, (JavaOneToOneMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java deleted file mode 100644 index 6177649214..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmTransientMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmTransientMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmTransientMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlTransient(), - XmlTransient.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmTransientMapping(parent, (XmlTransient) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlTransient(ormTypeMapping, (JavaTransientMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java deleted file mode 100644 index abc841dda2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingDefinition.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.ecore.EFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmXmlContextNodeFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.xml.EmfTools; - -public class OrmVersionMappingDefinition - implements OrmAttributeMappingDefinition -{ - // singleton - private static final OrmAttributeMappingDefinition INSTANCE = - new OrmVersionMappingDefinition(); - - - /** - * Return the singleton - */ - public static OrmAttributeMappingDefinition instance() { - return INSTANCE; - } - - - /** - * Enforce singleton usage - */ - private OrmVersionMappingDefinition() { - super(); - } - - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public XmlAttributeMapping buildResourceMapping(EFactory factory) { - return EmfTools.create( - factory, - OrmPackage.eINSTANCE.getXmlVersion(), - XmlVersion.class); - } - - public OrmAttributeMapping buildContextMapping( - OrmPersistentAttribute parent, - XmlAttributeMapping resourceMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildOrmVersionMapping(parent, (XmlVersion) resourceMapping); - } - - public XmlAttributeMapping buildVirtualResourceMapping( - OrmTypeMapping ormTypeMapping, - JavaAttributeMapping javaAttributeMapping, - OrmXmlContextNodeFactory factory) { - return factory.buildVirtualXmlVersion(ormTypeMapping, (JavaVersionMapping) javaAttributeMapping); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java deleted file mode 100644 index 6ecb0daf86..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.resource.orm.CascadeType; - -public class VirtualCascadeType extends CascadeType -{ - protected Cascade javaCascade; - - - public VirtualCascadeType(Cascade javaCascade) { - super(); - this.javaCascade = javaCascade; - } - - @Override - public boolean isCascadeAll() { - return this.javaCascade.isAll(); - } - - @Override - public void setCascadeAll(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeMerge() { - return this.javaCascade.isMerge(); - } - - @Override - public void setCascadeMerge(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadePersist() { - return this.javaCascade.isPersist(); - } - - @Override - public void setCascadePersist(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeRefresh() { - return this.javaCascade.isRefresh(); - } - - @Override - public void setCascadeRefresh(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isCascadeRemove() { - return this.javaCascade.isRemove(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java deleted file mode 100644 index 0b75a5c4d3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.CollectionMapping; -import org.eclipse.jpt.core.resource.orm.MapKey; - -public class VirtualMapKey extends MapKey -{ - CollectionMapping javaCollectionMapping; - - public VirtualMapKey(CollectionMapping collectionMapping) { - super(); - this.javaCollectionMapping = collectionMapping; - } - - @Override - public String getName() { - return this.javaCollectionMapping.getSpecifiedMapKey(); - } - - @Override - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java deleted file mode 100644 index 6f4af8edab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAssociationOverride.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c)2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.JoiningStrategy; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlAssociationOverride extends XmlAssociationOverride -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JoiningStrategy joiningStrategy; - - - public VirtualXmlAssociationOverride(String name, OrmTypeMapping ormTypeMapping, JoiningStrategy joiningStrategy) { - super(); - this.name = name; - this.ormTypeMapping = ormTypeMapping; - this.joiningStrategy = joiningStrategy; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ASSOCIATION_OVERRIDE__JOIN_COLUMNS); - if (this.joiningStrategy instanceof JoinColumnJoiningStrategy) { - for (JoinColumn joinColumn : - CollectionTools.iterable(((JoinColumnJoiningStrategy) this.joiningStrategy).joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java deleted file mode 100644 index a071e1ce71..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlAttributeMapping extends AbstractJpaEObject implements XmlAttributeMapping -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaAttributeMapping javaAttributeMapping; - - - public VirtualXmlAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaAttributeMapping; - } - - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - public String getMappingKey() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getPersistentAttribute().getDefaultMappingKey(); - } - return this.javaAttributeMapping.getKey(); - } - - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - public TextRange getNameTextRange() { - return null; - } - - public AccessType getAccess() { - return org.eclipse.jpt.core.context.AccessType.toOrmResourceModel( - this.javaAttributeMapping.getPersistentAttribute().getAccess()); - } - - public void setAccess(AccessType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java deleted file mode 100644 index 86e3490191..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class VirtualXmlAttributeOverride extends XmlAttributeOverride -{ - - public VirtualXmlAttributeOverride(String name, XmlColumn xmlColumn) { - super(); - this.name = name; - this.column = xmlColumn; - } - - @Override - public String getName() { - return this.name; - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java deleted file mode 100644 index d1383f2d92..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverrideColumn.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; - -/** - * javax.persistence.Column - */ -public class VirtualXmlAttributeOverrideColumn - extends VirtualXmlColumn -{ - - public VirtualXmlAttributeOverrideColumn(Column column) { - super(null, column); - } - - @Override - public String getName() { - return this.column.getSpecifiedName(); - } - - @Override - public String getColumnDefinition() { - return this.column.getColumnDefinition(); - } - - @Override - public String getTable() { - return this.column.getSpecifiedTable(); - } - - @Override - public Boolean getInsertable() { - return this.column.getSpecifiedInsertable(); - } - - @Override - public Boolean getUpdatable() { - return this.column.getSpecifiedUpdatable(); - } - - @Override - public Boolean getNullable() { - return this.column.getSpecifiedNullable(); - } - - @Override - public Boolean getUnique() { - return this.column.getSpecifiedUnique(); - } - - @Override - public Integer getLength() { - return this.column.getSpecifiedLength(); - } - - @Override - public Integer getScale() { - return this.column.getSpecifiedScale(); - } - - @Override - public Integer getPrecision() { - return this.column.getSpecifiedPrecision(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java deleted file mode 100644 index f9d5c52779..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualBasic is an implementation of Basic used when there is - * no tag in the orm.xml and an underlying javaBasicMapping exists. - */ -public class VirtualXmlBasic extends XmlBasic -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaBasicMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - public VirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaBasicMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaBasicMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaBasicMapping.getColumn()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public boolean isLob() { - if (this.isOrmMetadataComplete()) { - return false; - } - return this.javaAttributeMapping.getConverter().getType() == Converter.LOB_CONVERTER; - } - - @Override - public void setLob(boolean newLob) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EnumType getEnumerated() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.ENUMERATED_CONVERTER) { - org.eclipse.jpt.core.context.EnumType javaEnumeratedType = ((EnumeratedConverter) this.javaAttributeMapping.getConverter()).getEnumType(); - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(javaEnumeratedType); - } - return null; - } - - @Override - public void setEnumerated(EnumType newEnumerated) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java deleted file mode 100644 index fea21486c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual column is used to represent the XmlColumn resource object - * within a virtual mapping. A virtual mapping is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual column - * is not used when the mapping is specified in the orm.xml, but the column tag does not exist. - * - * A virtual column delegates to the underlying java column for its state. The metadataComplete - * flag determines whether it will get specified or default information from the java column - * - */ -public class VirtualXmlColumn extends XmlColumn -{ - - protected Column column; - - protected OrmTypeMapping ormTypeMapping; - - - public VirtualXmlColumn(OrmTypeMapping ormTypeMapping, Column column) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.column = column; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getColumnDefinition() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.column.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getInsertable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultInsertable()); - } - return Boolean.valueOf(this.column.isInsertable()); - } - - @Override - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getLength() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultLength()); - } - return Integer.valueOf(this.column.getLength()); - } - - @Override - public void setLength(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.isOrmMetadataComplete()) { - return this.column.getDefaultName(); - } - return this.column.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getNullable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultNullable()); - } - return Boolean.valueOf(this.column.isNullable()); - } - - @Override - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getPrecision() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultPrecision()); - } - return Integer.valueOf(this.column.getPrecision()); - } - - @Override - public void setPrecision(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getScale() { - if (this.isOrmMetadataComplete()) { - return Integer.valueOf(this.column.getDefaultScale()); - } - return Integer.valueOf(this.column.getScale()); - } - - @Override - public void setScale(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (this.isOrmMetadataComplete()) { - return this.column.getDefaultTable(); - } - return this.column.getTable(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUnique() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultUnique()); - } - return Boolean.valueOf(this.column.isUnique()); - } - - @Override - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUpdatable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.column.isDefaultUpdatable()); - } - return Boolean.valueOf(this.column.isUpdatable()); - } - - @Override - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getTableTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java deleted file mode 100644 index 206598370f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbedded is an implementation of Embedded used when there is - * no tag in the orm.xml and an underlying javaEmbeddedMapping exists. - */ -public class VirtualXmlEmbedded extends XmlEmbedded -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaEmbeddedMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.isOrmMetadataComplete()) { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn()); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java deleted file mode 100644 index 4dae7d00e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualEmbeddedId is an implementation of EmbeddedId used when there is - * no tag in the orm.xml and an underlying javaEmbeddedIdMapping exists. - */ -public class VirtualXmlEmbeddedId extends XmlEmbeddedId -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaEmbeddedIdMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaEmbeddedIdMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaEmbeddedIdMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED_ID__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.isOrmMetadataComplete()) { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn()); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java deleted file mode 100644 index 828999cb40..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.resource.orm.GenerationType; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlGeneratedValue extends XmlGeneratedValue -{ - JavaIdMapping javaIdMapping; - - protected boolean metadataComplete; - - - public VirtualXmlGeneratedValue(JavaIdMapping javaIdMapping, boolean metadataComplete) { - super(); - this.javaIdMapping = javaIdMapping; - this.metadataComplete = metadataComplete; - } - - protected JavaGeneratedValue getJavaGeneratedValue() { - return this.javaIdMapping.getGeneratedValue(); - } - - - @Override - public String getGenerator() { - return this.metadataComplete ? null : this.getJavaGeneratedValue().getGenerator(); - } - - @Override - public GenerationType getStrategy() { - return this.metadataComplete ? null : org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.getJavaGeneratedValue().getStrategy()); - } - - @Override - public void setGenerator(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public void setStrategy(GenerationType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getGeneratorTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java deleted file mode 100644 index 00743c702e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualId is an implementation of Id used when there is - * no tag in the orm.xml and an underlying javaIdMapping exists. - */ -public class VirtualXmlId extends XmlId -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaIdMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - protected final VirtualXmlGeneratedValue virtualGeneratedValue; - - protected final VirtualXmlTableGenerator virtualTableGenerator; - - protected final VirtualXmlSequenceGenerator virtualSequenceGenerator; - - - public VirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaIdMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaIdMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaIdMapping.getColumn()); - this.virtualGeneratedValue = new VirtualXmlGeneratedValue(javaIdMapping, this.isOrmMetadataComplete()); - this.virtualTableGenerator = new VirtualXmlTableGenerator(javaIdMapping.getGeneratorContainer(), this.isOrmMetadataComplete()); - this.virtualSequenceGenerator = new VirtualXmlSequenceGenerator(javaIdMapping.getGeneratorContainer(), this.isOrmMetadataComplete()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public XmlGeneratedValue getGeneratedValue() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratedValue() != null) { - return this.virtualGeneratedValue; - } - return null; - } - - @Override - public void setGeneratedValue(XmlGeneratedValue value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlSequenceGenerator getSequenceGenerator() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratorContainer().getSequenceGenerator() != null) { - return this.virtualSequenceGenerator; - } - return null; - } - - @Override - public void setSequenceGenerator(XmlSequenceGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlTableGenerator getTableGenerator() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getGeneratorContainer().getTableGenerator() != null) { - return this.virtualTableGenerator; - } - return null; - } - - @Override - public void setTableGenerator(XmlTableGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public EnumType getEnumerated() { - throw new UnsupportedOperationException("enumerated not supported on id mappings"); //$NON-NLS-1$ - } - - @Override - public void setEnumerated(EnumType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public boolean isLob() { - throw new UnsupportedOperationException("lob not supported on id mappings"); //$NON-NLS-1$ - } - - @Override - public void setLob(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java deleted file mode 100644 index 0e862c7c88..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlJoinColumn extends XmlJoinColumn -{ - protected JoinColumn javaJoinColumn; - - protected boolean metadataComplete; - - public VirtualXmlJoinColumn(JoinColumn javaJoinColumn, boolean metadataComplete) { - super(); - this.javaJoinColumn = javaJoinColumn; - this.metadataComplete = metadataComplete; - } - - @Override - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.javaJoinColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getInsertable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultInsertable()); - } - return Boolean.valueOf(this.javaJoinColumn.isInsertable()); - } - - @Override - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultName(); - } - return this.javaJoinColumn.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getReferencedColumnName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultReferencedColumnName(); - } - return this.javaJoinColumn.getReferencedColumnName(); - } - - @Override - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getNullable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultNullable()); - } - return Boolean.valueOf(this.javaJoinColumn.isNullable()); - } - - @Override - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultTable(); - } - return this.javaJoinColumn.getTable(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUnique() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultUnique()); - } - return Boolean.valueOf(this.javaJoinColumn.isUnique()); - } - - @Override - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUpdatable() { - if (this.metadataComplete) { - return Boolean.valueOf(this.javaJoinColumn.isDefaultUpdatable()); - } - return Boolean.valueOf(this.javaJoinColumn.isUpdatable()); - } - - @Override - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getTableTextRange() { - return null; - } - - @Override - public TextRange getReferencedColumnNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java deleted file mode 100644 index 1e1fee7ca7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlJoinTable - extends XmlJoinTable -{ - protected OrmTypeMapping ormTypeMapping; - - protected JoinTable joinTable; - - - public VirtualXmlJoinTable(OrmTypeMapping ormTypeMapping, JoinTable joinTable) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.joinTable = joinTable; - } - - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getName() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultName(); - } - return this.joinTable.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getCatalog() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultCatalog(); - } - return this.joinTable.getCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - if (this.isOrmMetadataComplete()) { - return this.joinTable.getDefaultSchema(); - } - return this.joinTable.getSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - if (this.joinTable == null || isOrmMetadataComplete()) { - return joinColumns; - } - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - @Override - public EList<XmlJoinColumn> getInverseJoinColumns() { - EList<XmlJoinColumn> inverseJoinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__INVERSE_JOIN_COLUMNS); - if (this.joinTable == null || isOrmMetadataComplete()) { - return inverseJoinColumns; - } - for (JoinColumn joinColumn : CollectionTools.iterable(this.joinTable.specifiedInverseJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - inverseJoinColumns.add(xmlJoinColumn); - } - - return inverseJoinColumns; - } - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_JOIN_TABLE__UNIQUE_CONSTRAINTS); - if (this.joinTable == null || isOrmMetadataComplete()) { - return xmlUniqueConstraints; - } - for (UniqueConstraint uniqueConstraint : CollectionTools.iterable(this.joinTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, isOrmMetadataComplete()); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getCatalogTextRange() { - return null; - } - - @Override - public TextRange getSchemaTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java deleted file mode 100644 index 3364c3cf24..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualManyToMany is an implementation of ManyToMany used when there is - * no tag in the orm.xml and an underlying javaManyToManyMapping exists. - */ -public class VirtualXmlManyToMany - extends XmlManyToMany -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToManyMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - - public VirtualXmlManyToMany( - OrmTypeMapping ormTypeMapping, - JavaManyToManyMapping javaManyToManyMapping) { - - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToManyMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaManyToManyMapping.getCascade()); - this.mapKey = new VirtualMapKey(javaManyToManyMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public CascadeType getCascade() { - if (isOrmMetadataComplete()) { - return null; - } - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - if (this.javaAttributeMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable() != null) { - return new VirtualXmlJoinTable( - this.ormTypeMapping, - this.javaAttributeMapping.getRelationshipReference(). - getJoinTableJoiningStrategy().getJoinTable()); - } - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getFullyQualifiedTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public MapKey getMapKey() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.isNoMapKey()) { - return null; - } - return this.mapKey; - } - - @Override - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getOrderBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getOrderable().getSpecifiedOrderBy(); - } - - @Override - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java deleted file mode 100644 index e14c5aab8e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualManyToOne is an implementation of ManyToOne used when there is - * no tag in the orm.xml and an underlying javaManyToOneMapping exists. - */ -public class VirtualXmlManyToOne - extends XmlManyToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaManyToOneMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - - public VirtualXmlManyToOne( - OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaManyToOneMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToOneMapping); - this.virtualCascadeType = new VirtualCascadeType(javaManyToOneMapping.getCascade()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_MANY_TO_ONE__JOIN_COLUMNS); - if (isOrmMetadataComplete()) { - return joinColumns; - } - for (JoinColumn joinColumn : - CollectionTools.iterable( - this.javaAttributeMapping.getRelationshipReference(). - getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - @Override - public CascadeType getCascade() { - if (isOrmMetadataComplete()) { - return null; - } - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getFullyQualifiedTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java deleted file mode 100644 index 0cc0cd8472..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlNullAttributeMapping extends XmlNullAttributeMapping -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaAttributeMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaAttributeMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - public String getMappingKey() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getPersistentAttribute().getDefaultMappingKey(); - } - return this.javaAttributeMapping.getKey(); - } - - @Override - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - @Override - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java deleted file mode 100644 index 4b5eb5a99d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualOneToMany is an implementation of OneToMany used when there is - * no tag in the orm.xml and an underlying javaOneToManyMapping exists. - */ -public class VirtualXmlOneToMany - extends XmlOneToMany -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToManyMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - public VirtualXmlOneToMany( - OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToManyMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaOneToManyMapping.getCascade()); - this.mapKey = new VirtualMapKey(javaOneToManyMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - @Override - public CascadeType getCascade() { - if (isOrmMetadataComplete()) { - return null; - } - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public Boolean getOrphanRemoval() { - throw new UnsupportedOperationException("operation not supported in JPA 1.0"); //$NON-NLS-1$ - } - - @Override - public void setOrphanRemoval(Boolean newOrphanRemoval) { - throw new UnsupportedOperationException("operation not supported in JPA 1.0"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - if (this.javaAttributeMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable() != null) { - return new VirtualXmlJoinTable( - this.ormTypeMapping, - this.javaAttributeMapping.getRelationshipReference(). - getJoinTableJoiningStrategy().getJoinTable()); - } - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getFullyQualifiedTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference(). - getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public MapKey getMapKey() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.isNoMapKey()) { - return null; - } - return this.mapKey; - } - - @Override - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getOrderBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getOrderable().getSpecifiedOrderBy(); - } - - @Override - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java deleted file mode 100644 index db5947d2e4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.FetchType; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * VirtualOneToOne is an implementation of OneToOne used when there is - * no tag in the orm.xml and an underlying javaOneToOneMapping exists. - */ -public class VirtualXmlOneToOne extends XmlOneToOne -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaOneToOneMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualCascadeType virtualCascadeType; - - - public VirtualXmlOneToOne( - OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaOneToOneMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToOneMapping); - this.virtualCascadeType = new VirtualCascadeType(javaOneToOneMapping.getCascade()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public FetchType getFetch() { - if (this.isOrmMetadataComplete()) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaAttributeMapping.getFetch()); - } - - @Override - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOptional() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaAttributeMapping.isDefaultOptional()); - } - return Boolean.valueOf(this.javaAttributeMapping.isOptional()); - } - - @Override - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__JOIN_COLUMNS); - if (isOrmMetadataComplete()) { - return joinColumns; - } - for (JoinColumn joinColumn : - CollectionTools.iterable( - this.javaAttributeMapping.getRelationshipReference(). - getJoinColumnJoiningStrategy().specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, isOrmMetadataComplete()); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - @Override - public CascadeType getCascade() { - if (isOrmMetadataComplete()) { - return null; - } - return this.virtualCascadeType; - } - - @Override - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getOrphanRemoval() { - throw new UnsupportedOperationException("operation not supported in JPA 1.0"); //$NON-NLS-1$ - } - - @Override - public void setOrphanRemoval(Boolean newOrphanRemoval) { - throw new UnsupportedOperationException("operation not supported in JPA 1.0"); //$NON-NLS-1$ - } - - @Override - public XmlJoinTable getJoinTable() { - return null; - } - - @Override - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTargetEntity() { - if (this.isOrmMetadataComplete()) { - return this.javaAttributeMapping.getDefaultTargetEntity(); - } - return this.javaAttributeMapping.getFullyQualifiedTargetEntity(); - } - - @Override - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getMappedBy() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaAttributeMapping.getRelationshipReference(). - getMappedByJoiningStrategy().getMappedByAttribute(); - } - - @Override - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> joinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__PRIMARY_KEY_JOIN_COLUMNS); - if (!this.isOrmMetadataComplete()) { - for (JavaPrimaryKeyJoinColumn joinColumn : - CollectionTools.iterable( - this.javaAttributeMapping.getRelationshipReference(). - getPrimaryKeyJoinColumnJoiningStrategy().primaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(joinColumn/*, this.metadataComplete*/); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } - - @Override - public TextRange getMappedByTextRange() { - return null; - } - - @Override - public TextRange getTargetEntityTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOrderColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOrderColumn.java deleted file mode 100644 index 371d08a907..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOrderColumn.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0; -import org.eclipse.jpt.core.resource.orm.XmlOrderColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlOrderColumn extends XmlOrderColumn -{ - protected OrderColumn2_0 javaOrderColumn; - - protected OrmTypeMapping ormTypeMapping; - - public VirtualXmlOrderColumn(OrderColumn2_0 javaOrderColumn, OrmTypeMapping ormTypeMapping) { - super(); - this.javaOrderColumn = javaOrderColumn; - this.ormTypeMapping = ormTypeMapping; - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getColumnDefinition() { - if (this.isOrmMetadataComplete()) { - return null; - } - return this.javaOrderColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getInsertable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaOrderColumn.isDefaultInsertable()); - } - return Boolean.valueOf(this.javaOrderColumn.isInsertable()); - } - - @Override - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.isOrmMetadataComplete()) { - return this.javaOrderColumn.getDefaultName(); - } - return this.javaOrderColumn.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - - @Override - public Boolean getNullable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaOrderColumn.isDefaultNullable()); - } - return Boolean.valueOf(this.javaOrderColumn.isNullable()); - } - - @Override - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Boolean getUpdatable() { - if (this.isOrmMetadataComplete()) { - return Boolean.valueOf(this.javaOrderColumn.isDefaultUpdatable()); - } - return Boolean.valueOf(this.javaOrderColumn.isUpdatable()); - } - - @Override - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java deleted file mode 100644 index 34127e1e98..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * A virtual primary key join column is used to represent the XmlPrimaryKeyJoinColumn resource object - * within a virtual secondary table. A virtual secondary table is one which is not specified - * in the orm.xml file, but is implied from the underlying java. Virtual pk join column - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual pk join column delegates to the underlying java pk join column for its state. - */ -public class VirtualXmlPrimaryKeyJoinColumn extends XmlPrimaryKeyJoinColumn -{ - - protected JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn; - - - protected VirtualXmlPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - super(); - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } - - @Override - public String getName() { - return this.javaPrimaryKeyJoinColumn.getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getColumnDefinition() { - return this.javaPrimaryKeyJoinColumn.getColumnDefinition(); - } - - @Override - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getReferencedColumnName() { - return this.javaPrimaryKeyJoinColumn.getReferencedColumnName(); - } - - @Override - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getReferencedColumnNameTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java deleted file mode 100644 index b25ddcb3f6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * A virtual secondary table is used to represent the XmlSecondaryTable resource object. - * A virtual secondary table is one which is not specified in the orm.xml file, - * but is implied from the underlying java. Virtual secondary table - * is not used when the secondary table is specified in the orm.xml. - * - * A virtual secondary table delegates to the underlying java secondary table for its state. - */ -public class VirtualXmlSecondaryTable extends XmlSecondaryTable -{ - - protected JavaSecondaryTable javaSecondaryTable; - - protected VirtualXmlSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - super(); - this.javaSecondaryTable = javaSecondaryTable; - } - - @Override - public String getName() { - return this.javaSecondaryTable.getSpecifiedName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getCatalog() { - return this.javaSecondaryTable.getSpecifiedCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - return this.javaSecondaryTable.getSpecifiedSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //VirtualXmlSecondaryTable is rebuilt everytime, so rebuilding the joinColumns list as well - @Override - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> primaryKeyJoinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE__PRIMARY_KEY_JOIN_COLUMNS); - - for (JavaPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.javaSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(pkJoinColumn); - primaryKeyJoinColumns.add(xmlPkJoinColumn); - } - - return primaryKeyJoinColumns; - } - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_SECONDARY_TABLE__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaSecondaryTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, true); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return null; - } - - @Override - public TextRange getCatalogTextRange() { - return null; - } - - @Override - public TextRange getSchemaTextRange() { - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java deleted file mode 100644 index 06a8ffb50d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlSequenceGenerator extends XmlSequenceGenerator -{ - JavaGeneratorContainer javaGeneratorHolder; - - protected boolean metadataComplete; - - - public VirtualXmlSequenceGenerator(JavaGeneratorContainer javaGeneratorHolder, boolean metadataComplete) { - super(); - this.javaGeneratorHolder = javaGeneratorHolder; - this.metadataComplete = metadataComplete; - } - - protected JavaSequenceGenerator getJavaSequenceGenerator() { - return this.javaGeneratorHolder.getSequenceGenerator(); - } - - @Override - public String getSequenceName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaSequenceGenerator().getSequenceName(); - } - - @Override - public void setSequenceName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaSequenceGenerator().getAllocationSize()); - } - - @Override - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaSequenceGenerator().getInitialValue()); - } - - @Override - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaSequenceGenerator().getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - @Override - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java deleted file mode 100644 index 26121e2f4b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EObjectContainmentEList; -import org.eclipse.jpt.core.context.java.JavaGeneratorContainer; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlTableGenerator extends XmlTableGenerator -{ - JavaGeneratorContainer javaGeneratorHolder; - - protected boolean metadataComplete; - - - public VirtualXmlTableGenerator(JavaGeneratorContainer javaGeneratorHolder, boolean metadataComplete) { - super(); - this.javaGeneratorHolder = javaGeneratorHolder; - this.metadataComplete = metadataComplete; - } - - protected JavaTableGenerator getJavaTableGenerator() { - return this.javaGeneratorHolder.getTableGenerator(); - } - - @Override - public String getCatalog() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getCatalog(); - } - - @Override - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getPkColumnName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getPkColumnName(); - } - - @Override - public void setPkColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getPkColumnValue() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getPkColumnValue(); - } - - @Override - public void setPkColumnValue(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getSchema() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getSchema(); - } - - @Override - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getTable() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getTable(); - } - - @Override - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getValueColumnName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getValueColumnName(); - } - - @Override - public void setValueColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaTableGenerator().getAllocationSize()); - } - - @Override - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return Integer.valueOf(this.getJavaTableGenerator().getInitialValue()); - } - - @Override - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.getJavaTableGenerator().getName(); - } - - @Override - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_TABLE_GENERATOR__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.getJavaTableGenerator().uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - @Override - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - @Override - public boolean isVirtual() { - return true; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java deleted file mode 100644 index e80ebe5273..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualTransient is an implementation of Transient used when there is - * no tag in the orm.xml and an underlying javaTransientMapping exists. - */ -public class VirtualXmlTransient extends XmlTransient -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaTransientMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - public VirtualXmlTransient(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaTransientMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaTransientMapping); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java deleted file mode 100644 index 2be593ccbb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlUniqueConstraint.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.context.orm; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EDataTypeEList; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlUniqueConstraint extends XmlUniqueConstraint -{ - protected UniqueConstraint uniqueConstraint; - - protected boolean metadataComplete; - - public VirtualXmlUniqueConstraint(UniqueConstraint uniqueConstraint, boolean metadataComplete) { - super(); - this.uniqueConstraint = uniqueConstraint; - this.metadataComplete = metadataComplete; - } - - @Override - public EList<String> getColumnNames() { - EList<String> columnNames = new EDataTypeEList<String>(String.class, this, OrmPackage.XML_UNIQUE_CONSTRAINT__COLUMN_NAMES); - - for (String columnName : CollectionTools.iterable(this.uniqueConstraint.columnNames())) { - columnNames.add(columnName); - } - return columnNames; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java deleted file mode 100644 index 14be7a4cbd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.core.internal.context.orm; - -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.EnumType; -import org.eclipse.jpt.core.resource.orm.TemporalType; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; - -/** - * VirtualVersion is an implementation of Version used when there is - * no tag in the orm.xml and an underlying javaVersionMapping exists. - */ -public class VirtualXmlVersion extends XmlVersion -{ - protected OrmTypeMapping ormTypeMapping; - - protected final JavaVersionMapping javaAttributeMapping; - - protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; - - protected final VirtualXmlColumn column; - - public VirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaAttributeMapping = javaVersionMapping; - this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaVersionMapping); - this.column = new VirtualXmlColumn(ormTypeMapping, javaVersionMapping.getColumn()); - } - - protected boolean isOrmMetadataComplete() { - return this.ormTypeMapping.isMetadataComplete(); - } - - @Override - public String getMappingKey() { - return this.virtualXmlAttributeMapping.getMappingKey(); - } - - @Override - public String getName() { - return this.virtualXmlAttributeMapping.getName(); - } - - @Override - public void setName(String newName) { - this.virtualXmlAttributeMapping.setName(newName); - } - - @Override - public TextRange getNameTextRange() { - return this.virtualXmlAttributeMapping.getNameTextRange(); - } - - @Override - public XmlColumn getColumn() { - return this.column; - } - - @Override - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TemporalType getTemporal() { - if (this.isOrmMetadataComplete()) { - return null; - } - if (this.javaAttributeMapping.getConverter().getType() == Converter.TEMPORAL_CONVERTER) { - org.eclipse.jpt.core.context.TemporalType javaTemporalType = ((TemporalConverter) this.javaAttributeMapping.getConverter()).getTemporalType(); - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(javaTemporalType); - } - return null; - } - - @Override - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public EnumType getEnumerated() { - throw new UnsupportedOperationException("enumerated not supported on version mappings"); //$NON-NLS-1$ - } - - @Override - public void setEnumerated(EnumType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - //see eclipselink bug 247078 for info one why I made the interface XmlConvertibleMapping - @Override - public boolean isLob() { - throw new UnsupportedOperationException("lob not supported on version mappings"); //$NON-NLS-1$ - } - - @Override - public void setLob(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); //$NON-NLS-1$ - } - - @Override - public TextRange getEnumeratedTextRange() { - return null; - } - - @Override - public TextRange getLobTextRange() { - return null; - } - - @Override - public TextRange getTemporalTextRange() { - return null; - } - -} |