diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context')
162 files changed, 0 insertions, 32002 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java deleted file mode 100644 index cb7cab0f38..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractJpaContextNode.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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; - -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.AbstractJpaNode; - -public abstract class AbstractJpaContextNode extends AbstractJpaNode - implements JpaContextNode -{ - // **************** constructor ******************************************** - - protected AbstractJpaContextNode(JpaNode parent) { - super(parent); - } - - - // **************** JpaNode impl ******************************************* - - @Override - public JpaContextNode getParent() { - return (JpaContextNode) super.getParent(); - } - - - // **************** JpaContextNode impl ************************************ - - /** - * Overidden in BaseJpaContext, Persistence, PersitsenceXml to throw UnsupportedOperationException - * Overidden in PersistenceUnit to return it. - */ - public PersistenceUnit getPersistenceUnit() { - return getParent().getPersistenceUnit(); - } - - /** - * Overidden in BaseJpaContext to return null - * Overidden in EntityMappings to return it. - */ - public EntityMappings getEntityMappings() { - return getParent().getEntityMappings(); - } - - /** - * Overidden in BaseJpaContext to return null - * Overidden in OrmPersistentType to return it. - */ - public OrmPersistentType getOrmPersistentType() { - return getParent().getOrmPersistentType(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java deleted file mode 100644 index 9151a05981..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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; - -import java.util.Collection; -import java.util.List; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -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.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericRootContextNode extends AbstractJpaContextNode - implements JpaRootContextNode -{ - /* This object has no parent, so it must point to the JPA project */ - protected final JpaProject jpaProject; - - /* Main context object */ - protected PersistenceXml persistenceXml; - - - public GenericRootContextNode(JpaProject jpaProject) { - super(null); - if (jpaProject == null) { - throw new IllegalArgumentException("The JPA project must not be null"); - } - this.jpaProject = jpaProject; - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - PersistenceResource pr = pae.getResource(); - - if (pr.exists()) { - this.persistenceXml = this.buildPersistenceXml(pr); - } - - pae.dispose(); - } - - @Override - protected boolean requiresParent() { - return false; - } - - - // **************** JpaNode impl ******************************************* - - @Override - public JpaProject getJpaProject() { - return this.jpaProject; - } - - @Override - public IResource getResource() { - return getJpaProject().getProject(); - } - - @Override - public JpaContextNode getParent() { - return null; - } - - - // **************** JpaContextNode impl ************************************ - - @Override - public PersistenceUnit getPersistenceUnit() { - // No PersistenceUnit in this context - return null; - } - - @Override - public EntityMappings getEntityMappings() { - // No EntityMappings in this context - return null; - } - - @Override - public OrmPersistentType getOrmPersistentType() { - // No OrmPersistentType in this context - return null; - } - - - // **************** persistence xml **************************************** - - public PersistenceXml getPersistenceXml() { - return this.persistenceXml; - } - - protected void setPersistenceXml(PersistenceXml persistenceXml) { - PersistenceXml old = this.persistenceXml; - this.persistenceXml = persistenceXml; - this.firePropertyChanged(PERSISTENCE_XML_PROPERTY, old, persistenceXml); - } - - public PersistenceXml addPersistenceXml() { - if (this.persistenceXml != null) { - throw new IllegalStateException(); - } - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(this.getJpaProject().getProject()); - PersistenceResource pr = pae.createDefaultResource(); - pae.dispose(); - PersistenceXml px = this.buildPersistenceXml(pr); - this.setPersistenceXml(px); - return px; - } - - public void removePersistenceXml() { - if (this.persistenceXml == null) { - throw new IllegalStateException(); - } - this.persistenceXml.dispose(); - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(getJpaProject().getProject()); - PersistenceResource pr = pae.getResource(); - pae.dispose(); - try { - WorkbenchResourceHelper.deleteResource(pr); - } - catch (CoreException ce) { - JptCorePlugin.log(ce); - } - - if (! pr.exists()) { - setPersistenceXml(null); - } - } - - - // **************** updating *********************************************** - - public void update(IProgressMonitor monitor) { - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - PersistenceResource pr = pae.getResource(); - - if (pr.exists()) { - if (this.persistenceXml != null) { - this.persistenceXml.update(pr); - } - else { - setPersistenceXml(this.buildPersistenceXml(pr)); - } - } - else { - setPersistenceXml(null); - } - - pae.dispose(); - } - - protected PersistenceXml buildPersistenceXml(PersistenceResource persistenceResource) { - return this.getJpaFactory().buildPersistenceXml(this, persistenceResource); - } - - - // **************** Validation ********************************************* - - /* If this is true, it may be assumed that all the requirements are valid - * for further validation. For example, if this is true at the point we - * are validating persistence units, it may be assumed that there is a - * single persistence.xml and that it has valid content down to the - * persistence unit level. */ - private boolean okToContinueValidation = true; - - public void addToMessages(List<IMessage> messages) { - addNoPersistenceXmlMessage(messages); - //TODO - multiple persistence unit message - addOrphanedJavaClassMessages(messages); - - if(okToContinueValidation) { - getPersistenceXml().addToMessages(messages); - } - - } - - protected void addNoPersistenceXmlMessage(List<IMessage> messages) { - if (persistenceXml == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PROJECT_NO_PERSISTENCE_XML, - this) - ); - okToContinueValidation = false; - } - } - - - - - protected void addOrphanedJavaClassMessages(List<IMessage> messages) { - if (getPersistenceXml() == null) { - //handled with other validation - return; - } - if (getPersistenceXml().getPersistence() == null) { - //handled with other validation - return; - } - if (getJpaProject().discoversAnnotatedClasses()) { - return; - } - Collection<String> orphanedClassNames = CollectionTools.collection(getJpaProject().annotatedClassNames()); - if (getPersistenceXml().getPersistence().persistenceUnitsSize() != 1) { - //context model currently only supports 1 persistenceUnit - return; - } - PersistenceUnit persistenceUnit = getPersistenceXml().getPersistence().persistenceUnits().next(); - for (String typeName : CollectionTools.iterable(getJpaProject().annotatedClassNames())) { - for (ClassRef classRef : CollectionTools.iterable(persistenceUnit.specifiedClassRefs())) { - if (classRef.isFor(typeName)) { - orphanedClassNames.remove(typeName); - } - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) { - if (mappingFileRef.getOrmXml() == null || mappingFileRef.getOrmXml().getEntityMappings() == null) { - continue; - } - if (mappingFileRef.getOrmXml().getEntityMappings().getPersistentType(typeName) != null) { - orphanedClassNames.remove(typeName); - } - } - } - - for (String orphanedTypeName : orphanedClassNames) { - JavaResourcePersistentType javaResourcePersistentType = getJpaProject().getJavaPersistentTypeResource(orphanedTypeName); - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT, - new String[] {persistenceUnit.getName()}, - javaResourcePersistentType.getResourceModel().getFile(), - javaResourcePersistentType.getMappingAnnotation().getTextRange(JDTTools.buildASTRoot(javaResourcePersistentType.getJpaCompilationUnit().getCompilationUnit()))) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java deleted file mode 100644 index eadbca2144..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JpaContextNodeAdapterFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.core.context.JpaContextNode; - -public class JpaContextNodeAdapterFactory - implements IAdapterFactory -{ - private static Class[] PROPERTIES = - new Class[] { IResource.class, IFile.class }; - - - public Class[] getAdapterList() { - return PROPERTIES; - } - - public Object getAdapter(Object element, Class key) { - JpaContextNode node; - - if (element instanceof JpaContextNode) { - node = (JpaContextNode) element; - } - else { - return null; - } - - IResource resource = node.getResource(); - - if (key.equals(IResource.class)) { - return resource; - } - else if (key.equals(IFile.class) && resource != null && resource.getType() == IResource.FILE) { - return (IFile) resource; - } - - return null; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java deleted file mode 100644 index c19f5e3e63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/MappingTools.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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; - -import java.util.Iterator; -import java.util.StringTokenizer; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -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.java.JavaPersistentAttribute; - -public class MappingTools -{ - public static boolean targetEntityIsValid(String targetEntity) { - if (targetEntity == null) { - return true; - } - // balance is # of name tokens - # of period tokens seen so far - // initially 0; finally 1; should never drop < 0 or > 1 - int balance = 0; - for (StringTokenizer t = new StringTokenizer(targetEntity, ".", true); t.hasMoreTokens();) { - String s = t.nextToken(); - if (s.indexOf('.') >= 0) { - // this is a delimiter - if (s.length() > 1) { - // too many periods in a row - return false; - } - balance--; - if (balance < 0) { - return false; - } - } else { - // this is an identifier segment - balance++; - } - } - return (balance == 1); - } - - /** - * Default join table name from the JPA spec: - * The concatenated names of the two associated primary - * entity tables, separated by a underscore. - * - * [owning table name]_[target table name] - */ - public static String buildJoinTableDefaultName(RelationshipMapping relationshipMapping) { - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - String owningTableName = relationshipMapping.getTypeMapping().getTableName(); - if (owningTableName == null) { - return null; - } - Entity targetEntity = relationshipMapping.getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String targetTableName = targetEntity.getTableName(); - if (targetTableName == null) { - return null; - } - return owningTableName + "_" + targetTableName; - } - - /** - * return the join column's default name; - * which is typically <attribute name>_<referenced column name> - * but, if we don't have an attribute name (e.g. in a unidirectional - * OneToMany or ManyToMany) is - * <target entity name>_<referenced column name> - */ - // <attribute name>_<referenced column name> - // or - // <target entity name>_<referenced column name> - public static String buildJoinColumnDefaultName(JoinColumn joinColumn) { - if (joinColumn.getOwner().joinColumnsSize() != 1) { - return null; - } - String prefix = joinColumn.getOwner().getAttributeName(); - if (prefix == null) { - prefix = targetEntityName(joinColumn); - } - if (prefix == null) { - return null; - } - // TODO not sure which of these is correct... - // (the spec implies that the referenced column is always the - // primary key column of the target entity) - // String targetColumn = this.targetPrimaryKeyColumnName(); - String targetColumn = joinColumn.getReferencedColumnName(); - if (targetColumn == null) { - return null; - } - return prefix + "_" + targetColumn; - } - - /** - * return the name of the target entity - */ - protected static String targetEntityName(JoinColumn joinColumn) { - Entity targetEntity = joinColumn.getOwner().getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getName(); - } - - public static String buildJoinColumnDefaultReferencedColumnName(JoinColumn joinColumn) { - if (joinColumn.getOwner().joinColumnsSize() != 1) { - return null; - } - return targetPrimaryKeyColumnName(joinColumn); - } - - /** - * return the name of the single primary key column of the target entity - */ - protected static String targetPrimaryKeyColumnName(JoinColumn joinColumn) { - Entity targetEntity = joinColumn.getOwner().getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryKeyColumnName(); - } - - - public static Embeddable getEmbeddableFor(JavaPersistentAttribute persistentAttribute) { - String qualifiedTypeName = persistentAttribute.getResourcePersistentAttribute().getQualifiedTypeName(); - if (qualifiedTypeName == null) { - return null; - } - PersistentType persistentType = persistentAttribute.getPersistenceUnit().getPersistentType(qualifiedTypeName); - if (persistentType != null) { - if (persistentType.getMappingKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - return (Embeddable) persistentType.getMapping(); - } - } - return null; - } - - public static ColumnMapping getColumnMapping(String attributeName, Embeddable embeddable) { - if (attributeName == null || embeddable == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = embeddable.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java deleted file mode 100644 index 80ee5ff187..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributePropertyTester.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class PersistentAttributePropertyTester extends PropertyTester -{ - public static final String IS_MAPPED = "isMapped"; - - public static final String IS_VIRTUAL = "isVirtual"; - - - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - if (IS_MAPPED.equals(property)) { - Boolean expectedIsMapped; - - try { - expectedIsMapped = (Boolean) expectedValue; - } - catch (ClassCastException cce) { - return false; - } - - Boolean actualIsMapped = ((PersistentAttribute) receiver).getMappingKey() != MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - - return actualIsMapped == expectedIsMapped; - } - else if (IS_VIRTUAL.equals(property)) { - Boolean expectedIsVirtual; - - try { - expectedIsVirtual = (Boolean) expectedValue; - } - catch (ClassCastException cce) { - return false; - } - - Boolean actualIsVirtual = false; - if (receiver instanceof OrmPersistentAttribute) { - actualIsVirtual = ((OrmPersistentAttribute) receiver).isVirtual(); - } - - return actualIsVirtual == expectedIsVirtual; - } - - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java deleted file mode 100644 index 24ec2e19f3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMapping.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -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 AbstractJavaAttributeMapping<T extends JavaResourceNode> extends AbstractJavaJpaContextNode - implements JavaAttributeMapping -{ - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - - protected AbstractJavaAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - @SuppressWarnings("unchecked") - protected T getMappingResource() { - if (isDefault()) { - return (T) this.resourcePersistentAttribute.getNullMappingAnnotation(getAnnotationName()); - } - return (T) this.resourcePersistentAttribute.getMappingAnnotation(getAnnotationName()); - } - - public GenericJavaPersistentAttribute getPersistentAttribute() { - return (GenericJavaPersistentAttribute) this.getParent(); - } - - protected JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - /** - * the persistent attribute can tell whether there is a "specified" mapping - * or a "default" one - */ - public boolean isDefault() { - return this.getPersistentAttribute().mappingIsDefault(this); - } - - protected boolean embeddableOwned() { - return this.getTypeMapping().getKey() == MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - protected boolean entityOwned() { - return this.getTypeMapping().getKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public TypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - public String getAttributeName() { - return this.getPersistentAttribute().getName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = null; - T mappingResource = getMappingResource(); - if (mappingResource != null) { - textRange = mappingResource.getTextRange(astRoot); - } - return (textRange != null) ? textRange : this.getPersistentAttribute().getValidationTextRange(astRoot); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.resourcePersistentAttribute = resourcePersistentAttribute; - initialize(getMappingResource()); - } - - protected void initialize(T mappingResource) { - - } - - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.resourcePersistentAttribute = resourcePersistentAttribute; - this.update(getMappingResource()); - } - - protected void update(T mappingResource) { - - } - - - //************ Validation ************************* - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addModifierMessages(messages, astRoot); - addInvalidMappingMessage(messages, astRoot); - } - - protected void addModifierMessages(List<IMessage> messages, CompilationUnit astRoot) { - GenericJavaPersistentAttribute attribute = this.getPersistentAttribute(); - if (attribute.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if ( this.resourcePersistentAttribute.isForField()) { - if (this.resourcePersistentAttribute.isFinal()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, - new String[] {attribute.getName()}, - attribute, attribute.getValidationTextRange(astRoot)) - ); - } - - if (this.resourcePersistentAttribute.isPublic()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, - new String[] {attribute.getName()}, - attribute, attribute.getValidationTextRange(astRoot)) - ); - } - } - } - - protected void addInvalidMappingMessage(List<IMessage> messages, CompilationUnit astRoot) { - if (! getTypeMapping().attributeMappingKeyAllowed(this.getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {this.getPersistentAttribute().getName()}, - this, this.getValidationTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java deleted file mode 100644 index 70a120bbfa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseColumn.java +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.java.JavaBaseColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.BaseColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaBaseColumn<T extends BaseColumnAnnotation> extends AbstractJavaNamedColumn<T> - implements JavaBaseColumn -{ - - protected String specifiedTable; - - protected String defaultTable; - - protected Boolean specifiedUnique; - - protected Boolean specifiedNullable; - - protected Boolean specifiedInsertable; - - protected Boolean specifiedUpdatable; - - protected AbstractJavaBaseColumn(JavaJpaContextNode parent, JavaBaseColumn.Owner owner) { - super(parent, owner); - } - - @Override - protected void initializeFromResource(T column) { - super.initializeFromResource(column); - this.defaultTable = this.defaultTable(); - this.specifiedTable = this.specifiedTable(column); - this.specifiedUnique = this.specifiedUnique(column); - this.specifiedNullable = this.specifiedNullable(column); - this.specifiedInsertable = this.specifiedInsertable(column); - this.specifiedUpdatable = this.specifiedUpdatable(column); - } - - @Override - public JavaBaseColumn.Owner getOwner() { - return (JavaBaseColumn.Owner) super.getOwner(); - } - - //************** IAbstractColumn implementation ******************* - - - 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; - getColumnResource().setTable(newSpecifiedTable); - firePropertyChanged(BaseColumn.SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - 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 getUnique() { - return (this.getSpecifiedUnique() == null) ? this.getDefaultUnique() : this.getSpecifiedUnique(); - } - - public Boolean getDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - this.getColumnResource().setUnique(newSpecifiedUnique); - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedUnique_(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - firePropertyChanged(BaseColumn.SPECIFIED_UNIQUE_PROPERTY, oldSpecifiedUnique, newSpecifiedUnique); - } - - public Boolean getNullable() { - return (this.getSpecifiedNullable() == null) ? this.getDefaultNullable() : this.getSpecifiedNullable(); - } - - public Boolean getDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - this.getColumnResource().setNullable(newSpecifiedNullable); - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedNullable_(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - firePropertyChanged(BaseColumn.SPECIFIED_NULLABLE_PROPERTY, oldSpecifiedNullable, newSpecifiedNullable); - } - - public Boolean getInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.getDefaultInsertable() : this.getSpecifiedInsertable(); - } - - public Boolean getDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - this.getColumnResource().setInsertable(newSpecifiedInsertable); - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedInsertable_(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - firePropertyChanged(BaseColumn.SPECIFIED_INSERTABLE_PROPERTY, oldSpecifiedInsertable, newSpecifiedInsertable); - } - - public Boolean getUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.getDefaultUpdatable() : this.getSpecifiedUpdatable(); - } - - public Boolean getDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - this.getColumnResource().setUpdatable(newSpecifiedUpdatable); - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedUpdatable_(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - firePropertyChanged(BaseColumn.SPECIFIED_UPDATABLE_PROPERTY, oldSpecifiedUpdatable, newSpecifiedUpdatable); - } - - @Override - protected String getTableName() { - return this.getTable(); - } - - public TextRange getTableTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getColumnResource().getTableTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean tableTouches(int pos, CompilationUnit astRoot) { - return getColumnResource().tableTouches(pos, astRoot); - } - - private Iterator<String> candidateTableNames() { - return this.tableIsAllowed() ? this.getOwner().getTypeMapping().associatedTableNamesIncludingInherited() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateTableNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateTableNames(), filter); - } - - private Iterator<String> quotedCandidateTableNames(Filter<String> filter) { - return StringTools.quote(this.candidateTableNames(filter)); - } - - /** - * Return whether the 'table' element is allowed. It is not allowed for - * join columns inside of join tables. - */ - public abstract boolean tableIsAllowed(); - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.tableTouches(pos, astRoot)) { - return this.quotedCandidateTableNames(filter); - } - return null; - } - - @Override - protected void update(T column) { - super.update(column); - this.setDefaultTable(this.defaultTable()); - this.setSpecifiedTable_(this.specifiedTable(column)); - this.setSpecifiedUnique_(this.specifiedUnique(column)); - this.setSpecifiedNullable_(this.specifiedNullable(column)); - this.setSpecifiedInsertable_(this.specifiedInsertable(column)); - this.setSpecifiedUpdatable_(this.specifiedUpdatable(column)); - } - - protected String defaultTable() { - return this.getOwner().getDefaultTableName(); - } - - protected String specifiedTable(BaseColumnAnnotation column) { - return column.getTable(); - } - - protected Boolean specifiedUnique(BaseColumnAnnotation column) { - return column.getUnique(); - } - - protected Boolean specifiedNullable(BaseColumnAnnotation column) { - return column.getNullable(); - } - - protected Boolean specifiedInsertable(BaseColumnAnnotation column) { - return column.getInsertable(); - } - - protected Boolean specifiedUpdatable(BaseColumnAnnotation column) { - return column.getUpdatable(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java deleted file mode 100644 index 64dc6cf3fc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseEmbeddedMapping; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PersistentAttribute; -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.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.resource.java.NullColumn; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -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; - - -public abstract class AbstractJavaBaseEmbeddedMapping<T extends JavaResourceNode> extends AbstractJavaAttributeMapping<T> - implements JavaBaseEmbeddedMapping -{ - protected final List<JavaAttributeOverride> specifiedAttributeOverrides; - - protected final List<JavaAttributeOverride> virtualAttributeOverrides; - - private Embeddable embeddable; - - protected AbstractJavaBaseEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - this.specifiedAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - } - - //****************** JavaAttributeMapping implemenation ******************* - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ATTRIBUTE_OVERRIDE, - JPA.ATTRIBUTE_OVERRIDES); - } - - //****************** AttributeOverride.Owner implemenation ******************* - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, embeddable()); - } - - public boolean isVirtual(BaseOverride override) { - return this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // Add a new attribute override - if (virtual) { - return setAttributeOverrideVirtual((JavaAttributeOverride) override); - } - return setAttributeOverrideSpecified((JavaAttributeOverride) override); - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(JavaAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(getResourcePersistentAttribute(), persistentAttribute.getName()); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - break; - } - } - } - - getResourcePersistentAttribute().removeAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideSpecified(JavaAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) getResourcePersistentAttribute().addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - newAttributeOverride.initializeFromResource(attributeOverrideResource); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - - //****************** BaseEmbeddedMapping implemenation ******************* - - @SuppressWarnings("unchecked") - public ListIterator<JavaAttributeOverride> attributeOverrides() { - return new CompositeListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides(), this.virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<JavaAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<JavaAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected void addSpecifiedAttributeOverride(int index, JavaAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected void addVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public JavaAttributeOverride getAttributeOverrideNamed(String name) { - return (JavaAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - protected BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - protected boolean containsOverride(String name, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - public Embeddable embeddable() { - return this.embeddable; - } - - - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.initializeAttributeOverrides(resourcePersistentAttribute); - this.initializeDefaultAttributeOverrides(resourcePersistentAttribute); - this.embeddable = MappingTools.getEmbeddableFor(getPersistentAttribute()); - } - - protected void initializeAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - attributeOverride.initializeFromResource((AttributeOverrideAnnotation) annotations.next()); - this.specifiedAttributeOverrides.add(attributeOverride); - } - } - - protected void initializeDefaultAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - for (Iterator<String> i = allOverridableAttributeNames(); i.hasNext(); ) { - String attributeName = i.next(); - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(attributeName); - if (attributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(resourcePersistentAttribute, attributeName)); - } - } - } @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.embeddable = MappingTools.getEmbeddableFor(getPersistentAttribute()); - this.updateSpecifiedAttributeOverrides(resourcePersistentAttribute); - this.updateVirtualAttributeOverrides(resourcePersistentAttribute); - - } - protected void updateSpecifiedAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<JavaResourceNode> resourceAttributeOverrides = resourcePersistentAttribute.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while (attributeOverrides.hasNext()) { - JavaAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update((AttributeOverrideAnnotation) resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride((AttributeOverrideAnnotation) resourceAttributeOverrides.next())); - } - } - - protected JavaAttributeOverride buildAttributeOverride(AttributeOverrideAnnotation attributeOverrideResource) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); - attributeOverride.initializeFromResource(attributeOverrideResource); - return attributeOverride; - } - - protected JavaAttributeOverride buildVirtualAttributeOverride(JavaResourcePersistentAttribute resourcePersistentAttribute, String attributeName) { - return buildAttributeOverride(buildVirtualAttributeOverrideResource(resourcePersistentAttribute, attributeName)); - } - - protected VirtualAttributeOverride buildVirtualAttributeOverrideResource(JavaResourcePersistentAttribute resourcePersistentAttribute, String attributeName) { - ColumnMapping columnMapping = (ColumnMapping) this.embeddable().getPersistentType().getAttributeNamed(attributeName).getMapping(); - return new VirtualAttributeOverride(resourcePersistentAttribute, attributeName, columnMapping.getColumn()); - } - - protected void updateVirtualAttributeOverrides(JavaResourcePersistentAttribute resourcePersistentAttribute) { - for (Iterator<String> i = allOverridableAttributeNames(); i.hasNext(); ) { - String attributeName = i.next(); - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(attributeName); - if (attributeOverride == null) { - addVirtualAttributeOverride(buildVirtualAttributeOverride(resourcePersistentAttribute, attributeName)); - } - else if (attributeOverride.isVirtual()) { - attributeOverride.getColumn().update(new NullColumn(resourcePersistentAttribute)); - } - } - - Collection<String> attributeNames = CollectionTools.collection(allOverridableAttributeNames()); - - //remove any default mappings that are not included in the attributeNames collection - for (JavaAttributeOverride attributeOverride : CollectionTools.iterable(virtualAttributeOverrides())) { - if (!attributeNames.contains(attributeOverride.getName()) - || containsSpecifiedAttributeOverride(attributeOverride.getName())) { - removeVirtualAttributeOverride(attributeOverride); - } - } - } - - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<PersistentAttribute, String>(this.allOverridableAttributes()) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - if (this.embeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.embeddable().getPersistentType().attributes()) { - @Override - protected boolean accept(PersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (AttributeOverride override : CollectionTools.iterable(this.attributeOverrides())) { - result = ((JavaAttributeOverride) override).javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //******** Validation ****************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - for (Iterator<JavaAttributeOverride> stream = attributeOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java deleted file mode 100644 index e9acc04916..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaGenerator.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.GeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractJavaGenerator extends AbstractJavaJpaContextNode - implements JavaGenerator -{ - protected String name; - - protected Integer specifiedInitialValue; - - protected Integer specifiedAllocationSize; - - protected GeneratorAnnotation generatorResource; - - protected AbstractJavaGenerator(JavaJpaContextNode parent) { - super(parent); - } - - public void initializeFromResource(GeneratorAnnotation generatorResource) { - this.generatorResource = generatorResource; - this.name = this.name(generatorResource); - this.specifiedInitialValue = this.specifiedInitialValue(generatorResource); - this.specifiedAllocationSize = this.specifiedAllocationSize(generatorResource); - } - - protected GeneratorAnnotation getGeneratorResource() { - return this.generatorResource; - } - - protected String name(GeneratorAnnotation generatorResource) { - return generatorResource.getName(); - } - - protected Integer specifiedInitialValue(GeneratorAnnotation generatorResource) { - return generatorResource.getInitialValue(); - } - - protected Integer specifiedAllocationSize(GeneratorAnnotation generatorResource) { - return generatorResource.getAllocationSize(); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - getGeneratorResource().setName(newName); - firePropertyChanged(Generator.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(Generator.NAME_PROPERTY, oldName, newName); - } - - public Integer getInitialValue() { - return (this.getSpecifiedInitialValue() == null) ? this.getDefaultInitialValue() : this.getSpecifiedInitialValue(); - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - getGeneratorResource().setInitialValue(newSpecifiedInitialValue); - firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - firePropertyChanged(Generator.SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - public Integer getAllocationSize() { - return (this.getSpecifiedAllocationSize() == null) ? this.getDefaultAllocationSize() : this.getSpecifiedAllocationSize(); - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - getGeneratorResource().setAllocationSize(newSpecifiedAllocationSize); - firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - firePropertyChanged(Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - public Integer getDefaultAllocationSize() { - return Generator.DEFAULT_ALLOCATION_SIZE; - } - - public boolean isVirtual() { - return false; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.generatorResource.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.generatorResource.getNameTextRange(astRoot); - } - - protected void update(GeneratorAnnotation generatorResource) { - this.generatorResource = generatorResource; - this.setName_(this.name(generatorResource)); - this.setSpecifiedInitialValue_(this.specifiedInitialValue(generatorResource)); - this.setSpecifiedAllocationSize_(this.specifiedAllocationSize(generatorResource)); - } - - public boolean overrides(Generator generator) { - // java is at the base of the tree - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java deleted file mode 100644 index 34bcc085f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJpaContextNode.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractJavaJpaContextNode extends AbstractJpaContextNode implements JavaJpaContextNode -{ - // ********** constructor ********** - - protected AbstractJavaJpaContextNode(JpaContextNode parent) { - super(parent); - } - - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - if (this.connectionProfileIsActive()) { - Iterator<String> result = this.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - /** - * This method is called if the database is connected, allowing us to - * get candidates from the various database tables etc. - * This method should NOT be cascaded to "child" objects; it should - * only return candidates for the current object. The cascading is - * handled by #javaCompletionProposals(int, Filter, CompilationUnit). - */ - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - return null; - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List, CompilationUnit))} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java deleted file mode 100644 index c755635529..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ /dev/null @@ -1,458 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractJavaMultiRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> implements MultiRelationshipMapping -{ - - protected String mappedBy; - - protected String orderBy; - - protected boolean isNoOrdering; - - protected boolean isPkOrdering; - - protected boolean isCustomOrdering; - - //TODO should this be null if this is the non-owning side of the relationship?? - protected final JavaJoinTable joinTable; - - protected String mapKey; - - protected AbstractJavaMultiRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.joinTable = getJpaFactory().buildJavaJoinTable(this); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.setMappedByOnResourceModel(newMappedBy); - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected abstract void setMappedByOnResourceModel(String mappedBy); - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - if (newOrderBy == null) { - if (getOrderByResource() != null) { - removeOrderByResource(); - } - } - else { - if (getOrderByResource() == null) { - addOrderByResource(); - } - getOrderByResource().setValue(newOrderBy); - } - firePropertyChanged(MultiRelationshipMapping.ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected void setOrderBy_(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - firePropertyChanged(MultiRelationshipMapping.ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected OrderByAnnotation getOrderByResource() { - return (OrderByAnnotation) getResourcePersistentAttribute().getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected OrderByAnnotation addOrderByResource() { - return (OrderByAnnotation) getResourcePersistentAttribute().addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - protected void removeOrderByResource() { - getResourcePersistentAttribute().removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - } - - public boolean isNoOrdering() { - return this.isNoOrdering; - } - - public void setNoOrdering(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - if (newNoOrdering) { - if (getOrderByResource() != null) { - removeOrderByResource(); - } - } - else { - //?? - } - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - protected void setNoOrdering_(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - public boolean isPkOrdering() { - return this.isPkOrdering; - } - - public void setPkOrdering(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - if (newPkOrdering) { - if (getOrderByResource() == null) { - addOrderByResource(); - } - else { - getOrderByResource().setValue(null); - } - } - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - protected void setPkOrdering_(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - public boolean isCustomOrdering() { - return this.isCustomOrdering; - } - - public void setCustomOrdering(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - if (newCustomOrdering) { - setOrderBy(""); - } - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - protected void setCustomOrdering_(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - public FetchType getDefaultFetch() { - return MultiRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - public JavaJoinTable getJoinTable() { - return this.joinTable; - } - - public boolean isJoinTableSpecified() { - return getJoinTable().isSpecified(); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - if (oldMapKey != newMapKey) { - if (this.getMapKeyResource(getResourcePersistentAttribute()) != null) { - if (newMapKey != null) { - this.getMapKeyResource(getResourcePersistentAttribute()).setName(newMapKey); - } - else { - getResourcePersistentAttribute().removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - } - else if (newMapKey != null) { - getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getMapKeyResource(getResourcePersistentAttribute()).setName(newMapKey); - } - } - firePropertyChanged(MultiRelationshipMapping.MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected void setMapKey_(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - firePropertyChanged(MultiRelationshipMapping.MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - -//TODO default orderBy - this wasn't supported in 1.0 either -// public void refreshDefaults(DefaultsContext defaultsContext) { -// super.refreshDefaults(defaultsContext); -// // if (isOrderByPk()) { -// // refreshDefaultOrderBy(defaultsContext); -// // } -// } -// -// //primary key ordering when just the @OrderBy annotation is present -// protected void refreshDefaultOrderBy(DefaultsContext defaultsContext) { -// IEntity targetEntity = getResolvedTargetEntity(); -// if (targetEntity != null) { -// setOrderBy(targetEntity.primaryKeyAttributeName() + " ASC"); -// } -// } - - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!resourcePersistentAttribute.typeIsContainer()) { - return null; - } - return resourcePersistentAttribute.getQualifiedReferenceEntityElementTypeName(); - } - - protected abstract boolean mappedByTouches(int pos, CompilationUnit astRoot); - - protected boolean mapKeyNameTouches(int pos, CompilationUnit astRoot) { - if (getMapKeyResource(getResourcePersistentAttribute()) != null) { - return getMapKeyResource(getResourcePersistentAttribute()).nameTouches(pos, astRoot); - } - return false; - } - - protected MapKeyAnnotation getMapKeyResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (MapKeyAnnotation) resourcePersistentAttribute.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - - protected Iterator<String> candidateMapKeyNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMapKeyNames(), filter); - } - - protected Iterator<String> quotedCandidateMapKeyNames(Filter<String> filter) { - return StringTools.quote(this.candidateMapKeyNames(filter)); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getJoinTable().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.mappedByTouches(pos, astRoot)) { - return this.quotedCandidateMappedByAttributeNames(filter); - } - if (this.mapKeyNameTouches(pos, astRoot)) { - return this.quotedCandidateMapKeyNames(filter); - } - return null; - } - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - MapKeyAnnotation mapKey = this.getMapKeyResource(resourcePersistentAttribute); - if (mapKey != null) { - this.mapKey = mapKey.getName(); - } - this.initializeOrderBy(this.getOrderByResource()); - this.joinTable.initializeFromResource(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.mappedBy = this.mappedBy(relationshipMapping); - } - - protected void initializeOrderBy(OrderByAnnotation orderBy) { - if (orderBy != null) { - this.orderBy = orderBy.getValue(); - if (orderBy.getValue() == null) { - this.isPkOrdering = true; - } - else { - this.isCustomOrdering = true; - } - } - else { - this.isNoOrdering = true; - } - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updateMapKey(resourcePersistentAttribute); - this.updateOrderBy(this.getOrderByResource()); - this.joinTable.update(resourcePersistentAttribute); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setMappedBy_(this.mappedBy(relationshipMapping)); - } - - protected void updateMapKey(JavaResourcePersistentAttribute resourcePersistentAttribute) { - MapKeyAnnotation mapKey = this.getMapKeyResource(resourcePersistentAttribute); - if (mapKey != null) { - setMapKey_(mapKey.getName()); - } - else { - setMapKey_(null); - } - } - - protected void updateOrderBy(OrderByAnnotation orderBy) { - if (orderBy != null) { - setOrderBy_(orderBy.getValue()); - if (orderBy.getValue() == null) { - setPkOrdering_(true); - setCustomOrdering_(false); - setNoOrdering_(false); - } - else { - setPkOrdering_(false); - setCustomOrdering_(true); - setNoOrdering_(false); - } - } - else { - setOrderBy_(null); - setPkOrdering_(false); - setCustomOrdering_(false); - setNoOrdering_(true); - } - } - protected abstract String mappedBy(T relationshipMapping); - - //******** Validation *********************************** - - public abstract TextRange getMappedByTextRange(CompilationUnit astRoot); - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (entityOwned() && (this.isJoinTableSpecified() || isRelationshipOwner())) { - getJoinTable().addToMessages(messages, astRoot); - } - if (this.getMappedBy() != null) { - addMappedByMessages(messages, astRoot); - } - } - - protected void addMappedByMessages(List<IMessage> messages, CompilationUnit astRoot) { - String mappedBy = this.getMappedBy(); - - if (this.isJoinTableSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE, - this.getJoinTable(), - this.getJoinTable().getValidationTextRange(astRoot)) - ); - - } - - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, - this.getMappedByTextRange(astRoot)) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, - this.getMappedByTextRange(astRoot)) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - this.getMappedByTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java deleted file mode 100644 index 4e80363cbc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaNamedColumn.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.resource.java.NamedColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public abstract class AbstractJavaNamedColumn<T extends NamedColumnAnnotation> extends AbstractJavaJpaContextNode - implements JavaNamedColumn -{ - - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractJavaNamedColumn(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - // ******************* initialization from java resource model ******************** - - protected void initializeFromResource(T column) { - this.specifiedName = column.getName(); - this.defaultName = this.defaultName(); - this.columnDefinition = column.getColumnDefinition(); - } - - - protected abstract T getColumnResource(); - - - //************** INamedColumn implementation ***************** - 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; - getColumnResource().setName(newSpecifiedName); - firePropertyChanged(NamedColumn.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(NamedColumn.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(NamedColumn.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getColumnDefinition() { - return this.columnDefinition; - } - - public void setColumnDefinition(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - getColumnResource().setColumnDefinition(newColumnDefinition); - firePropertyChanged(NamedColumn.COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setColumnDefinition_(String newColumnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = newColumnDefinition; - firePropertyChanged(NamedColumn.COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, newColumnDefinition); - } - - public Owner getOwner() { - return this.owner; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getColumnResource().getNameTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.getColumnResource().nameTouches(pos, astRoot); - } - - public Column getDbColumn() { - Table table = this.getDbTable(); - return (table == null) ? null : table.columnNamed(this.getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.getTableName()); - } - - /** - * Return the name of the column's table. - */ - protected abstract String getTableName(); - - public boolean isResolved() { - return this.getDbColumn() != null; - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - return null; - } - - private Iterator<String> candidateNames() { - Table dbTable = this.getDbTable(); - return (dbTable != null) ? dbTable.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - - // ******************* update from java resource model ******************** - - protected void update(T column) { - this.setSpecifiedName_(column.getName()); - this.setDefaultName(this.defaultName()); - this.setColumnDefinition_(column.getColumnDefinition()); - } - - /** - * Return the default column name. - */ - protected String defaultName() { - return this.getOwner().getDefaultColumnName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java deleted file mode 100644 index b9c3824427..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaOverride.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.OverrideAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public abstract class AbstractJavaOverride extends AbstractJavaJpaContextNode implements BaseOverride -{ - - protected String name; - - protected final Owner owner; - - protected OverrideAnnotation overrideResource; - - public AbstractJavaOverride(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - protected void initializeFromResource(OverrideAnnotation overrideResource) { - this.overrideResource = overrideResource; - this.name = this.name(overrideResource); - } - - protected OverrideAnnotation getOverrideResource() { - return this.overrideResource; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.overrideResource.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void update(OverrideAnnotation overrideResource) { - this.overrideResource = overrideResource; - this.setName_(this.name(overrideResource)); - } - - protected String name(OverrideAnnotation overrideResource) { - return overrideResource.getName(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public BaseOverride setVirtual(boolean virtual) { - return getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - protected abstract Iterator<String> candidateNames(); - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - return null; - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return this.overrideResource.nameTouches(pos, astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.overrideResource.getTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java deleted file mode 100644 index bbe49882d2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaQuery.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryHint; -import org.eclipse.jpt.core.resource.java.QueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - - -public abstract class AbstractJavaQuery extends AbstractJavaJpaContextNode - implements JavaQuery -{ - protected String name; - - protected String query; - - protected final List<JavaQueryHint> hints; - - protected QueryAnnotation queryAnnotation; - - protected AbstractJavaQuery(JavaJpaContextNode parent) { - super(parent); - this.hints = new ArrayList<JavaQueryHint>(); - } - - protected QueryAnnotation getQueryResource() { - return this.queryAnnotation; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryAnnotation.setName(newName); - firePropertyChanged(Query.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = 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.queryAnnotation.setQuery(newQuery); - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - protected void setQuery_(String newQuery) { - String oldQuery = this.query; - this.query = newQuery; - firePropertyChanged(Query.QUERY_PROPERTY, oldQuery, newQuery); - } - - public ListIterator<JavaQueryHint> hints() { - return new CloneListIterator<JavaQueryHint>(this.hints); - } - - public int hintsSize() { - return this.hints.size(); - } - - public JavaQueryHint addHint(int index) { - JavaQueryHint hint = getJpaFactory().buildJavaQueryHint(this); - this.hints.add(index, hint); - this.getQueryResource().addHint(index); - this.fireItemAdded(Query.HINTS_LIST, index, hint); - return hint; - } - - protected void addHint(int index, JavaQueryHint hint) { - addItemToList(index, hint, this.hints, Query.HINTS_LIST); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - JavaQueryHint removedHint = this.hints.remove(index); - this.getQueryResource().removeHint(index); - fireItemRemoved(Query.HINTS_LIST, index, removedHint); - } - - protected void removeHint_(JavaQueryHint hint) { - removeItemFromList(hint, this.hints, Query.HINTS_LIST); - } - - public void moveHint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.hints, targetIndex, sourceIndex); - this.getQueryResource().moveHint(targetIndex, sourceIndex); - fireItemMoved(Query.HINTS_LIST, targetIndex, sourceIndex); - } - - protected void initializeFromResource(QueryAnnotation queryAnnotation) { - this.queryAnnotation = queryAnnotation; - this.name = queryAnnotation.getName(); - this.query = queryAnnotation.getQuery(); - this.initializeQueryHints(queryAnnotation); - } - - protected void update(QueryAnnotation queryAnnotation) { - this.queryAnnotation = queryAnnotation; - this.setName_(queryAnnotation.getName()); - this.setQuery_(queryAnnotation.getQuery()); - this.updateQueryHints(queryAnnotation); - } - - protected void initializeQueryHints(QueryAnnotation queryResource) { - ListIterator<QueryHintAnnotation> annotations = queryResource.hints(); - - while(annotations.hasNext()) { - this.hints.add(createQueryHint(annotations.next())); - } - } - - protected void updateQueryHints(QueryAnnotation queryResource) { - ListIterator<JavaQueryHint> hints = hints(); - ListIterator<QueryHintAnnotation> resourceHints = queryResource.hints(); - - while (hints.hasNext()) { - JavaQueryHint hint = hints.next(); - if (resourceHints.hasNext()) { - hint.update(resourceHints.next()); - } - else { - removeHint_(hint); - } - } - - while (resourceHints.hasNext()) { - addHint(hintsSize(), createQueryHint(resourceHints.next())); - } - } - - protected JavaQueryHint createQueryHint(QueryHintAnnotation hintResource) { - JavaQueryHint queryHint = getJpaFactory().buildJavaQueryHint(this); - queryHint.initializeFromResource(hintResource); - return queryHint; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.queryAnnotation.getTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.queryAnnotation.getNameTextRange(astRoot); - } - - public boolean overrides(Query query) { - // java is at the base of the tree - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java deleted file mode 100644 index 9be2b4b4b7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaRelationshipMapping.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaRelationshipMapping<T extends RelationshipMappingAnnotation> extends AbstractJavaAttributeMapping<T> - implements JavaRelationshipMapping -{ - - protected String specifiedTargetEntity; - - protected String defaultTargetEntity; - - protected Entity resolvedTargetEntity; - - protected final JavaCascade cascade; - - protected FetchType specifiedFetch; - - protected AbstractJavaRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.cascade = new JavaCascade(this); - } - - public String getTargetEntity() { - return (this.getSpecifiedTargetEntity() == null) ? getDefaultTargetEntity() : this.getSpecifiedTargetEntity(); - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - this.getMappingResource().setTargetEntity(newSpecifiedTargetEntity); - firePropertyChanged(RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - protected void setSpecifiedTargetEntity_(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - firePropertyChanged(RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String newDefaultTargetEntity) { - String oldDefaultTargetEntity = this.defaultTargetEntity; - this.defaultTargetEntity = newDefaultTargetEntity; - firePropertyChanged(RelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY, oldDefaultTargetEntity, newDefaultTargetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity newResolvedTargetEntity) { - Entity oldResolvedTargetEntity = this.resolvedTargetEntity; - this.resolvedTargetEntity = newResolvedTargetEntity; - firePropertyChanged(RelationshipMapping.RESOLVED_TARGET_ENTITY_PROPERTY, oldResolvedTargetEntity, newResolvedTargetEntity); - } - - public JavaCascade getCascade() { - return this.cascade; - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getMappingResource().setFetch(FetchType.toJavaResourceModel(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); - } - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.defaultTargetEntity = this.defaultTargetEntity(resourcePersistentAttribute); - super.initializeFromResource(resourcePersistentAttribute); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - this.setDefaultTargetEntity(this.defaultTargetEntity(resourcePersistentAttribute)); - super.update(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - this.specifiedFetch = this.fetch(relationshipMapping); - this.cascade.initialize(relationshipMapping); - this.specifiedTargetEntity = this.specifiedTargetEntity(relationshipMapping); - this.resolvedTargetEntity = this.resolveTargetEntity(relationshipMapping); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedFetch_(this.fetch(relationshipMapping)); - this.cascade.update(relationshipMapping); - this.setSpecifiedTargetEntity_(this.specifiedTargetEntity(relationshipMapping)); - this.setResolvedTargetEntity(this.resolveTargetEntity(relationshipMapping)); - } - - protected FetchType fetch(T relationshipMapping) { - return FetchType.fromJavaResourceModel(relationshipMapping.getFetch()); - } - - protected String specifiedTargetEntity(T relationshipMapping) { - return relationshipMapping.getTargetEntity(); - } - - protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute); - - protected Entity resolveTargetEntity(T relationshipMapping) { - String qualifiedTargetEntity = getDefaultTargetEntity(); - if (getSpecifiedTargetEntity() != null) { - qualifiedTargetEntity = relationshipMapping.getFullyQualifiedTargetEntity(); - } - if (qualifiedTargetEntity == null) { - return null; - } - PersistentType persistentType = getPersistenceUnit().getPersistentType(qualifiedTargetEntity); - if (persistentType != null && persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; - } - - public Entity getEntity() { - if (getTypeMapping() instanceof Entity) { - return (Entity) getTypeMapping(); - } - return null; - } - - public Iterator<String> allTargetEntityAttributeNames() { - Entity targetEntity = this.getResolvedTargetEntity(); - return (targetEntity == null) ? EmptyIterator.<String> instance() : targetEntity.getPersistentType().allAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return this.allTargetEntityAttributeNames(); - } - - protected Iterator<String> candidateMappedByAttributeNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateMappedByAttributeNames(), filter); - } - - protected Iterator<String> quotedCandidateMappedByAttributeNames(Filter<String> filter) { - return StringTools.quote(this.candidateMappedByAttributeNames(filter)); - } - - - // ********** static methods ********** - - public boolean targetEntityIsValid(String targetEntity) { - return MappingTools.targetEntityIsValid(targetEntity); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java deleted file mode 100644 index 1f09a2c559..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java +++ /dev/null @@ -1,433 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SingleRelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaSingleRelationshipMapping; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -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; - - -public abstract class AbstractJavaSingleRelationshipMapping<T extends RelationshipMappingAnnotation> - extends AbstractJavaRelationshipMapping<T> implements JavaSingleRelationshipMapping -{ - - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected JavaJoinColumn defaultJoinColumn; - - protected Boolean specifiedOptional; - - protected AbstractJavaSingleRelationshipMapping(JavaPersistentAttribute parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - public FetchType getDefaultFetch() { - return SingleRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - //***************** ISingleRelationshipMapping implementation ***************** - public ListIterator<JavaJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn newJoinColumn) { - JavaJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JavaJoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - 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; - } - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = (JoinColumnAnnotation) getResourcePersistentAttribute().addAnnotation(index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumn.initializeFromResource(joinColumnResource); - this.fireItemAdded(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //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 = buildJoinColumn(new NullJoinColumn(getResourcePersistentAttribute())); - } - getResourcePersistentAttribute().removeAnnotation(index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - fireItemRemoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, JoinColumnsAnnotation.ANNOTATION_NAME); - fireItemMoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public Boolean getOptional() { - return getSpecifiedOptional() == null ? getDefaultOptional() : getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - setOptionalOnResourceModel(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected abstract void setOptionalOnResourceModel(Boolean newOptional); - - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.initializeSpecifiedJoinColumns(resourcePersistentAttribute); - this.initializeDefaultJoinColumn(resourcePersistentAttribute); - } - - @Override - protected void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.specifiedOptional = this.specifiedOptional(relationshipMapping); - } - - protected void initializeSpecifiedJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(buildJoinColumn((JoinColumnAnnotation) annotations.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(resourcePersistentAttribute)); - } - - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updateSpecifiedJoinColumns(resourcePersistentAttribute); - this.updateDefaultJoinColumn(resourcePersistentAttribute); - } - - @Override - protected void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedOptional_(this.specifiedOptional(relationshipMapping)); - } - - protected abstract Boolean specifiedOptional(T relationshipMapping); - - - protected void updateSpecifiedJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JavaResourceNode> resourceJoinColumns = resourcePersistentAttribute.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update((JoinColumnAnnotation) resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn((JoinColumnAnnotation) resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(new NullJoinColumn(resourcePersistentAttribute))); - } - else { - this.defaultJoinColumn.update(new NullJoinColumn(resourcePersistentAttribute)); - } - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initializeFromResource(joinColumnResource); - return joinColumn; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - /** - * eliminate any "container" types - */ - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute resourcePersistentAttribute) { - if (resourcePersistentAttribute.typeIsContainer()) { - return null; - } - return resourcePersistentAttribute.getQualifiedReferenceEntityTypeName(); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - //************* Validation ********************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (addJoinColumnMessages()) { - addJoinColumnMessages(messages, astRoot); - } - } - - //bug 192287 - do not want joinColumn validation errors on the non-owning side - //of a bidirectional relationship. This is a low risk fix for RC3, but a better - //solution would be to not have the default joinColumns on the non-owning side. - //This would fix another bug that we show default joinColumns in this situation. - protected boolean addJoinColumnMessages() { - return (entityOwned() && isRelationshipOwner()); - } - - protected void addJoinColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - - for (Iterator<JavaJoinColumn> stream = this.joinColumns(); stream.hasNext();) { - JavaJoinColumn joinColumn = stream.next(); - String table = joinColumn.getTable(); - boolean doContinue = joinColumn.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, joinColumn.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - - - public class JoinColumnOwner implements JavaJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping().getTableName(); - } - - public Entity getTargetEntity() { - return AbstractJavaSingleRelationshipMapping.this.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return AbstractJavaSingleRelationshipMapping.this.getPersistentAttribute().getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return AbstractJavaSingleRelationshipMapping.this; - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return AbstractJavaSingleRelationshipMapping.this.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractJavaSingleRelationshipMapping.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return AbstractJavaSingleRelationshipMapping.this.getValidationTextRange(astRoot); - } - - public int joinColumnsSize() { - return AbstractJavaSingleRelationshipMapping.this.joinColumnsSize(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java deleted file mode 100644 index 6ce7369b2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTable.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public abstract class AbstractJavaTable extends AbstractJavaJpaContextNode implements UniqueConstraint.Owner -{ - - protected String specifiedName; - protected String defaultName; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected final List<JavaUniqueConstraint> uniqueConstraints; - - - protected AbstractJavaTable(JavaJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<JavaUniqueConstraint>(); - } - - @Override - public JavaJpaContextNode getParent() { - return (JavaJpaContextNode) super.getParent(); - } - - /** - * Return the java table resource, do not return null if the java annotation does not exist. - * Use a null resource object instead of null. - */ - protected abstract TableAnnotation getTableResource(); - - /** - * Return the fully qualified annotation name of the java table resource - */ - protected abstract String getAnnotationName(); - - 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; - getTableResource().setName(newSpecifiedName); - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getTableResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getTableResource().setSchema(newSpecifiedSchema); - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - - // ********** unique constraints ********** - - public ListIterator<JavaUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<JavaUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public JavaUniqueConstraint addUniqueConstraint(int index) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - this.uniqueConstraints.add(index, uniqueConstraint); - UniqueConstraintAnnotation uniqueConstraintAnnotation = this.getTableResource().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - fireItemAdded(Table.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - JavaUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getTableResource().removeUniqueConstraint(index); - fireItemRemoved(Table.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getTableResource().moveUniqueConstraint(targetIndex, sourceIndex); - fireItemMoved(Table.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - - // ********** Table implementation ********** - - public TextRange getNameTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getNameTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return getTableResource().nameTouches(pos, astRoot); - } - - public TextRange getSchemaTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getSchemaTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public boolean schemaTouches(int pos, CompilationUnit astRoot) { - return getTableResource().schemaTouches(pos, astRoot); - } - - public TextRange getCatalogTextRange(CompilationUnit astRoot) { - return getTableResource().getCatalogTextRange(astRoot); - } - - public boolean catalogTouches(int pos, CompilationUnit astRoot) { - return getTableResource().catalogTouches(pos, astRoot); - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Table.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(Table.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(Table.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - - - protected void initializeFromResource(TableAnnotation table) { - this.defaultName = this.defaultName(); - this.defaultSchema = this.defaultSchema(); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedName = table.getName(); - this.specifiedSchema = table.getSchema(); - this.specifiedCatalog = table.getCatalog(); - this.initializeUniqueConstraints(table); - } - - protected void initializeUniqueConstraints(TableAnnotation table) { - for (UniqueConstraintAnnotation uniqueConstraintAnnotation : CollectionTools.iterable(table.uniqueConstraints())) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraintAnnotation)); - } - } - - protected void update(TableAnnotation table) { - this.setSpecifiedName_(table.getName()); - this.setSpecifiedSchema_(table.getSchema()); - this.setSpecifiedCatalog_(table.getCatalog()); - this.setDefaultName(this.defaultName()); - this.setDefaultSchema(this.defaultSchema()); - this.setDefaultCatalog(this.defaultCatalog()); - this.updateUniqueConstraints(table); - } - - protected abstract String defaultName(); - - protected String defaultSchema() { - if (getEntityMappings() != null) { - return getEntityMappings().getSchema(); - } - return getPersistenceUnit().getDefaultSchema(); - } - - protected String defaultCatalog() { - if (getEntityMappings() != null) { - return getEntityMappings().getCatalog(); - } - return getPersistenceUnit().getDefaultCatalog(); - } - - protected void updateUniqueConstraints(TableAnnotation table) { - ListIterator<JavaUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<UniqueConstraintAnnotation> resourceUniqueConstraints = table.uniqueConstraints(); - - while (uniqueConstraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getTableResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public org.eclipse.jpt.db.Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.tableNamed(this.getName()); - } - - public Schema getDbSchema() { - return this.getDatabase().schemaNamed(this.getSchema()); - } - - public boolean hasResolvedSchema() { - return this.getDbSchema() != null; - } - - public boolean isResolved() { - return this.getDbTable() != null; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaUniqueConstraint constraint : CollectionTools.iterable(this.uniqueConstraints())) { - result = constraint.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - /** - * called if the database is connected - * name, schema, catalog - */ - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.nameTouches(pos, astRoot)) { - return this.quotedCandidateNames(filter); - } - if (this.schemaTouches(pos, astRoot)) { - return this.quotedCandidateSchemas(filter); - } - if (this.catalogTouches(pos, astRoot)) { - return this.quotedCandidateCatalogs(filter); - } - return null; - } - - private Iterator<String> candidateNames() { - Schema dbSchema = this.getDbSchema(); - return (dbSchema != null) ? dbSchema.tableNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateNames(), filter); - } - - private Iterator<String> quotedCandidateNames(Filter<String> filter) { - return StringTools.quote(this.candidateNames(filter)); - } - - private Iterator<String> candidateSchemas() { - return this.getDatabase().schemaNames(); - } - - private Iterator<String> candidateSchemas(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateSchemas(), filter); - } - - private Iterator<String> quotedCandidateSchemas(Filter<String> filter) { - return StringTools.quote(this.candidateSchemas(filter)); - } - - private Iterator<String> candidateCatalogs() { - return this.getDatabase().catalogNames(); - } - - private Iterator<String> candidateCatalogs(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateCatalogs(), filter); - } - - private Iterator<String> quotedCandidateCatalogs(Filter<String> filter) { - return StringTools.quote(this.candidateCatalogs(filter)); - } - - public String getQualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getQualifiedName()); - } - - @Override - public String displayString() { - return getQualifiedName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java deleted file mode 100644 index 5ae078e889..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractJavaTypeMapping extends AbstractJavaJpaContextNode - implements JavaTypeMapping -{ - protected JavaResourcePersistentType javaResourcePersistentType; - - - protected AbstractJavaTypeMapping(JavaPersistentType parent) { - super(parent); - } - - protected JavaResourceNode getMappingResource() { - return this.javaResourcePersistentType.getMappingAnnotation(getAnnotationName()); - } - - //***************** ITypeMapping implementation ***************** - - public JavaPersistentType getPersistentType() { - return (JavaPersistentType) getParent(); - } - - public String getTableName() { - return null; - } - - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return null; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<JavaPersistentAttribute> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<JavaPersistentAttribute> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAssociationNames() { - return EmptyIterator.instance(); - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - //******************** updatating ********************* - public void initializeFromResource(JavaResourcePersistentType javaResourcePersistentType) { - this.javaResourcePersistentType = javaResourcePersistentType; - } - - public void update(JavaResourcePersistentType javaResourcePersistentType) { - this.javaResourcePersistentType = javaResourcePersistentType; - } - - //******************** validation ********************* - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.getMappingResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getPersistentType().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java deleted file mode 100644 index 3e7299264b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAssociationOverride.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaAssociationOverride extends AbstractJavaOverride - implements JavaAssociationOverride -{ - - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected final List<JavaJoinColumn> defaultJoinColumns; - - - public GenericJavaAssociationOverride(JavaJpaContextNode parent, AssociationOverride.Owner owner) { - super(parent, owner); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - this.defaultJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - @Override - public JavaAssociationOverride setVirtual(boolean virtual) { - return (JavaAssociationOverride) super.setVirtual(virtual); - } - - @Override - protected AssociationOverrideAnnotation getOverrideResource() { - return (AssociationOverrideAnnotation) super.getOverrideResource(); - } - - @Override - public AssociationOverride.Owner getOwner() { - return (AssociationOverride.Owner) super.getOwner(); - } - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public ListIterator<JavaJoinColumn> defaultJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.defaultJoinColumns); - } - - public int defaultJoinColumnsSize() { - return this.defaultJoinColumns.size(); - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = getOverrideResource().addJoinColumn(index); - joinColumn.initializeFromResource(joinColumnResource); - this.fireItemAdded(AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - getOverrideResource().removeJoinColumn(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedJoinColumn); - } - - protected void removeSpecifiedJoinColumn(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - getOverrideResource().moveJoinColumn(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - - @Override - protected Iterator<String> candidateNames() { - return this.getOwner().getTypeMapping().allOverridableAssociationNames(); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - public void initializeFromResource(AssociationOverrideAnnotation associationOverride) { - super.initializeFromResource(associationOverride); - this.name = associationOverride.getName(); - initializeSpecifiedJoinColumns(associationOverride); - } - - protected void initializeSpecifiedJoinColumns(AssociationOverrideAnnotation associationOverride) { - ListIterator<JoinColumnAnnotation> annotations = associationOverride.joinColumns(); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(createJoinColumn(annotations.next())); - } - } - - public void update(AssociationOverrideAnnotation associationOverride) { - super.update(associationOverride); - updateSpecifiedJoinColumns(associationOverride); - } - - protected void updateSpecifiedJoinColumns(AssociationOverrideAnnotation associationOverride) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = associationOverride.joinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), createJoinColumn(resourceJoinColumns.next())); - } - } - - - protected JavaJoinColumn createJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initializeFromResource(joinColumnResource); - return joinColumn; - } - - - //******************** validation ******************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addJoinColumnMessages(messages, astRoot); - } - - protected void addJoinColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - for (JavaJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - String table = joinColumn.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getOwner().getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange(astRoot)) - ); - } - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange(astRoot)) - ); - } - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - } - public class JoinColumnOwner implements JavaJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return GenericJavaAssociationOverride.this.owner.getTypeMapping().getTableName(); - } - - public String getDefaultColumnName() { - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaAssociationOverride.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaAssociationOverride.this.getOwner().getRelationshipMapping(GenericJavaAssociationOverride.this.getName()); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - - public TypeMapping getTypeMapping() { - return GenericJavaAssociationOverride.this.owner.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaAssociationOverride.this.defaultJoinColumns.contains(joinColumn); - } - - public int joinColumnsSize() { - return GenericJavaAssociationOverride.this.joinColumnsSize(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java deleted file mode 100644 index ac9fc986da..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaAttributeOverride.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaAttributeOverride extends AbstractJavaOverride - implements JavaAttributeOverride -{ - - protected final JavaColumn column; - - - public GenericJavaAttributeOverride(JavaJpaContextNode parent, AttributeOverride.Owner owner) { - super(parent, owner); - this.column = getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public JavaAttributeOverride setVirtual(boolean virtual) { - return (JavaAttributeOverride) super.setVirtual(virtual); - } - - @Override - protected AttributeOverrideAnnotation getOverrideResource() { - return (AttributeOverrideAnnotation) super.getOverrideResource(); - } - - @Override - public AttributeOverride.Owner getOwner() { - return (AttributeOverride.Owner) super.getOwner(); - } - - public ColumnAnnotation getColumnResource() { - return this.getOverrideResource().getNonNullColumn(); - } - - public String getDefaultColumnName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - return columnMapping.getColumn().getName(); - } - - public String getDefaultTableName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - String tableName = columnMapping.getColumn().getSpecifiedTable(); - if (tableName != null) { - return tableName; - } - return getOwner().getTypeMapping().getTableName(); - } - - protected ColumnMapping getColumnMapping() { - return getOwner().getColumnMapping(getName()); - } - - //************* IColumn.Owner implementation ************** - public TypeMapping getTypeMapping() { - return this.getOwner().getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return this.getTypeMapping().getDbTable(tableName); - } - - //************* IAttributeOverride implementation ************** - - public JavaColumn getColumn() { - return this.column; - } - - //************* JavaOverride implementation ************** - - @Override - protected Iterator<String> candidateNames() { - return this.getOwner().getTypeMapping().allOverridableAttributeNames(); - } - - //************* java resource model -> java context model ************** - public void initializeFromResource(AttributeOverrideAnnotation attributeOverrideResource) { - super.initializeFromResource(attributeOverrideResource); - this.column.initializeFromResource(this.getColumnResource()); - } - - public void update(AttributeOverrideAnnotation attributeOverrideResource) { - super.update(attributeOverrideResource); - this.column.update(this.getColumnResource()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - - //******************** validation ********************** - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - String table = getColumn().getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, getColumn().getName()}, - getColumn(), - getColumn().getTableTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, getColumn().getName()}, - getColumn(), - getColumn().getTableTextRange(astRoot)) - ); - } - doContinue = false; - } - - if (doContinue && ! getColumn().isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), getColumn().getName()}, - getColumn(), - getColumn().getNameTextRange(astRoot)) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {getColumn().getName()}, - getColumn(), - getColumn().getNameTextRange(astRoot)) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java deleted file mode 100644 index 0c90960e2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaBasicMapping.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaBasicMapping extends AbstractJavaAttributeMapping<BasicAnnotation> implements JavaBasicMapping -{ - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected EnumType specifiedEnumerated; - - protected final JavaColumn column; - - protected boolean lob; - - protected TemporalType temporal; - - public GenericJavaBasicMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.column.initializeFromResource(this.getColumnResource()); - this.specifiedEnumerated = this.specifiedEnumerated(this.getEnumeratedResource()); - this.lob = this.lob(resourcePersistentAttribute); - this.temporal = this.temporal(this.getTemporalResource()); - } - - @Override - protected void initialize(BasicAnnotation basicResource) { - this.specifiedFetch = this.specifiedFetchType(basicResource); - this.specifiedOptional = this.specifiedOptional(basicResource); - } - - protected EnumeratedAnnotation getEnumeratedResource() { - return (EnumeratedAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - } - - protected TemporalAnnotation getTemporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.LOB, - JPA.TEMPORAL, - JPA.ENUMERATED); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IBasicMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - 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.getMappingResource().setFetch(FetchType.toJavaResourceModel(newSpecifiedFetch)); - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); - } - - public Boolean getOptional() { - return (this.getSpecifiedOptional() == null) ? this.getDefaultOptional() : this.getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.getMappingResource().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 boolean isLob() { - return this.lob; - } - - public void setLob(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - if (newLob) { - if (lobResource(getResourcePersistentAttribute()) == null) { - getResourcePersistentAttribute().addAnnotation(LobAnnotation.ANNOTATION_NAME); - } - } - else { - if (lobResource(getResourcePersistentAttribute()) != null) { - getResourcePersistentAttribute().removeAnnotation(LobAnnotation.ANNOTATION_NAME); - } - } - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getTemporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public EnumType getEnumerated() { - return (this.getSpecifiedEnumerated() == null) ? this.getDefaultEnumerated() : this.getSpecifiedEnumerated(); - } - - public EnumType getDefaultEnumerated() { - return BasicMapping.DEFAULT_ENUMERATED; - } - - public EnumType getSpecifiedEnumerated() { - return this.specifiedEnumerated; - } - - public void setSpecifiedEnumerated(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - this.getEnumeratedResource().setValue(EnumType.toJavaResourceModel(newSpecifiedEnumerated)); - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedEnumerated_(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setSpecifiedEnumerated_(this.specifiedEnumerated(this.getEnumeratedResource())); - this.setLob(this.lob(resourcePersistentAttribute)); - this.setTemporal_(this.temporal(this.getTemporalResource())); - } - - @Override - protected void update(BasicAnnotation basicResource) { - this.setSpecifiedFetch_(this.specifiedFetchType(basicResource)); - this.setSpecifiedOptional_(this.specifiedOptional(basicResource)); - } - - protected FetchType specifiedFetchType(BasicAnnotation basic) { - return FetchType.fromJavaResourceModel(basic.getFetch()); - } - - protected Boolean specifiedOptional(BasicAnnotation basic) { - return basic.getOptional(); - } - - protected EnumType specifiedEnumerated(EnumeratedAnnotation enumerated) { - return EnumType.fromJavaResourceModel(enumerated.getValue()); - } - - protected boolean lob(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return lobResource(resourcePersistentAttribute) != null; - } - - protected LobAnnotation lobResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (LobAnnotation) resourcePersistentAttribute.getAnnotation(LobAnnotation.ANNOTATION_NAME); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - // ************** Validation ************************************* - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages ,astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java deleted file mode 100644 index 031a7717bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaColumn.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaColumn extends AbstractJavaBaseColumn<ColumnAnnotation> implements JavaColumn -{ - - protected Integer specifiedLength; - - protected Integer specifiedPrecision; - - protected Integer specifiedScale; - - public GenericJavaColumn(JavaJpaContextNode parent, JavaColumn.Owner owner) { - super(parent, owner); - } - - @Override - public void initializeFromResource(ColumnAnnotation column) { - super.initializeFromResource(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedPrecision = this.specifiedPrecision(column); - this.specifiedScale = this.specifiedScale(column); - } - - @Override - public JavaColumn.Owner getOwner() { - return (JavaColumn.Owner) super.getOwner(); - } - - @Override - protected ColumnAnnotation getColumnResource() { - return this.getOwner().getColumnResource(); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getColumnResource().setLength(newSpecifiedLength); - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - public Integer getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision(); - } - - public Integer getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - getColumnResource().setPrecision(newSpecifiedPrecision); - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - protected void setSpecifiedPrecision_(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - public Integer getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale(); - } - - public Integer getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - getColumnResource().setScale(newSpecifiedScale); - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - protected void setSpecifiedScale_(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - @Override - public boolean tableIsAllowed() { - return true; - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(ColumnAnnotation column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedPrecision_(this.specifiedPrecision(column)); - this.setSpecifiedScale_(this.specifiedScale(column)); - } - - protected Integer specifiedLength(ColumnAnnotation column) { - return column.getLength(); - } - - protected Integer specifiedPrecision(ColumnAnnotation column) { - return column.getPrecision(); - } - - protected Integer specifiedScale(ColumnAnnotation column) { - return column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java deleted file mode 100644 index e983bd18f5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaDiscriminatorColumn.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaDiscriminatorColumn extends AbstractJavaNamedColumn<DiscriminatorColumnAnnotation> - implements JavaDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected Integer specifiedLength; - - protected JavaResourcePersistentMember persistenceResource; - - public GenericJavaDiscriminatorColumn(JavaEntity parent, JavaNamedColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFromResource(JavaResourcePersistentMember persistentResource) { - this.persistenceResource = persistentResource; - this.initializeFromResource(this.getColumnResource()); - } - - @Override - public void initializeFromResource(DiscriminatorColumnAnnotation column) { - super.initializeFromResource(column); - this.specifiedDiscriminatorType = this.discriminatorType(column); - this.specifiedLength = this.length(column); - } - - protected JavaEntity getJavaEntity() { - return (JavaEntity) super.getParent(); - } - - @Override - protected DiscriminatorColumnAnnotation getColumnResource() { - return (DiscriminatorColumnAnnotation) this.persistenceResource.getNonNullAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - getColumnResource().setDiscriminatorType(DiscriminatorType.toJavaResourceModel(newSpecifiedDiscriminatorType)); - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedDiscriminatorType_(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return DiscriminatorColumn.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - getColumnResource().setLength(newSpecifiedLength); - firePropertyChanged(DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - @Override - protected String getTableName() { - return getJavaEntity().getTableName(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - - // ********** java annotations -> persistence model ********** - - public void update(JavaResourcePersistentMember persistentResource) { - this.persistenceResource = persistentResource; - this.update(this.getColumnResource()); - } - - @Override - public void update(DiscriminatorColumnAnnotation discriminatorColumn) { - super.update(discriminatorColumn); - this.setSpecifiedDiscriminatorType_(this.discriminatorType(discriminatorColumn)); - this.setSpecifiedLength_(this.length(discriminatorColumn)); - } - - protected DiscriminatorType discriminatorType(DiscriminatorColumnAnnotation discriminatorColumn) { - return DiscriminatorType.fromJavaResourceModel(discriminatorColumn.getDiscriminatorType()); - } - - protected Integer length(DiscriminatorColumnAnnotation discriminatorColumn) { - return discriminatorColumn.getLength(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java deleted file mode 100644 index 21d2bcab97..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddable.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericJavaEmbeddable extends AbstractJavaTypeMapping implements JavaEmbeddable -{ - public GenericJavaEmbeddable(JavaPersistentType parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - public boolean isMapped() { - return true; - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return attributeMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || attributeMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java deleted file mode 100644 index 4ae4b5648f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedIdMapping.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - - -public class GenericJavaEmbeddedIdMapping extends AbstractJavaBaseEmbeddedMapping<EmbeddedIdAnnotation> - implements JavaEmbeddedIdMapping -{ - - public GenericJavaEmbeddedIdMapping(JavaPersistentAttribute parent) { - super(parent); - } - - //****************** IJavaAttributeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedIdAnnotation.ANNOTATION_NAME; - } - - @Override - public boolean isIdMapping() { - return true; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java deleted file mode 100644 index b0fe9c987b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEmbeddedMapping.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; - - -public class GenericJavaEmbeddedMapping extends AbstractJavaBaseEmbeddedMapping<EmbeddedAnnotation> implements JavaEmbeddedMapping -{ - public GenericJavaEmbeddedMapping(JavaPersistentAttribute parent) { - super(parent); - } - - //****************** IJavaAttributeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java deleted file mode 100644 index 9faaa496ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaEntity.java +++ /dev/null @@ -1,1963 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -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.Generator; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -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.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.RelationshipMapping; -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.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaDiscriminatorColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaNamedColumn; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.internal.resource.java.NullAssociationOverride; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumns; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -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.SingleElementIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaEntity extends AbstractJavaTypeMapping implements JavaEntity -{ - protected EntityAnnotation entityResource; - - protected String specifiedName; - - protected String defaultName; - - protected final JavaTable table; - - protected final List<JavaSecondaryTable> specifiedSecondaryTables; - - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected InheritanceType specifiedInheritanceStrategy; - - protected InheritanceType defaultInheritanceStrategy; - - protected String defaultDiscriminatorValue; - - protected boolean discriminatorValueAllowed; - - protected String specifiedDiscriminatorValue; - - protected final JavaDiscriminatorColumn discriminatorColumn; - - protected JavaSequenceGenerator sequenceGenerator; - - protected JavaTableGenerator tableGenerator; - - protected final List<JavaAttributeOverride> specifiedAttributeOverrides; - - protected final List<JavaAttributeOverride> virtualAttributeOverrides; - - protected final List<JavaAssociationOverride> specifiedAssociationOverrides; - - protected final List<JavaAssociationOverride> virtualAssociationOverrides; - - protected final List<JavaNamedQuery> namedQueries; - - protected final List<JavaNamedNativeQuery> namedNativeQueries; - - protected String idClass; - - - public GenericJavaEntity(JavaPersistentType parent) { - super(parent); - this.table = getJpaFactory().buildJavaTable(this); - this.discriminatorColumn = buildJavaDiscriminatorColumn(); - this.specifiedSecondaryTables = new ArrayList<JavaSecondaryTable>(); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - this.specifiedAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<JavaAttributeOverride>(); - this.namedQueries = new ArrayList<JavaNamedQuery>(); - this.namedNativeQueries = new ArrayList<JavaNamedNativeQuery>(); - this.specifiedAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<JavaAssociationOverride>(); - } - - protected JavaBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected JavaDiscriminatorColumn buildJavaDiscriminatorColumn() { - return getJpaFactory().buildJavaDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected JavaNamedColumn.Owner buildDiscriminatorColumnOwner() { - return new JavaNamedColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericJavaEntity.this.getDbTable(tableName); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public String getDefaultColumnName() { - return DiscriminatorColumn.DEFAULT_NAME; - } - }; - } - - @Override - public void initializeFromResource(JavaResourcePersistentType resourcePersistentType) { - super.initializeFromResource(resourcePersistentType); - this.entityResource = (EntityAnnotation) resourcePersistentType.getMappingAnnotation(EntityAnnotation.ANNOTATION_NAME); - - this.specifiedName = this.specifiedName(this.entityResource); - this.defaultName = this.defaultName(resourcePersistentType); - this.defaultInheritanceStrategy = this.defaultInheritanceStrategy(); - this.specifiedInheritanceStrategy = this.specifiedInheritanceStrategy(getInheritanceResource()); - this.specifiedDiscriminatorValue = this.getDiscriminatorValueResource().getValue(); - this.defaultDiscriminatorValue = this.javaDefaultDiscriminatorValue(); - this.discriminatorValueAllowed = this.discriminatorValueIsAllowed(resourcePersistentType); - this.discriminatorColumn.initializeFromResource(resourcePersistentType); - this.table.initializeFromResource(resourcePersistentType); - this.initializeSecondaryTables(resourcePersistentType); - this.initializeTableGenerator(resourcePersistentType); - this.initializeSequenceGenerator(resourcePersistentType); - this.initializePrimaryKeyJoinColumns(resourcePersistentType); - this.initializeDefaultPrimaryKeyJoinColumn(resourcePersistentType); - this.initializeSpecifiedAttributeOverrides(resourcePersistentType); - this.initializeVirtualAttributeOverrides(resourcePersistentType); - this.initializeSpecifiedAssociationOverrides(resourcePersistentType); - this.initializeDefaultAssociationOverrides(resourcePersistentType); - this.initializeNamedQueries(resourcePersistentType); - this.initializeNamedNativeQueries(resourcePersistentType); - this.initializeIdClass(resourcePersistentType); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializeSecondaryTables(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedSecondaryTables.add(buildSecondaryTable((SecondaryTableAnnotation) annotations.next())); - } - } - - protected void initializeTableGenerator(JavaResourcePersistentType resourcePersistentType) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentType); - if (tableGeneratorResource != null) { - this.tableGenerator = buildTableGenerator(tableGeneratorResource); - } - } - - protected void initializeSequenceGenerator(JavaResourcePersistentType resourcePersistentType) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentType); - if (sequenceGeneratorResource != null) { - this.sequenceGenerator = buildSequenceGenerator(sequenceGeneratorResource); - } - } - - protected void initializePrimaryKeyJoinColumns(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn(JavaResourcePersistentType persistentTypeResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(persistentTypeResource)); - } - - protected void initializeSpecifiedAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaResourceNode> annotations = persistentTypeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride((AttributeOverrideAnnotation) annotations.next())); - } - } - - protected void initializeVirtualAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentTypeResource, persistentAttribute)); - } - } - } - - protected void initializeSpecifiedAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.specifiedAssociationOverrides.add(buildAssociationOverride((AssociationOverrideAnnotation) annotations.next())); - } - } - - protected void initializeDefaultAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - for (Iterator<String> i = allOverridableAssociationNames(); i.hasNext(); ) { - String associationName = i.next(); - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(associationName); - if (associationOverride == null) { - this.virtualAssociationOverrides.add(buildAssociationOverride(new NullAssociationOverride(resourcePersistentType, associationName))); - } - } - } - - protected void initializeNamedQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.namedQueries.add(buildNamedQuery((NamedQueryAnnotation) annotations.next())); - } - } - - protected void initializeNamedNativeQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaResourceNode> annotations = resourcePersistentType.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.namedNativeQueries.add(buildNamedNativeQuery((NamedNativeQueryAnnotation) annotations.next())); - } - } - - //query for the inheritance resource every time on setters. - //call one setter and the inheritanceResource could change. - //You could call more than one setter before this object has received any notification - //from the java resource model - protected InheritanceAnnotation getInheritanceResource() { - return (InheritanceAnnotation) this.javaResourcePersistentType.getNonNullAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - } - - protected DiscriminatorValueAnnotation getDiscriminatorValueResource() { - return (DiscriminatorValueAnnotation) this.javaResourcePersistentType.getNonNullAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - } - - protected void initializeIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClassResource = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClassResource != null) { - this.idClass = idClassResource.getValue(); - } - } - - //****************** ITypeMapping implemenation ******************* - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public boolean isMapped() { - return true; - } - - @Override - public String getTableName() { - return getTable().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return getTable().getDbTable(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - for (Iterator<Table> stream = this.associatedTablesIncludingInherited(); stream.hasNext();) { - org.eclipse.jpt.db.Table dbTable = stream.next().getDbTable(); - if (dbTable != null && dbTable.matchesShortJavaClassName(tableName)) { - return dbTable; - } - } - return null; - } - - @Override - public Schema getDbSchema() { - return getTable().getDbSchema(); - } - - - //****************** IJavaTypeMapping implemenation ******************* - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.TABLE, - JPA.SECONDARY_TABLE, - JPA.SECONDARY_TABLES, - JPA.PRIMARY_KEY_JOIN_COLUMN, - JPA.PRIMARY_KEY_JOIN_COLUMNS, - JPA.ID_CLASS, - JPA.INHERITANCE, - JPA.DISCRIMINATOR_VALUE, - JPA.DISCRIMINATOR_COLUMN, - JPA.SEQUENCE_GENERATOR, - JPA.TABLE_GENERATOR, - JPA.NAMED_QUERY, - JPA.NAMED_QUERIES, - JPA.NAMED_NATIVE_QUERY, - JPA.NAMED_NATIVE_QUERIES, - JPA.SQL_RESULT_SET_MAPPING, - JPA.EXCLUDE_DEFAULT_LISTENERS, - JPA.EXCLUDE_SUPERCLASS_LISTENERS, - JPA.ENTITY_LISTENERS, - JPA.PRE_PERSIST, - JPA.POST_PERSIST, - JPA.PRE_REMOVE, - JPA.POST_REMOVE, - JPA.PRE_UPDATE, - JPA.POST_UPDATE, - JPA.POST_LOAD, - JPA.ATTRIBUTE_OVERRIDE, - JPA.ATTRIBUTE_OVERRIDES, - JPA.ASSOCIATION_OVERRIDE, - JPA.ASSOCIATION_OVERRIDES); - } - - //****************** IEntity implemenation ******************* - - public String getName() { - return (this.getSpecifiedName() == null) ? this.getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - this.entityResource.setName(newSpecifiedName); - firePropertyChanged(Entity.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Entity.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected/*private-protected*/ void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Entity.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public JavaTable getTable() { - return this.table; - } - - public ListIterator<JavaSecondaryTable> specifiedSecondaryTables() { - return new CloneListIterator<JavaSecondaryTable>(this.specifiedSecondaryTables); - } - - public int specifiedSecondaryTablesSize() { - return this.specifiedSecondaryTables.size(); - } - - public JavaSecondaryTable addSpecifiedSecondaryTable(int index) { - JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); - this.specifiedSecondaryTables.add(index, secondaryTable); - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) this.javaResourcePersistentType.addAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - secondaryTable.initializeFromResource(secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - protected void addSpecifiedSecondaryTable(int index, JavaSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - JavaSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); - } - - protected void removeSpecifiedSecondaryTable_(JavaSecondaryTable secondaryTable) { - removeItemFromList(secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, SecondaryTablesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaSecondaryTable> secondaryTables() { - return specifiedSecondaryTables(); - } - - public int secondaryTablesSize() { - return specifiedSecondaryTablesSize(); - } - - 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; - getInheritanceResource().setStrategy(InheritanceType.toJavaResourceModel(newInheritanceType)); - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedInheritanceStrategy_(InheritanceType newInheritanceType) { - InheritanceType oldInheritanceType = this.specifiedInheritanceStrategy; - this.specifiedInheritanceStrategy = newInheritanceType; - firePropertyChanged(SPECIFIED_INHERITANCE_STRATEGY_PROPERTY, oldInheritanceType, newInheritanceType); - } - - public JavaDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - 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; - getDiscriminatorValueResource().setValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setSpecifiedDiscriminatorValue_(String newSpecifiedDiscriminatorValue) { - String oldSpecifiedDiscriminatorValue = this.specifiedDiscriminatorValue; - this.specifiedDiscriminatorValue = newSpecifiedDiscriminatorValue; - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean isDiscriminatorValueAllowed() { - return this.discriminatorValueAllowed; - } - - protected void setDiscriminatorValueAllowed(boolean newDiscriminatorValueAllowed) { - boolean oldDiscriminatorValueAllowed = this.discriminatorValueAllowed; - this.discriminatorValueAllowed = newDiscriminatorValueAllowed; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_ALLOWED_PROPERTY, oldDiscriminatorValueAllowed, newDiscriminatorValueAllowed); - } - - public JavaTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = (TableGeneratorAnnotation) this.javaResourcePersistentType.addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - this.tableGenerator.initializeFromResource(tableGeneratorResource); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); - } - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.javaResourcePersistentType.removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public JavaTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(JavaTableGenerator newTableGenerator) { - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - public JavaSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = (SequenceGeneratorAnnotation) this.javaResourcePersistentType.addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - this.sequenceGenerator.initializeFromResource(sequenceGeneratorResource); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); - } - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.javaResourcePersistentType.removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator,null); - } - - public JavaSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(JavaSequenceGenerator newSequenceGenerator) { - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaGenerator> generators() { - return new CompositeIterator<JavaGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public JavaPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn newPkJoinColumn) { - JavaPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - protected ListIterator<JavaPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<JavaPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public JavaPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != 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.defaultPrimaryKeyJoinColumn = null; - } - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) this.javaResourcePersistentType.addAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - primaryKeyJoinColumn.initializeFromResource(pkJoinColumnResource); - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(primaryKeyJoinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn 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. - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.javaResourcePersistentType)); - } - this.javaResourcePersistentType.removeAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - this.javaResourcePersistentType.move(targetIndex, sourceIndex, PrimaryKeyJoinColumns.ANNOTATION_NAME); - moveItemInList(targetIndex, sourceIndex, this.specifiedPrimaryKeyJoinColumns, Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - @SuppressWarnings("unchecked") - public ListIterator<JavaAttributeOverride> attributeOverrides() { - return new CompositeListIterator<JavaAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<JavaAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<JavaAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<JavaAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected JavaAttributeOverride addSpecifiedAttributeOverride(int index) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - this.specifiedAttributeOverrides.add(index, attributeOverride); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverride.initializeFromResource(attributeOverrideResource); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - return attributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(boolean virtual, JavaAttributeOverride attributeOverride) { - // Add a new attribute override - if (virtual) { - return setAttributeOverrideVirtual(attributeOverride); - } - return setAttributeOverrideSpecified(attributeOverride); - } - - protected JavaAttributeOverride setAttributeOverrideVirtual(JavaAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(this.javaResourcePersistentType, persistentAttribute); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - break; - } - } - } - - this.javaResourcePersistentType.removeAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected JavaAttributeOverride setAttributeOverrideSpecified(JavaAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - newAttributeOverride.initializeFromResource(attributeOverrideResource); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - protected AttributeOverride.Owner createAttributeOverrideOwner() { - return new AttributeOverrideOwner(); - } - - protected void addSpecifiedAttributeOverride(int index, JavaAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected void addVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(JavaAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public JavaAttributeOverride getAttributeOverrideNamed(String name) { - return (JavaAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - public JavaAssociationOverride getAssociationOverrideNamed(String name) { - return (JavaAssociationOverride) getOverrideNamed(name, associationOverrides()); - } - - public boolean containsAssociationOverride(String name) { - return containsOverride(name, associationOverrides()); - } - - public boolean containsSpecifiedAssociationOverride(String name) { - return containsOverride(name, specifiedAssociationOverrides()); - } - - public boolean containsDefaultAssociationOverride(String name) { - return containsOverride(name, virtualAssociationOverrides()); - } - - private BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(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, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - - @SuppressWarnings("unchecked") - public ListIterator<JavaAssociationOverride> associationOverrides() { - return new CompositeListIterator<JavaAssociationOverride>(specifiedAssociationOverrides(), virtualAssociationOverrides()); - } - - public int associationOverridesSize() { - return this.specifiedAssociationOverridesSize() + this.virtualAssociationOverridesSize(); - } - - public ListIterator<JavaAssociationOverride> virtualAssociationOverrides() { - return new CloneListIterator<JavaAssociationOverride>(this.virtualAssociationOverrides); - } - - public int virtualAssociationOverridesSize() { - return this.virtualAssociationOverrides.size(); - } - - public ListIterator<JavaAssociationOverride> specifiedAssociationOverrides() { - return new CloneListIterator<JavaAssociationOverride>(this.specifiedAssociationOverrides); - } - - public int specifiedAssociationOverridesSize() { - return this.specifiedAssociationOverrides.size(); - } - - public JavaAssociationOverride addSpecifiedAssociationOverride(int index) { - JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - this.specifiedAssociationOverrides.add(index, associationOverride); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverride.initializeFromResource(associationOverrideResource); - this.fireItemAdded(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - return associationOverride; - } - - protected AssociationOverride.Owner createAssociationOverrideOwner() { - return new AssociationOverrideOwner(); - } - - protected void addSpecifiedAssociationOverride(int index, JavaAssociationOverride associationOverride) { - addItemToList(index, associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeSpecifiedAssociationOverride_(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemMoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - protected JavaAssociationOverride setAssociationOverrideVirtual(boolean virtual, JavaAssociationOverride associationOverride) { - // Add a new attribute override - if (virtual) { - return setAssociationOverrideVirtual(associationOverride); - } - return setAssociationOverrideSpecified(associationOverride); - } - - protected JavaAssociationOverride setAssociationOverrideVirtual(JavaAssociationOverride associationOverride) { - int index = this.specifiedAssociationOverrides.indexOf(associationOverride); - this.specifiedAssociationOverrides.remove(index); - String associationOverrideName = associationOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - JavaAssociationOverride virtualAssociationOverride = null; - if (associationOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAssociations())) { - if (persistentAttribute.getName().equals(associationOverrideName)) { - //store the virtualAssociationOverride so we can fire change notification later - virtualAssociationOverride = buildAssociationOverride(new NullAssociationOverride(this.javaResourcePersistentType, associationOverrideName)); - this.virtualAssociationOverrides.add(virtualAssociationOverride); - break; - } - } - } - - this.javaResourcePersistentType.removeAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - fireItemRemoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); - - if (virtualAssociationOverride != null) { - fireItemAdded(Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualAssociationOverridesSize() - 1, virtualAssociationOverride); - } - return virtualAssociationOverride; - } - - protected JavaAssociationOverride setAssociationOverrideSpecified(JavaAssociationOverride oldAssociationOverride) { - int index = specifiedAssociationOverridesSize(); - JavaAssociationOverride newAssociationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - this.specifiedAssociationOverrides.add(index, newAssociationOverride); - - AssociationOverrideAnnotation attributeOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - newAssociationOverride.initializeFromResource(attributeOverrideResource); - - int virtualIndex = this.virtualAssociationOverrides.indexOf(oldAssociationOverride); - this.virtualAssociationOverrides.remove(virtualIndex); - - newAssociationOverride.setName(oldAssociationOverride.getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST, virtualIndex, oldAssociationOverride); - this.fireItemAdded(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, newAssociationOverride); - - return newAssociationOverride; - } - - protected void addVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - addItemToList(associationOverride, this.virtualAssociationOverrides, Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeVirtualAssociationOverride(JavaAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.virtualAssociationOverrides, Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST); - } - - public ListIterator<JavaNamedQuery> namedQueries() { - return new CloneListIterator<JavaNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public JavaNamedQuery addNamedQuery(int index) { - JavaNamedQuery namedQuery = getJpaFactory().buildJavaNamedQuery(this); - this.namedQueries.add(index, namedQuery); - NamedQueryAnnotation namedQueryAnnotation = (NamedQueryAnnotation) this.javaResourcePersistentType.addAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQuery.initializeFromResource(namedQueryAnnotation); - fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, JavaNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - JavaNamedQuery removedNamedQuery = this.namedQueries.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, removedNamedQuery); - } - - protected void removeNamedQuery_(JavaNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, NamedQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(QueryHolder.NAMED_QUERIES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<JavaNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public JavaNamedNativeQuery addNamedNativeQuery(int index) { - JavaNamedNativeQuery namedNativeQuery = getJpaFactory().buildJavaNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - NamedNativeQueryAnnotation namedNativeQueryAnnotation = (NamedNativeQueryAnnotation) this.javaResourcePersistentType.addAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedNativeQuery.initializeFromResource(namedNativeQueryAnnotation); - fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, JavaNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - JavaNamedNativeQuery removedNamedNativeQuery = this.namedNativeQueries.remove(index); - this.javaResourcePersistentType.removeAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, removedNamedNativeQuery); - } - - protected void removeNamedNativeQuery_(JavaNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.javaResourcePersistentType.move(targetIndex, sourceIndex, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - fireItemMoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaQuery> queries() { - return new CompositeIterator<JavaQuery>(this.namedNativeQueries(), this.namedQueries()); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (newIdClass != oldIdClass) { - if (newIdClass != null) { - if (getIdClassResource() == null) { - addIdClassResource(); - } - getIdClassResource().setValue(newIdClass); - } - else { - removeIdClassResource(); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getIdClassResource() { - return (IdClassAnnotation) this.javaResourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addIdClassResource() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeIdClassResource() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - TypeMapping typeMapping = i.next().getMapping(); - if (typeMapping != this && typeMapping instanceof Entity) { - return (Entity) typeMapping; - } - } - return this; - } - - public Entity getRootEntity() { - Entity rootEntity = this; - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - PersistentType persistentType = i.next(); - if (persistentType.getMapping() instanceof Entity) { - rootEntity = (Entity) persistentType.getMapping(); - } - } - return rootEntity; - } - - public String getPrimaryKeyColumnName() { - return getPrimaryKeyColumnName(getPersistentType().allAttributes()); - } - - //copied in GenericOrmEntity to avoid an API change for fixing bug 229423 in RC1 - public String getPrimaryKeyColumnName(Iterator<PersistentAttribute> attributes) { - String pkColumnName = null; - for (Iterator<PersistentAttribute> stream = attributes; stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - String name = attribute.getPrimaryKeyColumnName(); - if (name != null) { - //if the attribute is a primary key then we need to check if there is an attribute override - //and use its column name instead (bug 229423) - AttributeOverride attributeOverride = getAttributeOverrideNamed(attribute.getName()); - if (attributeOverride != null) { - name = attributeOverride.getColumn().getName(); - } - } - 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; - } - - @Override - public boolean tableNameIsInvalid(String tableName) { - return !CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - @Override - public Iterator<Table> associatedTables() { - return new CompositeIterator<Table>(this.getTable(), this.secondaryTables()); - } - - @Override - public Iterator<Table> associatedTablesIncludingInherited() { - return new CompositeIterator<Table>(new TransformationIterator<TypeMapping, Iterator<Table>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<Table> transform(TypeMapping mapping) { - return new FilteringIterator<Table, Table>(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); - } - }; - } - }); - } - - @Override - public Iterator<String> associatedTableNamesIncludingInherited() { - return this.nonNullTableNames(this.associatedTablesIncludingInherited()); - } - - protected Iterator<String> nonNullTableNames(Iterator<Table> tables) { - return new FilteringIterator<String, String>(this.tableNames(tables)) { - @Override - protected boolean accept(String o) { - return o != null; - } - }; - } - - protected Iterator<String> tableNames(Iterator<Table> tables) { - return new TransformationIterator<Table, String>(tables) { - @Override - protected String transform(Table t) { - return t.getName(); - } - }; - } - - /** - * 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> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - 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(); - } - }); - } - - - @Override - public Iterator<PersistentAttribute> allOverridableAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - public Iterator<PersistentAttribute> allOverridableAssociations() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAssociations(); - } - }); - } - - @Override - 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(); - } - }); - } - - @Override - public void update(JavaResourcePersistentType resourcePersistentType) { - super.update(resourcePersistentType); - this.entityResource = (EntityAnnotation) resourcePersistentType.getMappingAnnotation(EntityAnnotation.ANNOTATION_NAME); - - this.setSpecifiedName_(this.specifiedName(this.entityResource)); - this.setDefaultName(this.defaultName(resourcePersistentType)); - - this.updateInheritance(getInheritanceResource()); - this.updateDiscriminatorColumn(resourcePersistentType); - this.updateDiscriminatorValue(getDiscriminatorValueResource()); - this.setDiscriminatorValueAllowed(discriminatorValueIsAllowed(resourcePersistentType)); - this.updateTable(resourcePersistentType); - this.updateSecondaryTables(resourcePersistentType); - this.updateTableGenerator(resourcePersistentType); - this.updateSequenceGenerator(resourcePersistentType); - this.updateSpecifiedPrimaryKeyJoinColumns(resourcePersistentType); - this.updateDefaultPrimaryKeyJoinColumn(resourcePersistentType); - this.updateSpecifiedAttributeOverrides(resourcePersistentType); - this.updateVirtualAttributeOverrides(resourcePersistentType); - this.updateSpecifiedAssociationOverrides(resourcePersistentType); - this.updateVirtualAssociationOverrides(resourcePersistentType); - this.updateNamedQueries(resourcePersistentType); - this.updateNamedNativeQueries(resourcePersistentType); - this.updateIdClass(resourcePersistentType); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String specifiedName(EntityAnnotation entityResource) { - return entityResource.getName(); - } - - protected String defaultName(JavaResourcePersistentType persistentTypeResource) { - return persistentTypeResource.getName(); - } - - protected void updateTable(JavaResourcePersistentType persistentTypeResource) { - getTable().update(persistentTypeResource); - } - - protected void updateInheritance(InheritanceAnnotation inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.specifiedInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.defaultInheritanceStrategy()); - } - - protected InheritanceType specifiedInheritanceStrategy(InheritanceAnnotation inheritanceResource) { - return InheritanceType.fromJavaResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType defaultInheritanceStrategy() { - if (getRootEntity() == this) { - return InheritanceType.SINGLE_TABLE; - } - return getRootEntity().getInheritanceStrategy(); - } - - protected void updateDiscriminatorColumn(JavaResourcePersistentType persistentTypeResource) { - getDiscriminatorColumn().update(persistentTypeResource); - } - - protected void updateDiscriminatorValue(DiscriminatorValueAnnotation discriminatorValueResource) { - this.setSpecifiedDiscriminatorValue_(discriminatorValueResource.getValue()); - this.setDefaultDiscriminatorValue(this.javaDefaultDiscriminatorValue()); - } - - /** - * 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 javaDefaultDiscriminatorValue() { - if (this.javaResourcePersistentType.isAbstract()) { - return null; - } - if (this.getDiscriminatorType() != DiscriminatorType.STRING) { - return null; - } - return this.getName(); - } - - protected DiscriminatorType getDiscriminatorType() { - return this.getDiscriminatorColumn().getDiscriminatorType(); - } - - protected boolean discriminatorValueIsAllowed(JavaResourcePersistentType persistentTypeResource) { - return !persistentTypeResource.isAbstract(); - } - - protected void updateSecondaryTables(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaSecondaryTable> secondaryTables = specifiedSecondaryTables(); - ListIterator<JavaResourceNode> resourceSecondaryTables = persistentTypeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - while (secondaryTables.hasNext()) { - JavaSecondaryTable secondaryTable = secondaryTables.next(); - if (resourceSecondaryTables.hasNext()) { - secondaryTable.update((SecondaryTableAnnotation) resourceSecondaryTables.next()); - } - else { - removeSpecifiedSecondaryTable_(secondaryTable); - } - } - - while (resourceSecondaryTables.hasNext()) { - addSpecifiedSecondaryTable(specifiedSecondaryTablesSize(), buildSecondaryTable((SecondaryTableAnnotation) resourceSecondaryTables.next())); - } - } - - protected JavaSecondaryTable buildSecondaryTable(SecondaryTableAnnotation secondaryTableResource) { - JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); - secondaryTable.initializeFromResource(secondaryTableResource); - return secondaryTable; - } - - protected void updateTableGenerator(JavaResourcePersistentType persistentTypeResource) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(persistentTypeResource); - if (tableGeneratorResource == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(tableGeneratorResource)); - } - else { - getTableGenerator().update(tableGeneratorResource); - } - } - } - - protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorResource) { - JavaTableGenerator tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - tableGenerator.initializeFromResource(tableGeneratorResource); - return tableGenerator; - } - - protected TableGeneratorAnnotation tableGenerator(JavaResourcePersistentType persistentTypeResource) { - return (TableGeneratorAnnotation) persistentTypeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected void updateSequenceGenerator(JavaResourcePersistentType persistentTypeResource) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(persistentTypeResource); - if (sequenceGeneratorResource == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(sequenceGeneratorResource)); - } - else { - getSequenceGenerator().update(sequenceGeneratorResource); - } - } - } - - protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorResource) { - JavaSequenceGenerator sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - sequenceGenerator.initializeFromResource(sequenceGeneratorResource); - return sequenceGenerator; - } - - protected SequenceGeneratorAnnotation sequenceGenerator(JavaResourcePersistentType persistentTypeResource) { - return (SequenceGeneratorAnnotation) persistentTypeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - - protected void updateSpecifiedPrimaryKeyJoinColumns(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<JavaResourceNode> resourcePrimaryKeyJoinColumns = persistentTypeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - while (primaryKeyJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update((PrimaryKeyJoinColumnAnnotation) resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) resourcePrimaryKeyJoinColumns.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - primaryKeyJoinColumn.initializeFromResource(primaryKeyJoinColumnResource); - return primaryKeyJoinColumn; - } - - protected void updateDefaultPrimaryKeyJoinColumn(JavaResourcePersistentType persistentTypeResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.javaResourcePersistentType))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumn(persistentTypeResource)); - } - } - - protected void updateSpecifiedAttributeOverrides(JavaResourcePersistentType persistentTypeResource) { - ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<JavaResourceNode> resourceAttributeOverrides = persistentTypeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - while (attributeOverrides.hasNext()) { - JavaAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update((AttributeOverrideAnnotation) resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride((AttributeOverrideAnnotation) resourceAttributeOverrides.next())); - } - } - - protected JavaAttributeOverride buildAttributeOverride(AttributeOverrideAnnotation attributeOverrideResource) { - JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); - attributeOverride.initializeFromResource(attributeOverrideResource); - return attributeOverride; - } - - protected JavaAttributeOverride buildVirtualAttributeOverride(JavaResourcePersistentType resourcePersistentType, PersistentAttribute attribute) { - return buildAttributeOverride(buildVirtualAttributeOverrideResource(resourcePersistentType, attribute)); - } - - protected VirtualAttributeOverride buildVirtualAttributeOverrideResource(JavaResourcePersistentType resourcePersistentType, PersistentAttribute attribute) { - ColumnMapping columnMapping = (ColumnMapping) attribute.getMapping(); - return new VirtualAttributeOverride(resourcePersistentType, attribute.getName(), columnMapping.getColumn()); - } - - protected void updateVirtualAttributeOverrides(JavaResourcePersistentType resourcePersistentType) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - JavaAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - addVirtualAttributeOverride(buildVirtualAttributeOverride(resourcePersistentType, persistentAttribute)); - } - else if (attributeOverride.isVirtual()) { - attributeOverride.update(buildVirtualAttributeOverrideResource(resourcePersistentType, persistentAttribute)); - } - } - - Collection<String> attributeNames = CollectionTools.collection(allOverridableAttributeNames()); - - //remove any default mappings that are not included in the attributeNames collection - for (JavaAttributeOverride attributeOverride : CollectionTools.iterable(virtualAttributeOverrides())) { - if (!attributeNames.contains(attributeOverride.getName()) - || containsSpecifiedAttributeOverride(attributeOverride.getName())) { - removeVirtualAttributeOverride(attributeOverride); - } - } - } - - protected void updateSpecifiedAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - ListIterator<JavaResourceNode> resourceAssociationOverrides = resourcePersistentType.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - while (associationOverrides.hasNext()) { - JavaAssociationOverride associationOverride = associationOverrides.next(); - if (resourceAssociationOverrides.hasNext()) { - associationOverride.update((AssociationOverrideAnnotation) resourceAssociationOverrides.next()); - } - else { - removeSpecifiedAssociationOverride_(associationOverride); - } - } - - while (resourceAssociationOverrides.hasNext()) { - addSpecifiedAssociationOverride(specifiedAssociationOverridesSize(), buildAssociationOverride((AssociationOverrideAnnotation) resourceAssociationOverrides.next())); - } - } - - protected JavaAssociationOverride buildAssociationOverride(AssociationOverrideAnnotation associationOverrideResource) { - JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); - associationOverride.initializeFromResource(associationOverrideResource); - return associationOverride; - } - - protected void updateVirtualAssociationOverrides(JavaResourcePersistentType resourcePersistentType) { - for (Iterator<String> i = allOverridableAssociationNames(); i.hasNext(); ) { - String associationName = i.next(); - JavaAssociationOverride associationOverride = getAssociationOverrideNamed(associationName); - if (associationOverride == null) { - associationOverride = buildAssociationOverride(new NullAssociationOverride(resourcePersistentType, associationName)); - addVirtualAssociationOverride(associationOverride); - } - else if (associationOverride.isVirtual()) { - associationOverride.update(new NullAssociationOverride(resourcePersistentType, associationName)); - } - } - - Collection<String> associationNames = CollectionTools.collection(allOverridableAssociationNames()); - - //remove any default mappings that are not included in the associationNames collection - for (JavaAssociationOverride associationOverride : CollectionTools.iterable(virtualAssociationOverrides())) { - if (!associationNames.contains(associationOverride.getName()) - || containsSpecifiedAssociationOverride(associationOverride.getName())) { - removeVirtualAssociationOverride(associationOverride); - } - } - } - - protected void updateNamedQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaNamedQuery> namedQueries = namedQueries(); - ListIterator<JavaResourceNode> resourceNamedQueries = resourcePersistentType.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - - while (namedQueries.hasNext()) { - JavaNamedQuery namedQuery = namedQueries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update((NamedQueryAnnotation) resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(namedQueriesSize(), buildNamedQuery((NamedQueryAnnotation) resourceNamedQueries.next())); - } - } - - protected void updateNamedNativeQueries(JavaResourcePersistentType resourcePersistentType) { - ListIterator<JavaNamedNativeQuery> namedNativeQueries = namedNativeQueries(); - ListIterator<JavaResourceNode> resourceNamedNativeQueries = resourcePersistentType.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - - while (namedNativeQueries.hasNext()) { - JavaNamedNativeQuery namedQuery = namedNativeQueries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update((NamedNativeQueryAnnotation) resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(namedNativeQueriesSize(), buildNamedNativeQuery((NamedNativeQueryAnnotation) resourceNamedNativeQueries.next())); - } - } - - - protected JavaNamedQuery buildNamedQuery(NamedQueryAnnotation namedQueryResource) { - JavaNamedQuery namedQuery = getJpaFactory().buildJavaNamedQuery(this); - namedQuery.initializeFromResource(namedQueryResource); - return namedQuery; - } - - protected JavaNamedNativeQuery buildNamedNativeQuery(NamedNativeQueryAnnotation namedNativeQueryResource) { - JavaNamedNativeQuery namedNativeQuery = getJpaFactory().buildJavaNamedNativeQuery(this); - namedNativeQuery.initializeFromResource(namedNativeQueryResource); - return namedNativeQuery; - } - - protected void updateIdClass(JavaResourcePersistentType resourcePersistentType) { - IdClassAnnotation idClass = (IdClassAnnotation) resourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClass != null) { - setIdClass_(idClass.getValue()); - } - else { - setIdClass_(null); - } - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - //******************** Code Completion ************************* - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getTable().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaSecondaryTable sTable : CollectionTools.iterable(this.secondaryTables())) { - result = sTable.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaPrimaryKeyJoinColumn column : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaAttributeOverride override : CollectionTools.iterable(this.attributeOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaAssociationOverride override : CollectionTools.iterable(this.associationOverrides())) { - result = override.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - result = this.getDiscriminatorColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.getTableGenerator() != null) { - result = this.getTableGenerator().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - if (this.getSequenceGenerator() != null) { - result = this.getSequenceGenerator().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - - //********** Validation ******************************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - getTable().addToMessages(messages, astRoot); - addIdMessages(messages, astRoot); - addGeneratorMessages(messages, astRoot); - addQueryMessages(messages, astRoot); - - for (Iterator<JavaSecondaryTable> stream = this.specifiedSecondaryTables(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - for (Iterator<JavaAttributeOverride> stream = this.attributeOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - for (Iterator<JavaAssociationOverride> stream = this.associationOverrides(); stream.hasNext();) { - stream.next().addToMessages(messages, astRoot); - } - - } - - protected void addIdMessages(List<IMessage> messages, CompilationUnit astRoot) { - addNoIdMessage(messages, astRoot); - } - - protected void addNoIdMessage(List<IMessage> messages, CompilationUnit astRoot) { - if (entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, this.getValidationTextRange(astRoot)) - ); - } - } - - private boolean entityHasNoId() { - return ! this.entityHasId(); - } - - private boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - protected void addGeneratorMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<JavaGenerator> stream = this.generators(); stream.hasNext() ; ) { - JavaGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } - - protected void addQueryMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<JavaQuery> stream = this.queries(); stream.hasNext() ; ) { - JavaQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } - - class PrimaryKeyJoinColumnOwner implements JavaBaseJoinColumn.Owner - { - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaEntity.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericJavaEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity parentEntity = GenericJavaEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericJavaEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaEntity.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return GenericJavaEntity.this.getParentEntity().getPrimaryKeyColumnName(); - } - } - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaEntity.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaEntity.this.setAttributeOverrideVirtual(virtual, (JavaAttributeOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public TextRange validationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - } - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof RelationshipMapping) { - return (RelationshipMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericJavaEntity.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride attributeOverride) { - return GenericJavaEntity.this.setAssociationOverrideVirtual(virtual, (JavaAssociationOverride) attributeOverride); - } - - public TypeMapping getTypeMapping() { - return GenericJavaEntity.this; - } - - public TextRange validationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java deleted file mode 100644 index 7db737a10f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericJavaGeneratedValue extends AbstractJavaJpaContextNode implements JavaGeneratedValue -{ - protected GenerationType strategy; - - protected String generator; - - protected String defaultGenerator; - - protected GeneratedValueAnnotation generatedValueResource; - - public GenericJavaGeneratedValue(JavaAttributeMapping parent) { - super(parent); - } - - public void initializeFromResource(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.strategy = this.strategy(generatedValue); - this.generator = this.generator(generatedValue); - } - - public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.strategy; - } - - public void setSpecifiedStrategy(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - this.generatedValueResource.setStrategy(GenerationType.toJavaResourceModel(newStrategy)); - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - protected void setSpecifiedStrategy_(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); - } - - public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); - } - - public String getSpecifiedGenerator() { - return this.generator; - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - public void setSpecifiedGenerator(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - this.generatedValueResource.setGenerator(newGenerator); - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); - } - - protected void setSpecifiedGenerator_(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getTextRange(astRoot); - } - - public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getGeneratorTextRange(astRoot); - } - - // ********** resource model -> java context model ********** - - public void update(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.setSpecifiedStrategy_(this.strategy(generatedValue)); - this.setSpecifiedGenerator_(this.generator(generatedValue)); - } - - protected GenerationType strategy(GeneratedValueAnnotation generatedValue) { - return GenerationType.fromJavaResourceModel(generatedValue.getStrategy()); - } - - protected String generator(GeneratedValueAnnotation generatedValue) { - return generatedValue.getGenerator(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java deleted file mode 100644 index 0f3b1b3391..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java +++ /dev/null @@ -1,487 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaGeneratedValue; -import org.eclipse.jpt.core.context.java.JavaGenerator; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -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; - - -public class GenericJavaIdMapping extends AbstractJavaAttributeMapping<IdAnnotation> implements JavaIdMapping -{ - protected final JavaColumn column; - - protected JavaGeneratedValue generatedValue; - - protected TemporalType temporal; - - protected JavaTableGenerator tableGenerator; - - protected JavaSequenceGenerator sequenceGenerator; - - public GenericJavaIdMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.column.initializeFromResource(this.getColumnResource()); - this.temporal = this.temporal(this.getTemporalResource()); - this.initializeTableGenerator(resourcePersistentAttribute); - this.initializeSequenceGenerator(resourcePersistentAttribute); - this.initializeGeneratedValue(resourcePersistentAttribute); - this.updatePersistenceUnitGenerators(); - } - - protected void initializeTableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentAttribute); - if (tableGeneratorResource != null) { - this.tableGenerator = buildTableGenerator(tableGeneratorResource); - } - } - - protected void initializeSequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentAttribute); - if (sequenceGeneratorResource != null) { - this.sequenceGenerator = buildSequenceGenerator(sequenceGeneratorResource); - } - } - - protected void initializeGeneratedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - GeneratedValueAnnotation generatedValueResource = generatedValue(resourcePersistentAttribute); - if (generatedValueResource != null) { - this.generatedValue = buildGeneratedValue(generatedValueResource); - } - } - - protected TemporalAnnotation getTemporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.GENERATED_VALUE, - JPA.TEMPORAL, - JPA.TABLE_GENERATOR, - JPA.SEQUENCE_GENERATOR); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IIdMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getTemporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - /** - * internal setter used only for updating from the resource model. - * There were problems with InvalidThreadAccess exceptions in the UI - * when you set a value from the UI and the annotation doesn't exist yet. - * Adding the annotation causes an update to occur and then the exception. - */ - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public JavaGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); - } - this.generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - GeneratedValueAnnotation generatedValueResource = (GeneratedValueAnnotation) getResourcePersistentAttribute().addAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - this.generatedValue.initializeFromResource(generatedValueResource); - 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"); - } - JavaGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - getResourcePersistentAttribute().removeAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); - } - - public JavaGeneratedValue getGeneratedValue() { - return this.generatedValue; - } - - protected void setGeneratedValue(JavaGeneratedValue newGeneratedValue) { - JavaGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = newGeneratedValue; - firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, newGeneratedValue); - } - - public JavaTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = (TableGeneratorAnnotation) getResourcePersistentAttribute().addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - this.tableGenerator.initializeFromResource(tableGeneratorResource); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); - } - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - getResourcePersistentAttribute().removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public JavaTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(JavaTableGenerator newTableGenerator) { - JavaTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - public JavaSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - - this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = (SequenceGeneratorAnnotation) getResourcePersistentAttribute().addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - this.sequenceGenerator.initializeFromResource(sequenceGeneratorResource); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); - } - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - getResourcePersistentAttribute().removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public JavaSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(JavaSequenceGenerator newSequenceGenerator) { - JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<JavaGenerator> generators() { - return new CompositeIterator<JavaGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setTemporal_(this.temporal(this.getTemporalResource())); - this.updateTableGenerator(resourcePersistentAttribute); - this.updateSequenceGenerator(resourcePersistentAttribute); - this.updateGeneratedValue(resourcePersistentAttribute); - this.updatePersistenceUnitGenerators(); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - protected void updateTableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - TableGeneratorAnnotation tableGeneratorResource = tableGenerator(resourcePersistentAttribute); - if (tableGeneratorResource == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(tableGeneratorResource)); - } - else { - getTableGenerator().update(tableGeneratorResource); - } - } - } - - protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorResource) { - JavaTableGenerator tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - tableGenerator.initializeFromResource(tableGeneratorResource); - return tableGenerator; - } - - protected void updateSequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - SequenceGeneratorAnnotation sequenceGeneratorResource = sequenceGenerator(resourcePersistentAttribute); - if (sequenceGeneratorResource == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(sequenceGeneratorResource)); - } - else { - getSequenceGenerator().update(sequenceGeneratorResource); - } - } - } - - protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorResource) { - JavaSequenceGenerator sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - sequenceGenerator.initializeFromResource(sequenceGeneratorResource); - return sequenceGenerator; - } - - protected void updateGeneratedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - GeneratedValueAnnotation generatedValueResource = generatedValue(resourcePersistentAttribute); - if (generatedValueResource == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(generatedValueResource)); - } - else { - getGeneratedValue().update(generatedValueResource); - } - } - } - - protected JavaGeneratedValue buildGeneratedValue(GeneratedValueAnnotation generatedValueResource) { - JavaGeneratedValue generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - generatedValue.initializeFromResource(generatedValueResource); - return generatedValue; - } - - protected TableGeneratorAnnotation tableGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (TableGeneratorAnnotation) resourcePersistentAttribute.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); - } - - protected SequenceGeneratorAnnotation sequenceGenerator(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (SequenceGeneratorAnnotation) resourcePersistentAttribute.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); - } - - protected GeneratedValueAnnotation generatedValue(JavaResourcePersistentAttribute resourcePersistentAttribute) { - return (GeneratedValueAnnotation) resourcePersistentAttribute.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); - } - - protected void updatePersistenceUnitGenerators() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - } - - - // ************************************************************************* - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - //*********** Validation ************ - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - addGeneratedValueMessages(messages, astRoot); - addGeneratorMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } - - protected void addGeneratedValueMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaGeneratedValue generatedValue = this.getGeneratedValue(); - if (generatedValue == null) { - return; - } - String generatorName = generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Generator nextMasterGenerator : CollectionTools.iterable(getPersistenceUnit().allGenerators())) { - if (generatorName.equals(nextMasterGenerator.getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - generatedValue.getGeneratorTextRange(astRoot)) - ); - } - - protected void addGeneratorMessages(List<IMessage> messages, CompilationUnit astRoot) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<JavaGenerator> stream = this.generators(); stream.hasNext() ; ) { - JavaGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange(astRoot)) - ); - } - } - - masterList.add(current); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java deleted file mode 100644 index 35d5029cef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumn.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public class GenericJavaJoinColumn extends AbstractJavaBaseColumn<JoinColumnAnnotation> implements JavaJoinColumn -{ - - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected JoinColumnAnnotation joinColumn; - - public GenericJavaJoinColumn(JavaJpaContextNode parent, JavaJoinColumn.Owner owner) { - super(parent, owner); - } - - @Override - protected JoinColumnAnnotation getColumnResource() { - return this.joinColumn; - } - - public String getReferencedColumnName() { - return (this.specifiedReferencedColumnName == null) ? this.defaultReferencedColumnName : this.specifiedReferencedColumnName; - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - this.joinColumn.setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - - @Override - public JavaJoinColumn.Owner getOwner() { - return (JavaJoinColumn.Owner) super.getOwner(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public Table getDbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public Column getDbReferencedColumn() { - Table table = this.getDbReferencedColumnTable(); - return (table == null) ? null : table.columnNamed(this.getReferencedColumnName()); - } - - @Override - public boolean tableIsAllowed() { - return this.getOwner().tableIsAllowed(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return getColumnResource().referencedColumnNameTouches(pos, astRoot); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getDbReferencedColumnTable(); - return (table != null) ? table.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> quotedCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateReferencedColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.referencedColumnNameTouches(pos, astRoot)) { - return this.quotedCandidateReferencedColumnNames(filter); - } - return null; - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(astRoot); - return (textRange != null) ? textRange : getOwner().getValidationTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void initializeFromResource(JoinColumnAnnotation joinColumn) { - this.joinColumn = joinColumn; - super.initializeFromResource(joinColumn); - this.specifiedReferencedColumnName = joinColumn.getReferencedColumnName(); - this.defaultReferencedColumnName = this.defaultReferencedColumnName(); - } - - @Override - public void update(JoinColumnAnnotation joinColumn) { - this.joinColumn = joinColumn; - super.update(joinColumn); - this.setSpecifiedReferencedColumnName_(joinColumn.getReferencedColumnName()); - this.setDefaultReferencedColumnName(this.defaultReferencedColumnName()); - } - - @Override - protected String defaultName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String defaultReferencedColumnName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this); - } - - @Override - protected String defaultTable() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultTable(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java deleted file mode 100644 index b759f0e36f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTable.java +++ /dev/null @@ -1,739 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.NonOwningMapping; -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.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.resource.java.NullJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -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; - -public class GenericJavaJoinTable extends AbstractJavaTable implements JavaJoinTable -{ - protected final List<JavaJoinColumn> specifiedJoinColumns; - - protected JavaJoinColumn defaultJoinColumn; - - protected final List<JavaJoinColumn> specifiedInverseJoinColumns; - - protected JavaJoinColumn defaultInverseJoinColumn; - - protected JavaResourcePersistentAttribute attributeResource; - - public GenericJavaJoinTable(JavaRelationshipMapping parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<JavaJoinColumn>(); - this.specifiedInverseJoinColumns = new ArrayList<JavaJoinColumn>(); - } - - @Override - public JavaRelationshipMapping getParent() { - return (JavaRelationshipMapping) super.getParent(); - } - - //******************* AbstractJavaTable implementation ***************** - - @Override - protected String getAnnotationName() { - return JoinTableAnnotation.ANNOTATION_NAME; - } - - /** - * Default join table name from the JPA spec: - * The concatenated names of the two associated primary - * entity tables, separated by a underscore. - * - * [owning table name]_[target table name] - */ - @Override - protected String defaultName() { - return MappingTools.buildJoinTableDefaultName(getRelationshipMapping()); - } - - @Override - protected String defaultCatalog() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultCatalog(); - } - - @Override - protected String defaultSchema() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return super.defaultSchema(); - } - - @Override - protected JoinTableAnnotation getTableResource() { - return (JoinTableAnnotation) this.attributeResource.getNonNullAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - /** - * Return the join table java resource, null if the annotation does not exist. - * Use tableResource() if you want a non null implementation - */ - protected JoinTableAnnotation getJoinTableResource() { - return (JoinTableAnnotation) this.attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - protected void addJoinTableResource() { - this.attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - } - - - //******************* IJoinTable implementation ***************** - - public ListIterator<JavaJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(JavaJoinColumn newJoinColumn) { - JavaJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultJoinColumns() { - if (this.defaultJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultJoinColumnsSize() { - return (this.defaultJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedJoinColumn(int index) { - JoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - 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; - } - if (getJoinTableResource() == null) { - //Add the JoinTable before creating the specifiedJoinColumn. - //Otherwise we will remove it and create another during an update - //from the java resource model - addJoinTableResource(); - } - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - JoinColumnAnnotation joinColumnResource = this.getTableResource().addJoinColumn(index); - joinColumn.initializeFromResource(joinColumnResource); - this.fireItemAdded(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, JavaJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //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 = buildJoinColumn(new NullJoinColumn(getTableResource())); - } - this.getTableResource().removeJoinColumn(index); - fireItemRemoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getTableResource().moveJoinColumn(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public ListIterator<JavaJoinColumn> inverseJoinColumns() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public JavaJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(JavaJoinColumn newInverseJoinColumn) { - JavaJoinColumn oldInverseJoinColumn = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = newInverseJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldInverseJoinColumn, newInverseJoinColumn); - } - - protected ListIterator<JavaJoinColumn> defaultInverseJoinColumns() { - if (this.defaultInverseJoinColumn != null) { - return new SingleElementListIterator<JavaJoinColumn>(this.defaultInverseJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultInverseJoinColumnsSize() { - return (this.defaultInverseJoinColumn == null) ? 0 : 1; - } - - public ListIterator<JavaJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<JavaJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - public boolean containsSpecifiedInverseJoinColumns() { - return !this.specifiedInverseJoinColumns.isEmpty(); - } - - public JavaJoinColumn addSpecifiedInverseJoinColumn(int index) { - JoinColumn oldDefaultInverseJoinColumn = this.getDefaultInverseJoinColumn(); - if (oldDefaultInverseJoinColumn != 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.defaultInverseJoinColumn = null; - } - if (getJoinTableResource() == null) { - //Add the JoinTable before creating the specifiedJoinColumn. - //Otherwise we will remove it and create another during an update - //from the java resource model - addJoinTableResource(); - } - JavaJoinColumn inverseJoinColumn = getJpaFactory().buildJavaJoinColumn(this, createInverseJoinColumnOwner()); - this.specifiedInverseJoinColumns.add(index, inverseJoinColumn); - JoinColumnAnnotation joinColumnResource = this.getTableResource().addInverseJoinColumn(index); - inverseJoinColumn.initializeFromResource(joinColumnResource); - this.fireItemAdded(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, inverseJoinColumn); - if (oldDefaultInverseJoinColumn != null) { - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldDefaultInverseJoinColumn, null); - } - return inverseJoinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, JavaJoinColumn inverseJoinColumn) { - addItemToList(index, inverseJoinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn inverseJoinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(inverseJoinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - JavaJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if (!containsSpecifiedInverseJoinColumns()) { - //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.defaultInverseJoinColumn = buildInverseJoinColumn(new NullJoinColumn(getTableResource())); - } - this.getTableResource().removeInverseJoinColumn(index); - fireItemRemoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(JavaJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getTableResource().moveInverseJoinColumn(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - public RelationshipMapping getRelationshipMapping() { - return this.getParent(); - } - - public boolean isSpecified() { - return getJoinTableResource() != null; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaJoinColumn column : CollectionTools.iterable(this.joinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - for (JavaJoinColumn column : CollectionTools.iterable(this.inverseJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - protected JavaJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected JavaJoinColumn.Owner createInverseJoinColumnOwner() { - return new InverseJoinColumnOwner(); - } - - public void initializeFromResource(JavaResourcePersistentAttribute attributeResource) { - this.attributeResource = attributeResource; - JoinTableAnnotation joinTable = getTableResource(); - this.initializeFromResource(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(joinTable); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(joinTable); - } - - protected void initializeSpecifiedJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JoinColumnAnnotation> annotations = joinTableResource.joinColumns(); - - while(annotations.hasNext()) { - this.specifiedJoinColumns.add(buildJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && getRelationshipMapping().isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(new NullJoinColumn(joinTable)); - } - - protected void initializeSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JoinColumnAnnotation> annotations = joinTableResource.inverseJoinColumns(); - - while(annotations.hasNext()) { - this.specifiedInverseJoinColumns.add(buildInverseJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return !containsSpecifiedInverseJoinColumns() && getRelationshipMapping().isRelationshipOwner(); - } - - protected void initializeDefaultInverseJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultInverseJoinColumn()) { - return; - } - this.defaultInverseJoinColumn = buildInverseJoinColumn(new NullJoinColumn(joinTable)); - } - - public void update(JavaResourcePersistentAttribute attributeResource) { - this.attributeResource = attributeResource; - JoinTableAnnotation joinTable = getTableResource(); - this.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(joinTable); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(joinTable); - } - - protected void updateSpecifiedJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = joinTableResource.joinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(new NullJoinColumn(joinTable))); - } - else { - this.defaultJoinColumn.update(new NullJoinColumn(joinTable)); - } - } - - protected void updateSpecifiedInverseJoinColumns(JoinTableAnnotation joinTableResource) { - ListIterator<JavaJoinColumn> joinColumns = specifiedInverseJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = joinTableResource.inverseJoinColumns(); - - while (joinColumns.hasNext()) { - JavaJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedInverseJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedInverseJoinColumn(specifiedInverseJoinColumnsSize(), buildInverseJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultInverseJoinColumn(JoinTableAnnotation joinTable) { - if (!shouldBuildDefaultInverseJoinColumn()) { - setDefaultInverseJoinColumn(null); - return; - } - if (getDefaultInverseJoinColumn() == null) { - this.setDefaultInverseJoinColumn(buildInverseJoinColumn(new NullJoinColumn(joinTable))); - } - else { - this.defaultInverseJoinColumn.update(new NullJoinColumn(joinTable)); - } - } - - protected JavaJoinColumn buildJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createJoinColumnOwner()); - joinColumn.initializeFromResource(joinColumnResource); - return joinColumn; - } - - protected JavaJoinColumn buildInverseJoinColumn(JoinColumnAnnotation joinColumnResource) { - JavaJoinColumn joinColumn = getJpaFactory().buildJavaJoinColumn(this, createInverseJoinColumnOwner()); - joinColumn.initializeFromResource(joinColumnResource); - return joinColumn; - } - - - //********************* validation ******************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && !isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - doContinue = false; - } - - for (Iterator<JavaJoinColumn> stream = joinColumns(); stream.hasNext(); ) { - JavaJoinColumn joinColumn = stream.next(); - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - - for (Iterator<JavaJoinColumn> stream = inverseJoinColumns(); stream.hasNext(); ) { - JavaJoinColumn joinColumn = stream.next(); - - if (doContinue && ! joinColumn.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, joinColumn.getNameTextRange(astRoot)) - ); - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, joinColumn.getReferencedColumnNameTextRange(astRoot)) - ); - } - } - } - - /** - * just a little common behavior - */ - abstract class AbstractJoinColumnOwner implements JavaJoinColumn.Owner - { - AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericJavaJoinTable.this.getRelationshipMapping(); - } - - /** - * the default table name is always valid and a specified table name - * is prohibited (which will be handled elsewhere) - */ - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - /** - * the join column can only be on the join table itself - */ - public boolean tableIsAllowed() { - return false; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - if (GenericJavaJoinTable.this.getName() == null) { - return null; - } - return (GenericJavaJoinTable.this.getName().equals(tableName)) ? GenericJavaJoinTable.this.getDbTable() : null; - } - - /** - * by default, the join column is, obviously, in the join table; - * not sure whether it can be anywhere else... - */ - public String getDefaultTableName() { - return GenericJavaJoinTable.this.getName(); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaJoinTable.this.getValidationTextRange(astRoot); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - class InverseJoinColumnOwner extends AbstractJoinColumnOwner - { - public InverseJoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericJavaJoinTable.this.getRelationshipMapping().getPersistentAttribute().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.inverseJoinColumnsSize(); - } - } - - - /** - * owner for "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - class JoinColumnOwner extends AbstractJoinColumnOwner - { - public JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericJavaJoinTable.this.getRelationshipMapping().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericJavaJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String attributeName = GenericJavaJoinTable.this.getRelationshipMapping().getPersistentAttribute().getName(); - for (Iterator<PersistentAttribute> stream = targetEntity.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - AttributeMapping mapping = attribute.getMapping(); - if (mapping instanceof NonOwningMapping) { - String mappedBy = ((NonOwningMapping) mapping).getMappedBy(); - if ((mappedBy != null) && mappedBy.equals(attributeName)) { - return attribute.getName(); - } - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - return getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericJavaJoinTable.this.joinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java deleted file mode 100644 index 3d9bf0eebe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToManyMapping.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaManyToManyMapping extends AbstractJavaMultiRelationshipMapping<ManyToManyAnnotation> - implements JavaManyToManyMapping -{ - - public GenericJavaManyToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ORDER_BY, - JPA.MAP_KEY, - JPA.JOIN_TABLE); - } - - // ********** JavaMultiRelationshipMapping implementation ********** - - @Override - protected boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - - @Override - protected void setMappedByOnResourceModel(String mappedBy) { - getMappingResource().setMappedBy(mappedBy); - } - - @Override - protected String mappedBy(ManyToManyAnnotation relationshipMapping) { - return relationshipMapping.getMappedBy(); - } - - // ********** INonOwningMapping implementation ********** - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - - @Override - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java deleted file mode 100644 index c11ca44d2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaManyToOneMapping.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaManyToOneMapping extends AbstractJavaSingleRelationshipMapping<ManyToOneAnnotation> - implements JavaManyToOneMapping -{ - - public GenericJavaManyToOneMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS, - JPA.JOIN_TABLE); - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - @Override - protected void setOptionalOnResourceModel(Boolean newOptional) { - this.getMappingResource().setOptional(newOptional); - } - - @Override - protected Boolean specifiedOptional(ManyToOneAnnotation relationshipMapping) { - return relationshipMapping.getOptional(); - } - - //ManyToOne mapping is always the owning side - public boolean isRelationshipOwner() { - return true; - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java deleted file mode 100644 index 240ee74e52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaMappedSuperclass.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - -public class GenericJavaMappedSuperclass extends AbstractJavaTypeMapping - implements JavaMappedSuperclass -{ - - protected String idClass; - - public GenericJavaMappedSuperclass(JavaPersistentType parent) { - super(parent); - } - - public boolean isMapped() { - return true; - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return MappedSuperclassAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ID_CLASS, - JPA.EXCLUDE_DEFAULT_LISTENERS, - JPA.EXCLUDE_SUPERCLASS_LISTENERS, - JPA.ENTITY_LISTENERS, - JPA.PRE_PERSIST, - JPA.POST_PERSIST, - JPA.PRE_REMOVE, - JPA.POST_REMOVE, - JPA.PRE_UPDATE, - JPA.POST_UPDATE, - JPA.POST_LOAD); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (newIdClass != oldIdClass) { - if (newIdClass != null) { - if (getIdClassResource() == null) { - addIdClassResource(); - } - getIdClassResource().setValue(newIdClass); - } - else { - removeIdClassResource(); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected IdClassAnnotation getIdClassResource() { - return (IdClassAnnotation) this.javaResourcePersistentType.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void addIdClassResource() { - this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - protected void removeIdClassResource() { - this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - } - - @Override - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - @Override - public Iterator<JavaPersistentAttribute> overridableAttributes() { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - @Override - public Iterator<JavaPersistentAttribute> overridableAssociations() { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return o.isOverridableAssociation(); - } - }; - } - - protected Iterator<String> namesOf(Iterator<JavaPersistentAttribute> attributes) { - return new TransformationIterator<JavaPersistentAttribute, String>(attributes) { - @Override - protected String transform(JavaPersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - @Override - public void initializeFromResource(JavaResourcePersistentType persistentTypeResource) { - super.initializeFromResource(persistentTypeResource); - this.initializeIdClass(persistentTypeResource); - } - - protected void initializeIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClassResource = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClassResource != null) { - this.idClass = idClassResource.getValue(); - } - } - - @Override - public void update(JavaResourcePersistentType persistentTypeResource) { - super.update(persistentTypeResource); - this.updateIdClass(persistentTypeResource); - } - - protected void updateIdClass(JavaResourcePersistentType typeResource) { - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME); - if (idClass != null) { - setIdClass_(idClass.getValue()); - } - else { - setIdClass_(null); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java deleted file mode 100644 index 6b84edd515..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedNativeQuery.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; - - -public class GenericJavaNamedNativeQuery extends AbstractJavaQuery - implements JavaNamedNativeQuery -{ - - protected String resultClass; - - protected String resultSetMapping; - - public GenericJavaNamedNativeQuery(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected NamedNativeQueryAnnotation getQueryResource() { - return (NamedNativeQueryAnnotation) super.getQueryResource(); - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getQueryResource().setResultClass(newResultClass); - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - protected void setResultClass_(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - getQueryResource().setResultSetMapping(newResultSetMapping); - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - protected void setResultSetMapping_(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - public void initializeFromResource(NamedNativeQueryAnnotation queryResource) { - super.initializeFromResource(queryResource); - this.resultClass = queryResource.getResultClass(); - this.resultSetMapping = queryResource.getResultSetMapping(); - } - - public void update(NamedNativeQueryAnnotation queryResource) { - super.update(queryResource); - this.setResultClass_(queryResource.getResultClass()); - this.setResultSetMapping_(queryResource.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java deleted file mode 100644 index 9b834036b9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNamedQuery.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; - - - -public class GenericJavaNamedQuery extends AbstractJavaQuery implements JavaNamedQuery -{ - - public GenericJavaNamedQuery(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected NamedQueryAnnotation getQueryResource() { - return (NamedQueryAnnotation) super.getQueryResource(); - } - - public void initializeFromResource(NamedQueryAnnotation queryResource) { - super.initializeFromResource(queryResource); - } - - public void update(NamedQueryAnnotation queryResource) { - super.update(queryResource); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java deleted file mode 100644 index badb692ade..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaNullAttributeMapping.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - - -public class GenericJavaNullAttributeMapping extends AbstractJavaAttributeMapping<JavaResourceNode> -{ - public GenericJavaNullAttributeMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return null; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - protected JavaResourceNode getMappingResource() { - return null; - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java deleted file mode 100644 index d5682df714..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToManyMapping.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaOneToManyMapping extends AbstractJavaMultiRelationshipMapping<OneToManyAnnotation> - implements JavaOneToManyMapping -{ - - public GenericJavaOneToManyMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.ORDER_BY, - JPA.MAP_KEY, - JPA.JOIN_TABLE, - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS); - } - - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - - // ********** JavaMultiRelationshipMapping implementation ********** - - @Override - protected boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - @Override - protected void setMappedByOnResourceModel(String mappedBy) { - this.getMappingResource().setMappedBy(mappedBy); - } - - @Override - protected String mappedBy(OneToManyAnnotation relationshipMapping) { - return relationshipMapping.getMappedBy(); - } - - - // ********** INonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - @Override - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java deleted file mode 100644 index 3b4581b171..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaOneToOneMapping.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumns; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaOneToOneMapping extends AbstractJavaSingleRelationshipMapping<OneToOneAnnotation> - implements JavaOneToOneMapping -{ - protected String mappedBy; - - protected final List<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns; - - public GenericJavaOneToOneMapping(JavaPersistentAttribute parent) { - super(parent); - this.primaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.PRIMARY_KEY_JOIN_COLUMN, - JPA.PRIMARY_KEY_JOIN_COLUMNS, - JPA.JOIN_COLUMN, - JPA.JOIN_COLUMNS, - JPA.JOIN_TABLE); - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public JavaPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createJoinColumnOwner()); - this.primaryKeyJoinColumns.add(index, pkJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) getResourcePersistentAttribute().addAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - pkJoinColumn.initializeFromResource(pkJoinColumnResource); - this.fireItemAdded(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - getResourcePersistentAttribute().removeAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - fireItemRemoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - getResourcePersistentAttribute().move(targetIndex, sourceIndex, PrimaryKeyJoinColumns.ANNOTATION_NAME); - fireItemMoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public boolean containsPrimaryKeyJoinColumns() { - return !this.primaryKeyJoinColumns.isEmpty(); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - this.getMappingResource().setMappedBy(newMappedBy); - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(NonOwningMapping.MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - @Override - protected void setOptionalOnResourceModel(Boolean newOptional) { - this.getMappingResource().setOptional(newOptional); - } - - public TextRange getMappedByTextRange(CompilationUnit astRoot) { - return this.getMappingResource().getMappedByTextRange(astRoot); - } - - public boolean mappedByTouches(int pos, CompilationUnit astRoot) { - return this.getMappingResource().mappedByTouches(pos, astRoot); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.mappedByTouches(pos, astRoot)) { - return this.quotedCandidateMappedByAttributeNames(filter); - } - return null; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - @Override - protected void initialize(OneToOneAnnotation oneToOneResource) { - super.initialize(oneToOneResource); - this.mappedBy = oneToOneResource.getMappedBy(); - } - - @Override - protected Boolean specifiedOptional(OneToOneAnnotation oneToOneResource) { - return oneToOneResource.getOptional(); - } - - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.initializePrimaryKeyJoinColumns(resourcePersistentAttribute); - } - - protected void initializePrimaryKeyJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaResourceNode> annotations = resourcePersistentAttribute.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - while(annotations.hasNext()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) annotations.next())); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createJoinColumnOwner()); - pkJoinColumn.initializeFromResource(primaryKeyJoinColumnResource); - return pkJoinColumn; - } - - @Override - protected void update(OneToOneAnnotation oneToOneResource) { - super.update(oneToOneResource); - this.setMappedBy_(oneToOneResource.getMappedBy()); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.updatePrimaryKeyJoinColumns(resourcePersistentAttribute); - } - - protected void updatePrimaryKeyJoinColumns(JavaResourcePersistentAttribute resourcePersistentAttribute) { - ListIterator<JavaPrimaryKeyJoinColumn> pkJoinColumns = primaryKeyJoinColumns(); - ListIterator<JavaResourceNode> resourcePkJoinColumns = resourcePersistentAttribute.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - while (pkJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn pkJoinColumn = pkJoinColumns.next(); - if (resourcePkJoinColumns.hasNext()) { - pkJoinColumn.update((PrimaryKeyJoinColumnAnnotation) resourcePkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(pkJoinColumn); - } - } - - while (resourcePkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(specifiedJoinColumnsSize(), buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) resourcePkJoinColumns.next())); - } - } - - - - //***************** Validation *********************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (this.getMappedBy() != null) { - addMappedByMessages(messages ,astRoot); - } - } - - @Override - protected boolean addJoinColumnMessages() { - if (containsPrimaryKeyJoinColumns() && !containsSpecifiedJoinColumns()) { - return false; - } - return super.addJoinColumnMessages(); - } - - protected void addMappedByMessages(List<IMessage> messages, CompilationUnit astRoot) { - String mappedBy = this.getMappedBy(); - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange(astRoot)) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange(astRoot)) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, this.getMappedByTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java deleted file mode 100644 index 7c0cfcd257..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaPersistentAttribute extends AbstractJavaJpaContextNode - implements JavaPersistentAttribute -{ - protected String name; - - protected JavaAttributeMapping defaultMapping; - - protected JavaAttributeMapping specifiedMapping; - - protected JavaResourcePersistentAttribute resourcePersistentAttribute; - - public GenericJavaPersistentAttribute(JavaPersistentType parent) { - super(parent); - } - - public String getId() { - return JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public void initializeFromResource(JavaResourcePersistentAttribute persistentAttributeResource) { - this.resourcePersistentAttribute = persistentAttributeResource; - this.name = this.name(persistentAttributeResource); - initializeDefaultMapping(persistentAttributeResource); - initializeSpecifiedMapping(persistentAttributeResource); - } - - protected void initializeDefaultMapping(JavaResourcePersistentAttribute persistentAttributeResource) { - this.defaultMapping = getJpaPlatform().buildDefaultJavaAttributeMapping(this); - this.defaultMapping.initializeFromResource(persistentAttributeResource); - } - - protected void initializeSpecifiedMapping(JavaResourcePersistentAttribute persistentAttributeResource) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(persistentAttributeResource); - this.specifiedMapping = createJavaAttributeMappingFromAnnotation(javaMappingAnnotationName, persistentAttributeResource); - } - - public JavaResourcePersistentAttribute getResourcePersistentAttribute() { - return this.resourcePersistentAttribute; - } - - public JavaPersistentType getPersistentType() { - return (JavaPersistentType) this.getParent(); - } - - public JavaTypeMapping getTypeMapping() { - return this.getPersistentType().getMapping(); - } - - public String getPrimaryKeyColumnName() { - return this.getMapping().getPrimaryKeyColumnName(); - } - - public boolean isOverridableAttribute() { - return this.getMapping().isOverridableAttributeMapping(); - } - - public boolean isOverridableAssociation() { - return this.getMapping().isOverridableAssociationMapping(); - } - - public boolean isIdAttribute() { - return this.getMapping().isIdMapping(); - } - - public boolean isVirtual() { - return false; - } - - public String getName() { - return this.name; - } - - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public JavaAttributeMapping getDefaultMapping() { - return this.defaultMapping; - } - - /** - * clients do not set the "default" mapping - */ - protected void setDefaultMapping(JavaAttributeMapping newDefaultMapping) { - JavaAttributeMapping oldMapping = this.defaultMapping; - this.defaultMapping = newDefaultMapping; - firePropertyChanged(PersistentAttribute.DEFAULT_MAPPING_PROPERTY, oldMapping, newDefaultMapping); - } - - public JavaAttributeMapping getSpecifiedMapping() { - return this.specifiedMapping; - } - - /** - * clients do not set the "specified" mapping; - * use #setMappingKey(String) - */ - protected void setSpecifiedMapping(JavaAttributeMapping newSpecifiedMapping) { - JavaAttributeMapping oldMapping = this.specifiedMapping; - this.specifiedMapping = newSpecifiedMapping; - firePropertyChanged(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY, oldMapping, newSpecifiedMapping); - } - - - public JavaAttributeMapping getMapping() { - return (this.specifiedMapping != null) ? this.specifiedMapping : this.defaultMapping; - } - - public String getMappingKey() { - return this.getMapping().getKey(); - } - - /** - * return null if there is no "default" mapping for the attribute - */ - public String getDefaultMappingKey() { - return this.defaultMapping.getKey(); - } - - /** - * return null if there is no "specified" mapping for the attribute - */ - public String getSpecifiedMappingKey() { - return (this.specifiedMapping == null) ? null : this.specifiedMapping.getKey(); - } - - // TODO support morphing mappings, i.e. copying common settings over - // to the new mapping; this can't be done in the same was as XmlAttributeMapping - // since we don't know all the possible mapping types - public void setSpecifiedMappingKey(String newKey) { - if (newKey == getSpecifiedMappingKey()) { - return; - } - JavaAttributeMapping oldMapping = getMapping(); - JavaAttributeMapping newMapping = createJavaAttributeMappingFromMappingKey(newKey); - - this.specifiedMapping = newMapping; - if (newMapping != null) { - this.resourcePersistentAttribute.setMappingAnnotation(newMapping.getAnnotationName()); - } - else { - this.resourcePersistentAttribute.setMappingAnnotation(null); - } - firePropertyChanged(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); - - if (oldMapping != null) { - Collection<String> annotationsToRemove = CollectionTools.collection(oldMapping.correspondingAnnotationNames()); - if (getMapping() != null) { - CollectionTools.removeAll(annotationsToRemove, getMapping().correspondingAnnotationNames()); - } - - for (String annotationName : annotationsToRemove) { - this.resourcePersistentAttribute.removeAnnotation(annotationName); - } - } - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean contains(int offset, CompilationUnit astRoot) { - TextRange fullTextRange = this.getFullTextRange(astRoot); - // 'fullTextRange' will be null if the attribute no longer exists in the java; - // the context model can be out of synch with the resource model - // when a selection event occurs before the context model has a - // chance to synch with the resource model via the update thread - return (fullTextRange == null) ? false : fullTextRange.includes(offset); - } - - - public TextRange getFullTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourcePersistentAttribute.getNameTextRange(astRoot); - } - - public TextRange getSelectionTextRange() { - return getSelectionTextRange(this.buildASTRoot()); - } - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.resourcePersistentAttribute.getJpaCompilationUnit().getCompilationUnit()); - } - - public void update(JavaResourcePersistentAttribute jrpa) { - this.resourcePersistentAttribute = jrpa; - this.setName(this.name(jrpa)); - this.updateDefaultMapping(jrpa); - this.updateSpecifiedMapping(jrpa); - } - - protected String name(JavaResourcePersistentAttribute jrpa) { - return jrpa.getName(); - } - - public String specifiedMappingAnnotationName() { - return (this.specifiedMapping == null) ? null : this.specifiedMapping.getAnnotationName(); - } - - protected void updateSpecifiedMapping(JavaResourcePersistentAttribute jrpa) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(jrpa); - if (specifiedMappingAnnotationName() != javaMappingAnnotationName) { - setSpecifiedMapping(createJavaAttributeMappingFromAnnotation(javaMappingAnnotationName, jrpa)); - } - else { - if (getSpecifiedMapping() != null) { - getSpecifiedMapping().update(jrpa); - } - } - } - - protected void updateDefaultMapping(JavaResourcePersistentAttribute jrpa) { - String defaultMappingKey = getJpaPlatform().defaultJavaAttributeMappingKey(this); - if (getDefaultMapping().getKey() != defaultMappingKey) { - JavaAttributeMapping oldDefaultMapping = this.defaultMapping; - this.defaultMapping = getJpaPlatform().buildDefaultJavaAttributeMapping(this); - this.defaultMapping.initializeFromResource(jrpa); - firePropertyChanged(PersistentAttribute.DEFAULT_MAPPING_PROPERTY, oldDefaultMapping, this.defaultMapping); - } - else { - getDefaultMapping().update(jrpa); - } - } - - protected String javaMappingAnnotationName(JavaResourcePersistentAttribute jrpa) { - Annotation mappingAnnotation = (Annotation) jrpa.getMappingAnnotation(); - if (mappingAnnotation != null) { - return mappingAnnotation.getAnnotationName(); - } - return null; - } - - protected JavaAttributeMapping createJavaAttributeMappingFromMappingKey(String key) { - if (key == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - return null; - } - return getJpaPlatform().buildJavaAttributeMappingFromMappingKey(key, this); - } - - protected JavaAttributeMapping createJavaAttributeMappingFromAnnotation(String annotationName, JavaResourcePersistentAttribute jrpa) { - if (annotationName == null) { - return null; - } - JavaAttributeMapping mapping = getJpaPlatform().buildJavaAttributeMappingFromAnnotation(annotationName, this); - mapping.initializeFromResource(jrpa); - return mapping; - } - - /** - * the mapping might be "default", but it still might be a "null" mapping... - */ - public boolean mappingIsDefault(JavaAttributeMapping mapping) { - return this.defaultMapping == mapping; - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return this.getMapping().javaCompletionProposals(pos, filter, astRoot); - } - - //************* Validation ****************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - if (this.specifiedMapping != null) { - this.specifiedMapping.addToMessages(messages, astRoot); - } - else if (this.defaultMapping != null) { - this.defaultMapping.addToMessages(messages, astRoot); - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - //nothing to dispose - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java deleted file mode 100644 index feb54cc1fc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java +++ /dev/null @@ -1,526 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.JpaFile; -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.JpaContextNode; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ChainIterator; -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.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implements JavaPersistentType -{ - protected String name; - - protected JavaTypeMapping mapping; - - protected final List<JavaPersistentAttribute> attributes; - - protected AccessType access; - - protected PersistentType parentPersistentType; - - protected JavaResourcePersistentType resourcePersistentType; - - public GenericJavaPersistentType(JpaContextNode parent, JavaResourcePersistentType resourcePersistentType) { - super(parent); - this.attributes = new ArrayList<JavaPersistentAttribute>(); - this.initialize(resourcePersistentType); - } - - @Override - public IResource getResource() { - return this.resourcePersistentType.getResourceModel().getJpaCompilationUnit().getCompilationUnit().getResource(); - } - - //****************** JpaStructureNode implementation ******************* - - public String getId() { - return JavaStructureNodes.PERSISTENT_TYPE_ID; - } - - //****************** PersistentType implementation ******************* - public String getName() { - return this.name; - } - - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public JavaTypeMapping getMapping() { - return this.mapping; - } - - public String getMappingKey() { - return getMapping().getKey(); - } - - public void setMappingKey(String key) { - if (key == getMapping().getKey()) { - return; - } - JavaTypeMapping oldMapping = getMapping(); - JavaTypeMapping newMapping = createJavaTypeMappingFromMappingKey(key); - - this.mapping = newMapping; - this.resourcePersistentType.setMappingAnnotation(newMapping.getAnnotationName()); - firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); - - if (oldMapping != null) { - Collection<String> annotationsToRemove = CollectionTools.collection(oldMapping.correspondingAnnotationNames()); - if (getMapping() != null) { - CollectionTools.removeAll(annotationsToRemove, getMapping().correspondingAnnotationNames()); - } - - for (String annotationName : annotationsToRemove) { - this.resourcePersistentType.removeAnnotation(annotationName); - } - } - } - - protected void setMapping(JavaTypeMapping newMapping) { - JavaTypeMapping oldMapping = this.mapping; - this.mapping = newMapping; - firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); - } - - public boolean isMapped() { - return getMapping().isMapped(); - } - - public AccessType getAccess() { - return this.access; - } - - protected void setAccess(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - firePropertyChanged(PersistentType.ACCESS_PROPERTY, oldAccess, newAccess); - } - - protected Iterator<JavaPersistentAttribute> attributesNamed(final String attributeName) { - return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(attributes()) { - @Override - protected boolean accept(JavaPersistentAttribute o) { - return attributeName.equals(o.getName()); - } - }; - } - - public JavaPersistentAttribute getAttributeNamed(String attributeName) { - Iterator<JavaPersistentAttribute> stream = attributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - } - - public PersistentAttribute resolveAttribute(String attributeName) { - Iterator<JavaPersistentAttribute> stream = attributesNamed(attributeName); - if (stream.hasNext()) { - JavaPersistentAttribute attribute = stream.next(); - return (stream.hasNext()) ? null /*more than one*/: attribute; - } - return (getParentPersistentType() == null) ? null : getParentPersistentType().resolveAttribute(attributeName); - } - - public ListIterator<JavaPersistentAttribute> attributes() { - return new CloneListIterator<JavaPersistentAttribute>(this.attributes); - } - - public int attributesSize() { - return this.attributes.size(); - } - - private void addAttribute(JavaPersistentAttribute attribute) { - addItemToList(attribute, this.attributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - private void removeAttribute(JavaPersistentAttribute attribute) { - removeItemFromList(attribute, this.attributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - public Iterator<String> attributeNames() { - return this.attributeNames(this.attributes()); - } - - protected Iterator<String> attributeNames(Iterator<? extends PersistentAttribute> attrs) { - return new TransformationIterator<PersistentAttribute, String>(attrs) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<PersistentType, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(PersistentType pt) { - return pt.attributes(); - } - }); - } - - public Iterator<String> allAttributeNames() { - return this.attributeNames(this.allAttributes()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - Iterator<String> values = this.mapping.javaCompletionProposals(pos, filter, astRoot); - if (values != null) { - return values; - } - for (Iterator<JavaPersistentAttribute> stream = attributes(); stream.hasNext();) { - values = stream.next().javaCompletionProposals(pos, filter, astRoot); - if (values != null) { - return values; - } - } - return EmptyIterator.instance(); - } - - // it would be nice if the we passed in an astRoot here, but then we - // would need to pass it to the XML structure nodes too... - public JpaStructureNode getStructureNode(int offset) { - CompilationUnit astRoot = this.buildASTRoot(); - - if (this.contains(offset, astRoot)) { - for (Iterator<JavaPersistentAttribute> stream = this.attributes(); stream.hasNext();) { - JavaPersistentAttribute persistentAttribute = stream.next(); - if (persistentAttribute.contains(offset, astRoot)) { - return persistentAttribute; - } - } - return this; - } - return null; - } - - protected CompilationUnit buildASTRoot() { - return JDTTools.buildASTRoot(this.resourcePersistentType.getJpaCompilationUnit().getCompilationUnit()); - } - - public boolean contains(int offset, CompilationUnit astRoot) { - TextRange fullTextRange = this.getFullTextRange(astRoot); - // 'fullTextRange' will be null if the type no longer exists in the java; - // the context model can be out of synch with the resource model - // when a selection event occurs before the context model has a - // chance to synch with the resource model via the update thread - return (fullTextRange == null) ? false : fullTextRange.includes(offset); - } - - - protected TextRange getFullTextRange(CompilationUnit astRoot) { - return this.resourcePersistentType.getTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getSelectionTextRange(astRoot); - } - - public TextRange getSelectionTextRange(CompilationUnit astRoot) { - return this.resourcePersistentType.getNameTextRange(astRoot); - } - - public TextRange getSelectionTextRange() { - return this.getSelectionTextRange(this.buildASTRoot()); - } - - - public Iterator<PersistentType> inheritanceHierarchy() { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this) { - @Override - protected PersistentType nextLink(PersistentType pt) { - return pt.getParentPersistentType(); - } - }; - } - - public PersistentType getParentPersistentType() { - return this.parentPersistentType; - } - - public void setParentPersistentType(PersistentType newParentPersistentType) { - if (attributeValueHasNotChanged(this.parentPersistentType, newParentPersistentType)) { - return; - } - PersistentType oldParentPersistentType = this.parentPersistentType; - this.parentPersistentType = newParentPersistentType; - firePropertyChanged(PersistentType.PARENT_PERSISTENT_TYPE_PROPERTY, oldParentPersistentType, newParentPersistentType); - } - - public boolean hasAnyAttributeMappingAnnotations() { - if (this.resourcePersistentType.hasAnyAttributeAnnotations()) { - return true; - } - return false; - } - - // ******************** Updating ********************** - protected void initialize(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - this.parentPersistentType = this.parentPersistentType(jrpt); - this.access = this.access(jrpt); - this.name = this.name(jrpt); - this.initializeMapping(jrpt); - this.initializePersistentAttributes(jrpt); - } - - protected void initializeMapping(JavaResourcePersistentType persistentTypeResource) { - this.mapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(this.javaMappingAnnotationName(persistentTypeResource), this); - this.mapping.initializeFromResource(persistentTypeResource); - } - - protected void initializePersistentAttributes(JavaResourcePersistentType persistentTypeResource) { - Iterator<JavaResourcePersistentAttribute> resourceAttributes = persistentTypeResource.fields(); - if (getAccess() == AccessType.PROPERTY) { - resourceAttributes = persistentTypeResource.properties(); - } - - while (resourceAttributes.hasNext()) { - this.attributes.add(createAttribute(resourceAttributes.next())); - } - } - - public void update(JavaResourcePersistentType jrpt) { - this.resourcePersistentType = jrpt; - getJpaFile(this.resourcePersistentType.getResourceModel()).addRootStructureNode(this.resourcePersistentType.getQualifiedName(), this); - updateParentPersistentType(jrpt); - updateAccess(jrpt); - updateName(jrpt); - updateMapping(jrpt); - updatePersistentAttributes(jrpt); - } - - protected void updateAccess(JavaResourcePersistentType jrpt) { - this.setAccess(this.access(jrpt)); - } - - /** - * Check the access "specified" by the java resource model. - * Check xml mapping specified access first - * If still null check java annotations if the xml is not metadata-complete = true - * If still null then set to parentPersistentType access. - * If still null check entity-mappings specified access setting if this persistent-type is listed in an orm.xml file - * If still null check the persistence-unit default Access - * Default to FIELD if all else fails. - */ - protected AccessType access(JavaResourcePersistentType jrpt) { - AccessType javaAccess = null; - boolean metadataComplete = false; - if (getOrmPersistentType() != null) { - javaAccess = getOrmPersistentType().getMapping().getSpecifiedAccess(); - metadataComplete = getOrmPersistentType().getMapping().isMetadataComplete(); - } - if (javaAccess == null && !metadataComplete) { - javaAccess = AccessType.fromJavaResourceModel(jrpt.getAccess()); - } - if (javaAccess == null) { - if (getParentPersistentType() != null) { - javaAccess = getParentPersistentType().getAccess(); - } - } - if (javaAccess == null) { - if (getEntityMappings() != null) { - javaAccess = getEntityMappings().getAccess(); - } - } - if (javaAccess == null) { - //have to check persistence-unit separately in the case where it is not listed directly in an orm.xml - //if it is listed in an orm.xml then the entityMappings().getAccess() check will cover persistence-unit.defaultAccess - if (getPersistenceUnit() != null) { - javaAccess = getPersistenceUnit().getDefaultAccess(); - } - } - if (javaAccess == null) { - javaAccess = AccessType.FIELD; - } - return javaAccess; - } - - protected void updateName(JavaResourcePersistentType jrpt) { - this.setName(this.name(jrpt)); - } - - protected String name(JavaResourcePersistentType jrpt) { - return jrpt.getQualifiedName(); - } - - protected void updateMapping(JavaResourcePersistentType jrpt) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(jrpt); - if (getMapping().getAnnotationName() != javaMappingAnnotationName) { - setMapping(createJavaTypeMappingFromAnnotation(javaMappingAnnotationName, jrpt)); - } - else { - getMapping().update(jrpt); - } - } - - protected JavaTypeMapping createJavaTypeMappingFromMappingKey(String key) { - return getJpaPlatform().buildJavaTypeMappingFromMappingKey(key, this); - } - - protected JavaTypeMapping createJavaTypeMappingFromAnnotation(String annotationName, JavaResourcePersistentType jrpt) { - JavaTypeMapping typeMapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(annotationName, this); - typeMapping.initializeFromResource(jrpt); - return typeMapping; - } - - protected String javaMappingAnnotationName(JavaResourcePersistentType jrpt) { - Annotation mappingAnnotation = (Annotation) jrpt.getMappingAnnotation(); - if (mappingAnnotation != null) { - return mappingAnnotation.getAnnotationName(); - } - return null; - } - - protected void updatePersistentAttributes(JavaResourcePersistentType jrpt) { - ListIterator<JavaPersistentAttribute> contextAttributes = attributes(); - Iterator<JavaResourcePersistentAttribute> resourceAttributes = jrpt.fields(); - if (getAccess() == AccessType.PROPERTY) { - resourceAttributes = jrpt.properties(); - } - - while (contextAttributes.hasNext()) { - JavaPersistentAttribute persistentAttribute = contextAttributes.next(); - if (resourceAttributes.hasNext()) { - persistentAttribute.update(resourceAttributes.next()); - } - else { - removeAttribute(persistentAttribute); - } - } - - while (resourceAttributes.hasNext()) { - addAttribute(createAttribute(resourceAttributes.next())); - } - } - - protected JavaPersistentAttribute createAttribute(JavaResourcePersistentAttribute persistentAttributeResource) { - JavaPersistentAttribute javaPersistentAttribute = getJpaFactory().buildJavaPersistentAttribute(this); - javaPersistentAttribute.initializeFromResource(persistentAttributeResource); - return javaPersistentAttribute; - } - - public void updateParentPersistentType(JavaResourcePersistentType persistentTypeResource) { - setParentPersistentType(parentPersistentType(persistentTypeResource)); - } - - protected PersistentType parentPersistentType(JavaResourcePersistentType persistentTypeResource) { - return parentPersistentType(persistentTypeResource.getSuperClassQualifiedName()); - } - - protected PersistentType parentPersistentType(String fullyQualifiedTypeName) { - PersistentType possibleParent = possibleParent(fullyQualifiedTypeName); - if (possibleParent == null) { - return null; - } - if (possibleParent.isMapped()) { - return possibleParent; - } - return possibleParent.getParentPersistentType(); - } - - /** - * JPA spec supports the case where there are non-persistent types in the hierarchy - * This will check for a PersistentType with the given name in this PersistenceUnit. - * If it is not found then find the JavaPersistentTypeResource and look for its parent type - */ - protected PersistentType possibleParent(String fullyQualifiedTypeName) { - PersistentType possibleParent = getPersistentType(fullyQualifiedTypeName); - if (possibleParent != null) { - return possibleParent; - } - JavaResourcePersistentType jrpt = getJpaProject().getJavaPersistentTypeResource(fullyQualifiedTypeName); - return (jrpt == null) ? null : this.possibleParent(jrpt.getSuperClassQualifiedName()); - } - - protected PersistentType getPersistentType(String fullyQualifiedTypeName) { - return getPersistenceUnit().getPersistentType(fullyQualifiedTypeName); - } - - //*************** Validation ****************************************** - public void addToMessages(List<IMessage> messages) { - //get astRoot here to pass down - addToMessages(messages, this.buildASTRoot()); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - try { - this.mapping.addToMessages(messages, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - addAttributeMessages(messages, astRoot); - } - - protected void addAttributeMessages(List<IMessage> messages, CompilationUnit astRoot) { - for (JavaPersistentAttribute persistentAttribute : this.attributes) { - try { - persistentAttribute.addToMessages(messages, astRoot); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - JpaFile jpaFile = getJpaFile(this.resourcePersistentType.getResourceModel()); - - if (jpaFile != null) { - //jpaFile can be null if the .java file was deleted, - //rootStructureNodes are cleared in the dispose of JpaFile - jpaFile.removeRootStructureNode(this.resourcePersistentType.getQualifiedName()); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java deleted file mode 100644 index 42c1f756ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - - -public class GenericJavaPrimaryKeyJoinColumn extends AbstractJavaNamedColumn<PrimaryKeyJoinColumnAnnotation> - implements JavaPrimaryKeyJoinColumn -{ - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource; - - public GenericJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner) { - super(parent, owner); - } - - @Override - public void initializeFromResource(PrimaryKeyJoinColumnAnnotation column) { - this.primaryKeyJoinColumnResource = column; - super.initializeFromResource(column); - this.specifiedReferencedColumnName = this.specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = this.defaultReferencedColumnName(); - } - - //************** JavaNamedColumn implementation *************** - @Override - public JavaBaseJoinColumn.Owner getOwner() { - return (JavaBaseJoinColumn.Owner) super.getOwner(); - } - - @Override - protected PrimaryKeyJoinColumnAnnotation getColumnResource() { - return this.primaryKeyJoinColumnResource; - } - - //************** IAbstractJoinColumn implementation *************** - - public String getReferencedColumnName() { - return (this.specifiedReferencedColumnName == null) ? this.defaultReferencedColumnName : this.specifiedReferencedColumnName; - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - protected String getTableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - public Column getDbReferencedColumn() { - Table table = this.getDbReferencedColumnTable(); - return (table == null) ? null : table.columnNamed(this.getReferencedColumnName()); - } - - public Table getDbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public boolean referencedColumnNameTouches(int pos, CompilationUnit astRoot) { - return this.getColumnResource().referencedColumnNameTouches(pos, astRoot); - } - - private Iterator<String> candidateReferencedColumnNames() { - Table table = this.getOwner().getDbReferencedColumnTable(); - return (table != null) ? table.columnNames() : EmptyIterator.<String> instance(); - } - - private Iterator<String> candidateReferencedColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateReferencedColumnNames(), filter); - } - - private Iterator<String> quotedCandidateReferencedColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateReferencedColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.referencedColumnNameTouches(pos, astRoot)) { - return this.quotedCandidateReferencedColumnNames(filter); - } - return null; - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange(CompilationUnit astRoot) { - return this.getColumnResource().getReferencedColumnNameTextRange(astRoot); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = getColumnResource().getTextRange(astRoot); - return (textRange != null) ? textRange : this.getOwner().getValidationTextRange(astRoot); - } - - @Override - public void update(PrimaryKeyJoinColumnAnnotation column) { - this.primaryKeyJoinColumnResource = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(this.specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(this.defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(PrimaryKeyJoinColumnAnnotation column) { - return column.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String defaultReferencedColumnName() { - return defaultName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java deleted file mode 100644 index e86a8de5aa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaQueryHint.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.context.java.JavaQuery; -import org.eclipse.jpt.core.context.java.JavaQueryHint; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericJavaQueryHint extends AbstractJavaJpaContextNode implements JavaQueryHint -{ - protected String name; - - protected String value; - - protected QueryHintAnnotation queryHint; - - public GenericJavaQueryHint(JavaQuery parent) { - super(parent); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryHint.setName(newName); - firePropertyChanged(QueryHint.NAME_PROPERTY, oldName, newName); - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.queryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - - public void initializeFromResource(QueryHintAnnotation queryHint) { - this.queryHint = queryHint; - this.name = queryHint.getName(); - this.value = queryHint.getValue(); - } - - public void update(QueryHintAnnotation queryHint) { - this.queryHint = queryHint; - this.setName(queryHint.getName()); - this.setValue(queryHint.getValue()); - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java deleted file mode 100644 index 3dc0480727..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSecondaryTable.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaBaseJoinColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -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; - -public class GenericJavaSecondaryTable extends AbstractJavaTable - implements JavaSecondaryTable -{ - protected final List<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected JavaPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - protected SecondaryTableAnnotation secondaryTableResource; - - public GenericJavaSecondaryTable(JavaEntity parent) { - super(parent); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<JavaPrimaryKeyJoinColumn>(); - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - //***************** AbstractJavaTable implementation ******************** - - @Override - protected String getAnnotationName() { - return SecondaryTableAnnotation.ANNOTATION_NAME; - } - - @Override - protected SecondaryTableAnnotation getTableResource() { - return this.secondaryTableResource; - } - - @Override - protected String defaultName() { - return null; - } - - //***************** ISecondaryTable implementation ******************** - - - public ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<JavaPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<JavaPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public JavaPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn newPkJoinColumn) { - JavaPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - protected ListIterator<JavaPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<JavaPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public JavaPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != 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.defaultPrimaryKeyJoinColumn = null; - } - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = this.secondaryTableResource.addPkJoinColumn(index); - primaryKeyJoinColumn.initializeFromResource(pkJoinColumnResource); - this.fireItemAdded(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn joinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(int index) { - JavaPrimaryKeyJoinColumn 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. - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(this.secondaryTableResource)); - } - this.secondaryTableResource.removePkJoinColumn(index); - fireItemRemoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(JavaPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.secondaryTableResource.movePkJoinColumn(targetIndex, sourceIndex); - fireItemMoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public JavaEntity getJavaEntity() { - return getParent(); - } - - - //********************* updating ************************ - - public void initializeFromResource(SecondaryTableAnnotation secondaryTable) { - super.initializeFromResource(secondaryTable); - this.secondaryTableResource = secondaryTable; - this.initializeSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.initializeDefaultPrimaryKeyJoinColumn(secondaryTable); - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(SecondaryTableAnnotation secondaryTable) { - ListIterator<PrimaryKeyJoinColumnAnnotation> annotations = secondaryTable.pkJoinColumns(); - - while(annotations.hasNext()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(annotations.next())); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn(SecondaryTableAnnotation secondaryTable) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(secondaryTable)); - } - - - public void update(SecondaryTableAnnotation secondaryTableResource) { - this.secondaryTableResource = secondaryTableResource; - super.update(secondaryTableResource); - this.updateSpecifiedPrimaryKeyJoinColumns(secondaryTableResource); - this.updateDefaultPrimaryKeyJoinColumn(secondaryTableResource); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(SecondaryTableAnnotation secondaryTableResource) { - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<PrimaryKeyJoinColumnAnnotation> resourcePrimaryKeyJoinColumns = secondaryTableResource.pkJoinColumns(); - - while (primaryKeyJoinColumns.hasNext()) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn(SecondaryTableAnnotation secondaryTableResource) { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumn(secondaryTableResource))); - } - else { - this.defaultPrimaryKeyJoinColumn.update(new NullPrimaryKeyJoinColumn(secondaryTableResource)); - } - } - - protected JavaPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(PrimaryKeyJoinColumnAnnotation primaryKeyJoinColumnResource) { - JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - primaryKeyJoinColumn.initializeFromResource(primaryKeyJoinColumnResource); - return primaryKeyJoinColumn; - } - - protected JavaBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = this.connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - } - } - - - //********************* code completion ************************ - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - for (JavaPrimaryKeyJoinColumn column : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - result = column.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - } - return null; - } - - public boolean isVirtual() { - return false; - } - - class PrimaryKeyJoinColumnOwner implements JavaBaseJoinColumn.Owner - { - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return GenericJavaSecondaryTable.this.getValidationTextRange(astRoot); - } - - public TypeMapping getTypeMapping() { - return GenericJavaSecondaryTable.this.getJavaEntity(); - } - - public Table getDbTable(String tableName) { - return GenericJavaSecondaryTable.this.getDbTable(); - } - - public Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericJavaSecondaryTable.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericJavaSecondaryTable.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return getJavaEntity().getPrimaryKeyColumnName(); - - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java deleted file mode 100644 index 4c406448fb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaSequenceGenerator.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; - - -public class GenericJavaSequenceGenerator extends AbstractJavaGenerator - implements JavaSequenceGenerator -{ - protected String specifiedSequenceName; - - public GenericJavaSequenceGenerator(JavaJpaContextNode parent) { - super(parent); - } - - @Override - protected SequenceGeneratorAnnotation getGeneratorResource() { - return (SequenceGeneratorAnnotation) super.getGeneratorResource(); - } - - public void initializeFromResource(SequenceGeneratorAnnotation sequenceGenerator) { - super.initializeFromResource(sequenceGenerator); - this.specifiedSequenceName = this.specifiedSequenceName(sequenceGenerator); - } - - public Integer getDefaultInitialValue() { - return SequenceGenerator.DEFAULT_INITIAL_VALUE; - } - - public String getSequenceName() { - return (this.getSpecifiedSequenceName() == null) ? getDefaultSequenceName() : this.getSpecifiedSequenceName(); - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - getGeneratorResource().setSequenceName(newSpecifiedSequenceName); - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - public String getDefaultSequenceName() { - return null; - } - - public void update(SequenceGeneratorAnnotation sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(this.specifiedSequenceName(sequenceGenerator)); - } - - protected String specifiedSequenceName(SequenceGeneratorAnnotation generatorResource) { - return generatorResource.getSequenceName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java deleted file mode 100644 index 7b22f2ad57..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTable.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaTable extends AbstractJavaTable implements JavaTable -{ - protected JavaResourcePersistentMember persistentResource; - - public GenericJavaTable(JavaEntity parent) { - super(parent); - } - - public void initializeFromResource(JavaResourcePersistentMember persistentResource) { - this.persistentResource = persistentResource; - initializeFromResource(getTableResource()); - } - - - //query for the table resource every time on setters. - //call one setter and the tableResource could change. - //You could call more than one setter before this object has received any notification - //from the java resource model - @Override - protected TableAnnotation getTableResource() { - //TODO get the NullTable from the resource model or build it here in the context model?? - return (TableAnnotation) this.persistentResource.getNonNullAnnotation(getAnnotationName()); - } - - @Override - protected String getAnnotationName() { - return TableAnnotation.ANNOTATION_NAME; - } - - @Override - public JavaEntity getParent() { - return (JavaEntity) super.getParent(); - } - - protected JavaEntity getJavaEntity() { - return getParent(); - } - - protected Entity getRootEntity() { - return getJavaEntity().getRootEntity(); - } - - @Override - /** - * Table name default to the owning java entity name. - * If this entity is part of a single table inheritance hierarchy, table - * name defaults to the root entity's table name. - */ - protected String defaultName() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getName(); - } - } - return getJavaEntity().getName(); - } - - @Override - protected String defaultSchema() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getSchema(); - } - } - return super.defaultSchema(); - } - - @Override - protected String defaultCatalog() { - if (getJavaEntity().getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (getRootEntity() != getJavaEntity()) { - return getRootEntity().getTable().getCatalog(); - } - } - return super.defaultCatalog(); - } - - public void update(JavaResourcePersistentMember persistentResource) { - this.persistentResource = persistentResource; - this.update(getTableResource()); - } - - //******************* validation ********************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - boolean doContinue = this.connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange(astRoot)) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java deleted file mode 100644 index 63d687771d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTableGenerator.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -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.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericJavaTableGenerator extends AbstractJavaGenerator - implements JavaTableGenerator, UniqueConstraint.Owner -{ - - protected String specifiedTable; - - protected String defaultTable; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected String specifiedSchema; - - protected String defaultSchema; - - protected String specifiedPkColumnName; - - protected String defaultPkColumnName; - - protected String specifiedValueColumnName; - - protected String defaultValueColumnName; - - protected String specifiedPkColumnValue; - - protected String defaultPkColumnValue; - - protected final List<JavaUniqueConstraint> uniqueConstraints; - - public GenericJavaTableGenerator(JavaJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<JavaUniqueConstraint>(); - } - - @Override - protected TableGeneratorAnnotation getGeneratorResource() { - return (TableGeneratorAnnotation) super.getGeneratorResource(); - } - - public Integer getDefaultInitialValue() { - return TableGenerator.DEFAULT_INITIAL_VALUE; - } - - 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; - getGeneratorResource().setTable(newSpecifiedTable); - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getGeneratorResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - 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); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getGeneratorResource().setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getPkColumnName() { - return (this.getSpecifiedPkColumnName() == null) ? getDefaultPkColumnName() : this.getSpecifiedPkColumnName(); - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - getGeneratorResource().setPkColumnName(newSpecifiedPkColumnName); - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - protected void setSpecifiedPkColumnName_(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - public String getValueColumnName() { - return (this.getSpecifiedValueColumnName() == null) ? getDefaultValueColumnName() : this.getSpecifiedValueColumnName(); - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - getGeneratorResource().setValueColumnName(newSpecifiedValueColumnName); - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - protected void setSpecifiedValueColumnName_(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - public String getPkColumnValue() { - return (this.getSpecifiedPkColumnValue() == null) ? getDefaultPkColumnValue() : this.getSpecifiedPkColumnValue(); - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - getGeneratorResource().setPkColumnValue(newSpecifiedPkColumnValue); - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public void setSpecifiedPkColumnValue_(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public String getDefaultPkColumnValue() { - return this.defaultPkColumnValue; - } - - - // ********** unique constraints ********** - - public ListIterator<JavaUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<JavaUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public JavaUniqueConstraint addUniqueConstraint(int index) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - this.uniqueConstraints.add(index, uniqueConstraint); - UniqueConstraintAnnotation uniqueConstraintAnnotation = this.getGeneratorResource().addUniqueConstraint(index); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - fireItemAdded(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - JavaUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - this.getGeneratorResource().removeUniqueConstraint(index); - fireItemRemoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getGeneratorResource().moveUniqueConstraint(targetIndex, sourceIndex); - fireItemMoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - protected void addUniqueConstraint(int index, JavaUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - protected void removeUniqueConstraint_(JavaUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - - // ********** java resource model -> java context model ********** - - public void initializeFromResource(TableGeneratorAnnotation tableGenerator) { - super.initializeFromResource(tableGenerator); - this.specifiedTable = this.specifiedTable(tableGenerator); - this.specifiedCatalog = this.specifiedCatalog(tableGenerator); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedSchema = this.specifiedSchema(tableGenerator); - this.defaultSchema = this.defaultSchema(); - this.specifiedPkColumnName = this.specifiedPkColumnName(tableGenerator); - this.specifiedValueColumnName = this.specifiedValueColumnName(tableGenerator); - this.specifiedPkColumnValue = this.specifiedPkColumnValue(tableGenerator); - this.initializeUniqueConstraints(tableGenerator); - } - - protected void initializeUniqueConstraints(TableGeneratorAnnotation tableGenerator) { - for (UniqueConstraintAnnotation uniqueConstraintAnnotation : CollectionTools.iterable(tableGenerator.uniqueConstraints())) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraintAnnotation)); - } - } - - public void update(TableGeneratorAnnotation tableGenerator) { - super.update(tableGenerator); - this.setSpecifiedTable_(this.specifiedTable(tableGenerator)); - this.setSpecifiedCatalog_(this.specifiedCatalog(tableGenerator)); - this.setDefaultCatalog(this.defaultCatalog()); - this.setSpecifiedSchema_(this.specifiedSchema(tableGenerator)); - this.setDefaultSchema(this.defaultSchema()); - this.setSpecifiedPkColumnName_(this.specifiedPkColumnName(tableGenerator)); - this.setSpecifiedValueColumnName_(this.specifiedValueColumnName(tableGenerator)); - this.setSpecifiedPkColumnValue_(this.specifiedPkColumnValue(tableGenerator)); - this.updateUniqueConstraints(tableGenerator); - } - - protected void updateUniqueConstraints(TableGeneratorAnnotation tableGenerator) { - ListIterator<JavaUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<UniqueConstraintAnnotation> resourceUniqueConstraints = tableGenerator.uniqueConstraints(); - - while (uniqueConstraints.hasNext()) { - JavaUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected JavaUniqueConstraint buildUniqueConstraint(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - JavaUniqueConstraint uniqueConstraint = getJpaFactory().buildJavaUniqueConstraint(this, this); - uniqueConstraint.initialize(uniqueConstraintAnnotation); - return uniqueConstraint; - } - - protected String specifiedTable(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getTable(); - } - - protected String specifiedCatalog(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getCatalog(); - } - - protected String specifiedSchema(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getSchema(); - } - - protected String specifiedPkColumnName(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getPkColumnName(); - } - - protected String specifiedValueColumnName(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getValueColumnName(); - } - - protected String specifiedPkColumnValue(TableGeneratorAnnotation tableGenerator) { - return tableGenerator.getPkColumnValue(); - } - - protected String defaultSchema() { - if (getEntityMappings() != null) { - return getEntityMappings().getSchema(); - } - return getPersistenceUnit().getDefaultSchema(); - } - - protected String defaultCatalog() { - if (getEntityMappings() != null) { - return getEntityMappings().getCatalog(); - } - return getPersistenceUnit().getDefaultCatalog(); - } - - public Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.tableNamed(this.getTable()); - } - - public Schema getDbSchema() { - return this.getDatabase().schemaNamed(this.getSchema()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java deleted file mode 100644 index d7d919db68..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaTransientMapping.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaTransientMapping; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaTransientMapping extends AbstractJavaAttributeMapping<TransientAnnotation> - implements JavaTransientMapping -{ - public GenericJavaTransientMapping(JavaPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return TransientAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java deleted file mode 100644 index 47332c31f3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaUniqueConstraint.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.java; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; - -public class GenericJavaUniqueConstraint extends AbstractJavaJpaContextNode - implements JavaUniqueConstraint -{ - - protected final List<String> columnNames; - - protected UniqueConstraintAnnotation uniqueConstraintAnnotation; - - protected Owner owner; - public GenericJavaUniqueConstraint(JavaJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - this.columnNames = new ArrayList<String>(); - } - - public Owner getOwner() { - return this.owner; - } - - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(int index, String columnName) { - this.columnNames.add(index, columnName); - this.uniqueConstraintAnnotation.addColumnName(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - protected void addColumnName_(int index, String columnName) { - this.columnNames.add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - public void removeColumnName(String columnName) { - this.removeColumnName(this.columnNames.indexOf(columnName)); - } - - public void removeColumnName(int index) { - String removedColumnName = this.columnNames.remove(index); - this.uniqueConstraintAnnotation.removeColumnName(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - protected void removeColumnName_(int index) { - String removedColumnName = this.columnNames.remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - CollectionTools.move(this.columnNames, targetIndex, sourceIndex); - this.uniqueConstraintAnnotation.moveColumnName(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public void initialize(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - this.uniqueConstraintAnnotation = uniqueConstraintAnnotation; - this.initializeColumnNames(uniqueConstraintAnnotation); - } - - protected void initializeColumnNames(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - ListIterator<String> annotationColumnNames = uniqueConstraintAnnotation.columnNames(); - - for (String annotationColumnName : CollectionTools.iterable(annotationColumnNames)) { - this.columnNames.add(annotationColumnName); - } - } - - public void update(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - this.uniqueConstraintAnnotation = uniqueConstraintAnnotation; - this.updateColumnNames(uniqueConstraintAnnotation); - } - - protected void updateColumnNames(UniqueConstraintAnnotation uniqueConstraintAnnotation) { - ListIterator<String> annotationColumnNames = uniqueConstraintAnnotation.columnNames(); - - int index = 0; - for (String annotationColumnName : CollectionTools.iterable(annotationColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != annotationColumnName) { - addColumnName_(index, annotationColumnName); - } - } - else { - addColumnName_(index, annotationColumnName); - } - index++; - } - - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); - } - } - - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.uniqueConstraintAnnotation.getTextRange(astRoot); - } - - private boolean columnNamesTouches(int pos, CompilationUnit astRoot) { - return this.uniqueConstraintAnnotation.columnNamesTouches(pos, astRoot); - } - - private Iterator<String> candidateColumnNames() { - return this.getOwner().candidateUniqueConstraintColumnNames(); - } - - private Iterator<String> candidateColumnNames(Filter<String> filter) { - return new FilteringIterator<String, String>(this.candidateColumnNames(), filter); - } - - private Iterator<String> quotedCandidateColumnNames(Filter<String> filter) { - return StringTools.quote(this.candidateColumnNames(filter)); - } - - @Override - public Iterator<String> connectedJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.connectedJavaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - if (this.columnNamesTouches(pos, astRoot)) { - return this.quotedCandidateColumnNames(filter); - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java deleted file mode 100644 index 36e7f873a3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaVersionMapping.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.java.JavaColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericJavaVersionMapping extends AbstractJavaAttributeMapping<VersionAnnotation> implements JavaVersionMapping -{ - protected final JavaColumn column; - - protected TemporalType temporal; - - public GenericJavaVersionMapping(JavaPersistentAttribute parent) { - super(parent); - this.column = createJavaColumn(); - } - - protected JavaColumn createJavaColumn() { - return getJpaFactory().buildJavaColumn(this, this); - } - - @Override - public void initializeFromResource(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.initializeFromResource(resourcePersistentAttribute); - this.column.initializeFromResource(this.getColumnResource()); - this.temporal = this.temporal(this.temporalResource()); - } - - protected TemporalAnnotation temporalResource() { - return (TemporalAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(TemporalAnnotation.ANNOTATION_NAME); - } - - public ColumnAnnotation getColumnResource() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); - } - - //************** IJavaAttributeMapping implementation *************** - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - - public Iterator<String> correspondingAnnotationNames() { - return new ArrayIterator<String>( - JPA.COLUMN, - JPA.TEMPORAL); - } - - //************** INamedColumn.Owner implementation *************** - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - //************** IVersionMapping implementation *************** - - public JavaColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.temporalResource().setValue(TemporalType.toJavaResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - @Override - public void update(JavaResourcePersistentAttribute resourcePersistentAttribute) { - super.update(resourcePersistentAttribute); - this.column.update(this.getColumnResource()); - this.setTemporal(this.temporal(this.temporalResource())); - } - - protected TemporalType temporal(TemporalAnnotation temporal) { - return TemporalType.fromJavaResourceModel(temporal.getValue()); - } - - @Override - public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { - Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - result = this.getColumn().javaCompletionProposals(pos, filter, astRoot); - if (result != null) { - return result; - } - return null; - } - - //*********** Validation ****************************** - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - super.addToMessages(messages, astRoot); - - addColumnMessages(messages, astRoot); - } - - protected void addColumnMessages(List<IMessage> messages, CompilationUnit astRoot) { - JavaColumn column = this.getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && column.connectionProfileIsActive(); - - if (doContinue && this.getTypeMapping().tableNameIsInvalid(table)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, column.getTableTextRange(astRoot)) - ); - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, column.getNameTextRange(astRoot)) - ); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java deleted file mode 100644 index 3c37d7b648..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; - -public class JavaBasicMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaBasicMappingProvider INSTANCE = new JavaBasicMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaBasicMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return BasicAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaBasicMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getResourcePersistentAttribute().typeIsBasic(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java deleted file mode 100644 index e7a21e46f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaCascade.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.java.JavaRelationshipMapping; -import org.eclipse.jpt.core.resource.java.RelationshipMappingAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - -public class JavaCascade extends AbstractJavaJpaContextNode implements Cascade -{ - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - protected RelationshipMappingAnnotation relationshipMapping; - - protected JavaCascade(JavaRelationshipMapping parent) { - super(parent); - } - - public boolean isAll() { - return this.all; - } - - public void setAll(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - this.relationshipMapping.setCascadeAll(newAll); - firePropertyChanged(Cascade.ALL_PROPERTY, oldAll, newAll); - } - - public boolean isPersist() { - return this.persist; - } - - public void setPersist(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - this.relationshipMapping.setCascadePersist(newPersist); - firePropertyChanged(Cascade.PERSIST_PROPERTY, oldPersist, newPersist); - } - - public boolean isMerge() { - return this.merge; - } - - public void setMerge(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - this.relationshipMapping.setCascadeMerge(newMerge); - firePropertyChanged(Cascade.MERGE_PROPERTY, oldMerge, newMerge); - } - - public boolean isRemove() { - return this.remove; - } - - public void setRemove(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - this.relationshipMapping.setCascadeRemove(newRemove); - firePropertyChanged(Cascade.REMOVE_PROPERTY, oldRemove, newRemove); - } - - public boolean isRefresh() { - return this.refresh; - } - - public void setRefresh(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - this.relationshipMapping.setCascadeRefresh(newRefresh); - firePropertyChanged(Cascade.REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.relationshipMapping.getCascadeTextRange(astRoot); - } - - public void initialize(RelationshipMappingAnnotation relationshipMapping) { - this.relationshipMapping = relationshipMapping; - this.all = relationshipMapping.isCascadeAll(); - this.persist = relationshipMapping.isCascadePersist(); - this.merge = relationshipMapping.isCascadeMerge(); - this.remove = relationshipMapping.isCascadeRemove(); - this.refresh = relationshipMapping.isCascadeRefresh(); - } - - public void update(RelationshipMappingAnnotation relationshipMapping) { - this.relationshipMapping = relationshipMapping; - this.setAll(relationshipMapping.isCascadeAll()); - this.setPersist(relationshipMapping.isCascadePersist()); - this.setMerge(relationshipMapping.isCascadeMerge()); - this.setRemove(relationshipMapping.isCascadeRemove()); - this.setRefresh(relationshipMapping.isCascadeRefresh()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java deleted file mode 100644 index 3f8567367a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEmbeddable; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; - -public class JavaEmbeddableProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaEmbeddableProvider INSTANCE = new JavaEmbeddableProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddableProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddableAnnotation.ANNOTATION_NAME; - } - - public JavaEmbeddable buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaEmbeddable(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java deleted file mode 100644 index bc30accc8f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedIdMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; - -public class JavaEmbeddedIdMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaEmbeddedIdMappingProvider INSTANCE = new JavaEmbeddedIdMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddedIdMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedIdAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaEmbeddedIdMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return MappingTools.getEmbeddableFor(persistentAttribute) != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java deleted file mode 100644 index fdd6f131ed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; - -public class JavaEmbeddedMappingProvider - implements DefaultJavaAttributeMappingProvider -{ - - // singleton - private static final JavaEmbeddedMappingProvider INSTANCE = new JavaEmbeddedMappingProvider(); - - /** - * Return the singleton. - */ - public static DefaultJavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEmbeddedMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EmbeddedAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaEmbeddedMapping(parent); - } - - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { - return MappingTools.getEmbeddableFor(persistentAttribute) != null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java deleted file mode 100644 index 7114a094ac..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; - -/** - * - */ -public class JavaEntityProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaEntityProvider INSTANCE = new JavaEntityProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEntityProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return EntityAnnotation.ANNOTATION_NAME; - } - - public JavaEntity buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaEntity(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java deleted file mode 100644 index 42db79746b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.IdAnnotation; - -public class JavaIdMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaIdMappingProvider INSTANCE = new JavaIdMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaIdMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaIdMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java deleted file mode 100644 index 028370fbfa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToManyMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; - -public class JavaManyToManyMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaManyToManyMappingProvider INSTANCE = new JavaManyToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaManyToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToManyAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaManyToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java deleted file mode 100644 index 757a9c1b42..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaManyToOneMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; - -public class JavaManyToOneMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaManyToOneMappingProvider INSTANCE = new JavaManyToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaManyToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return ManyToOneAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaManyToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java deleted file mode 100644 index 8f3317cc07..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; - -public class JavaMappedSuperclassProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaMappedSuperclassProvider INSTANCE = new JavaMappedSuperclassProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaMappedSuperclassProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public String getAnnotationName() { - return MappedSuperclassAnnotation.ANNOTATION_NAME; - } - - public JavaMappedSuperclass buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaMappedSuperclass(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java deleted file mode 100644 index cd209b7683..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullAttributeMappingProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; - -/** - * This mapping provider implementation is used to create a JavaNullAttributeMapping. - * A JavaNullAttributeMapping should be used when no "mapping" annotation - * exists on a Java attribute *and* no default mapping applies. - */ -public class JavaNullAttributeMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaNullAttributeMappingProvider INSTANCE = new JavaNullAttributeMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaNullAttributeMappingProvider() { - super(); - } - - public String getKey() { - return null; - } - - public String getAnnotationName() { - return null; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaNullAttributeMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java deleted file mode 100644 index b3067e7e93..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class JavaNullTypeMapping extends AbstractJavaTypeMapping -{ - public JavaNullTypeMapping(JavaPersistentType parent) { - super(parent); - } - - public String getAnnotationName() { - return null; - } - - public String getKey() { - return MappingKeys.NULL_TYPE_MAPPING_KEY; - } - - public boolean isMapped() { - return false; - } - - public Iterator<String> correspondingAnnotationNames() { - return EmptyIterator.instance(); - } - - @Override - public void addToMessages(List<IMessage> messages, CompilationUnit astRoot) { - //Adding this message here because the likely solution is to add an annotation to the java file. - //This message used to be found on the <class> tag in the persistence.xml. The other possible - //way to fix the error is to remove it from the persistnce.xml. This can be accomplished - //with the Synchronize Classes action. We could also add a quick fix for this error. - messages.add(DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_INVALID_CLASS, - new String[] { this.getPersistentType().getName() }, - this, - this.getValidationTextRange(astRoot))); - } - - @Override - public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.getPersistentType().getValidationTextRange(astRoot); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java deleted file mode 100644 index bcc6313964..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMappingProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; - -/** - * This mapping provider implementation is used to create a JavaNullAttributeMapping. - * A JavaNullAttributeMapping should be used when no "mapping" annotation - * exists on a Java type. - */ -public class JavaNullTypeMappingProvider - implements JavaTypeMappingProvider -{ - - // singleton - private static final JavaNullTypeMappingProvider INSTANCE = new JavaNullTypeMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaTypeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaNullTypeMappingProvider() { - super(); - } - - public String getKey() { - return null; - } - - public String getAnnotationName() { - return null; - } - - public JavaTypeMapping buildMapping(JavaPersistentType parent, JpaFactory factory) { - return factory.buildJavaNullTypeMapping(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java deleted file mode 100644 index 15b91f8a6c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToManyMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; - -public class JavaOneToManyMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaOneToManyMappingProvider INSTANCE = new JavaOneToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaOneToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToManyAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaOneToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java deleted file mode 100644 index 319b9ef298..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaOneToOneMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; - -public class JavaOneToOneMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaOneToOneMappingProvider INSTANCE = new JavaOneToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaOneToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return OneToOneAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaOneToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java deleted file mode 100644 index 4fb5aa294e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaTransientMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; - -public class JavaTransientMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaTransientMappingProvider INSTANCE = new JavaTransientMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaTransientMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return TransientAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaTransientMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java deleted file mode 100644 index c17edb669e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaVersionMappingProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.java; - -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; - -public class JavaVersionMappingProvider - implements JavaAttributeMappingProvider -{ - - // singleton - private static final JavaVersionMappingProvider INSTANCE = new JavaVersionMappingProvider(); - - /** - * Return the singleton. - */ - public static JavaAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaVersionMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return VersionAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaVersionMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java deleted file mode 100644 index efbc1d16ae..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverride.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; -import org.eclipse.jpt.core.utility.TextRange; - - -public class VirtualAttributeOverride extends AbstractJavaResourceNode implements AttributeOverrideAnnotation, Annotation -{ - private final VirtualAttributeOverrideColumn column; - - private String name; - - public VirtualAttributeOverride(JavaResourceNode parent, String name, Column column) { - super(parent); - this.name = name; - this.column = new VirtualAttributeOverrideColumn(this, column); - } - - public void initialize(CompilationUnit astRoot) { - //null, nothing to initialize - } - - public org.eclipse.jdt.core.dom.Annotation getJdtAnnotation(CompilationUnit astRoot) { - return null; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public String getAnnotationName() { - return AttributeOverrideAnnotation.ANNOTATION_NAME; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - if (name != null) { - createAttributeOverrideResource().setName(name); - } - } - - public ColumnAnnotation getNonNullColumn() { - return getColumn(); - } - - public ColumnAnnotation getColumn() { - return this.column; - } - - public ColumnAnnotation addColumn() { - throw new UnsupportedOperationException(); - } - - public void removeColumn() { - throw new UnsupportedOperationException(); - } - - @Override - public JavaResourcePersistentMember getParent() { - return (JavaResourcePersistentMember) super.getParent(); - } - - protected AttributeOverrideAnnotation createAttributeOverrideResource() { - return (AttributeOverrideAnnotation) getParent().addAnnotation(getAnnotationName()); - } - - public void updateFromJava(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - - } - - public boolean nameTouches(int pos, CompilationUnit astRoot) { - return false; - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java deleted file mode 100644 index 3f0e8eff56..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideColumn.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.internal.resource.java.NullBaseColumn; -import org.eclipse.jpt.core.resource.java.Annotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.utility.TextRange; - - -public class VirtualAttributeOverrideColumn extends NullBaseColumn implements ColumnAnnotation, Annotation -{ - private Column column; - - public VirtualAttributeOverrideColumn(AttributeOverrideAnnotation parent, Column column) { - super(parent); - this.column = column; - } - - @Override - public AttributeOverrideAnnotation getParent() { - return (AttributeOverrideAnnotation) super.getParent(); - } - - public String getAnnotationName() { - return ColumnAnnotation.ANNOTATION_NAME; - } - - @Override - protected ColumnAnnotation createColumnResource() { - return getParent().addColumn(); - } - - @Override - public String getName() { - if (this.column.getSpecifiedName() != null) { - return this.column.getSpecifiedName(); - } - return null; - } - - @Override - public String getTable() { - if (this.column.getSpecifiedTable() != null) { - return this.column.getSpecifiedTable(); - } - return null; - } - - @Override - public Boolean getInsertable() { - if (this.column.getSpecifiedInsertable() != null) { - return this.column.getSpecifiedInsertable(); - } - return null; - } - - @Override - public Boolean getUpdatable() { - if (this.column.getSpecifiedUpdatable() != null) { - return this.column.getSpecifiedUpdatable(); - } - return null; - } - @Override - public Boolean getNullable() { - if (this.column.getSpecifiedNullable() != null) { - return this.column.getSpecifiedNullable(); - } - return null; - } - - @Override - public Boolean getUnique() { - if (this.column.getSpecifiedUnique() != null) { - return this.column.getSpecifiedUnique(); - } - return null; - } - - @Override - public String getColumnDefinition() { - return this.column.getColumnDefinition(); - } - - public Integer getLength() { - if (this.column.getSpecifiedLength() != null) { - return this.column.getSpecifiedLength(); - } - return null; - } - - public void setLength(Integer length) { - if (length != null) { - createColumnResource().setLength(length); - } - } - - public Integer getScale() { - if (this.column.getSpecifiedScale() != null) { - return this.column.getSpecifiedScale(); - } - return null; - } - - public void setScale(Integer scale) { - if (scale != null) { - createColumnResource().setScale(scale); - } - } - - public Integer getPrecision() { - if (this.column.getSpecifiedPrecision() != null) { - return this.column.getSpecifiedPrecision(); - } - return null; - } - - public void setPrecision(Integer precision) { - if (precision != null) { - createColumnResource().setPrecision(precision); - } - } - - public TextRange getScaleTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getLengthTextRange(CompilationUnit astRoot) { - return null; - } - - public TextRange getPrecisionTextRange(CompilationUnit astRoot) { - return null; - } -} 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 ec1153a0bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.NonOwningMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -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.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -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.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> extends AbstractOrmJpaContextNode - implements OrmAttributeMapping -{ - protected String name; - - protected T attributeMapping; - - protected JavaPersistentAttribute javaPersistentAttribute; - - protected AbstractOrmAttributeMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public JavaPersistentAttribute getJavaPersistentAttribute() { - return this.javaPersistentAttribute; - } - - protected void setJavaPersistentAttribute(JavaPersistentAttribute newJavaPersistentAttribute) { - JavaPersistentAttribute oldJavaPersistentAttribute = this.javaPersistentAttribute; - this.javaPersistentAttribute = newJavaPersistentAttribute; - firePropertyChanged(OrmAttributeMapping.JAVA_PERSISTENT_ATTRIBUTE_PROPERTY, oldJavaPersistentAttribute, newJavaPersistentAttribute); - - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.attributeMapping.setName(newName); - firePropertyChanged(OrmAttributeMapping.NAME_PROPERTY, oldName, newName); - getPersistentAttribute().nameChanged(oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(OrmAttributeMapping.NAME_PROPERTY, oldName, newName); - getPersistentAttribute().nameChanged(oldName, newName); - } - - public OrmPersistentAttribute getPersistentAttribute() { - return (OrmPersistentAttribute) getParent(); - } - - public String getAttributeName() { - return this.getPersistentAttribute().getName(); - } - - public boolean isDefault() { - return false; - } - - public void initializeFromOrmAttributeMapping(OrmAttributeMapping oldMapping) { - setName(oldMapping.getName()); - } - - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - initializeFromOrmAttributeMapping((OrmAttributeMapping) oldMapping); - } - - public void initializeFromOrmBasicMapping(OrmBasicMapping oldMapping) { - initializeFromXmlColumnMapping(oldMapping); - } - - public void initializeFromOrmIdMapping(OrmIdMapping oldMapping) { - initializeFromXmlColumnMapping(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) { - initializeFromXmlColumnMapping(oldMapping); - } - - public void initializeFromXmlRelationshipMapping(OrmRelationshipMapping oldMapping) { - initializeFromOrmAttributeMapping(oldMapping); - } - - public void initializeFromXmlMulitRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - initializeFromXmlRelationshipMapping(oldMapping); - } - - public void initializeFromXmlSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - initializeFromXmlRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToManyMapping(OrmOneToManyMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlMulitRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToOneMapping(OrmManyToOneMapping oldMapping) { - initializeFromXmlSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmOneToOneMapping(OrmOneToOneMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlSingleRelationshipMapping(oldMapping); - } - - public void initializeFromOrmManyToManyMapping(OrmManyToManyMapping oldMapping) { - initializeFromXmlNonOwningMapping(oldMapping); - initializeFromXmlMulitRelationshipMapping(oldMapping); - } - - public String getPrimaryKeyColumnName() { - return null; - } - - public OrmTypeMapping getTypeMapping() { - return this.getPersistentAttribute().getTypeMapping(); - } - - - public boolean isOverridableAttributeMapping() { - return false; - } - - public boolean isOverridableAssociationMapping() { - return false; - } - - public boolean isIdMapping() { - return false; - } - - protected T getAttributeMapping() { - return this.attributeMapping; - } - - public void initialize(T attributeMapping) { - this.attributeMapping = attributeMapping; - this.name = attributeMapping.getName(); - this.javaPersistentAttribute = findJavaPersistentAttribute(); - } - - public void update(T attributeMapping) { - this.attributeMapping = attributeMapping; - this.setName_(attributeMapping.getName()); - this.setJavaPersistentAttribute(findJavaPersistentAttribute()); - } - - protected JavaPersistentAttribute findJavaPersistentAttribute() { - JavaPersistentType javaPersistentType = getPersistentAttribute().getPersistentType().getJavaPersistentType(); - if (javaPersistentType != null && getName() != null) { - return javaPersistentType.getAttributeNamed(getName()); - } - return null; - } - - - protected boolean entityOwned() { - return getTypeMapping().getKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public boolean contains(int textOffset) { - return this.attributeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.attributeMapping.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return (this.getPersistentAttribute().isVirtual()) ? this.getTypeMapping().getAttributesTextRange() : this.attributeMapping.getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.attributeMapping.getNameTextRange(); - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addAttributeMessages(messages); - addInvalidMappingMessage(messages); - } - - protected void addAttributeMessages(List<IMessage> messages) { - addUnspecifiedAttributeMessage(messages); - addUnresolvedAttributeMessage(messages); - addModifierMessages(messages); - } - - protected void addUnspecifiedAttributeMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME, - this, - getValidationTextRange()) - ); - } - } - - protected void addUnresolvedAttributeMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getName()) - && findJavaPersistentAttribute() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME, - new String[] {getName(), getPersistentAttribute().getPersistentType().getMapping().getClass_()}, - this, - getNameTextRange()) - ); - } - } - - protected void addModifierMessages(List<IMessage> messages) { - if (getKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if (getJavaPersistentAttribute() == null) { - return; - } - JavaResourcePersistentAttribute resourcePersistentAttribute = getJavaPersistentAttribute().getResourcePersistentAttribute(); - - if (resourcePersistentAttribute.isForField()) { - //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. - if (resourcePersistentAttribute.isFinal()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, - new String[] {getName()}, - getPersistentAttribute(), - getPersistentAttribute().getValidationTextRange()) - ); - } - - if (resourcePersistentAttribute.isPublic()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, - new String[] {getName()}, - getPersistentAttribute(), - getPersistentAttribute().getValidationTextRange()) - ); - - } - } - } - - //TODO validation message - i think more info is needed in this message. include type mapping type? - protected void addInvalidMappingMessage(List<IMessage> messages) { - if (! getTypeMapping().attributeMappingKeyAllowed(getKey())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_MAPPING, - new String[] {getName()}, - 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 6c15616ef3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseColumn.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.BaseColumn; -import org.eclipse.jpt.core.context.orm.OrmBaseColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlAbstractColumn; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractOrmBaseColumn<T extends XmlAbstractColumn> 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(OrmJpaContextNode 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); -// } - - 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 (oldSpecifiedTable != newSpecifiedTable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setTable(newSpecifiedTable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedTable != null) { - addColumnResource(); - getColumnResource().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 getUnique() { - return (this.getSpecifiedUnique() == null) ? this.getDefaultUnique() : this.getSpecifiedUnique(); - } - - public Boolean getDefaultUnique() { - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getSpecifiedUnique() { - return this.specifiedUnique; - } - - public void setSpecifiedUnique(Boolean newSpecifiedUnique) { - Boolean oldSpecifiedUnique = this.specifiedUnique; - this.specifiedUnique = newSpecifiedUnique; - if (oldSpecifiedUnique != newSpecifiedUnique) { - if (this.getColumnResource() != null) { - this.getColumnResource().setUnique(newSpecifiedUnique); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedUnique != null) { - addColumnResource(); - getColumnResource().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 getNullable() { - return (this.getSpecifiedNullable() == null) ? this.getDefaultNullable() : this.getSpecifiedNullable(); - } - - public Boolean getDefaultNullable() { - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getSpecifiedNullable() { - return this.specifiedNullable; - } - - public void setSpecifiedNullable(Boolean newSpecifiedNullable) { - Boolean oldSpecifiedNullable = this.specifiedNullable; - this.specifiedNullable = newSpecifiedNullable; - if (oldSpecifiedNullable != newSpecifiedNullable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setNullable(newSpecifiedNullable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedNullable != null) { - addColumnResource(); - getColumnResource().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 getInsertable() { - return (this.getSpecifiedInsertable() == null) ? this.getDefaultInsertable() : this.getSpecifiedInsertable(); - } - - public Boolean getDefaultInsertable() { - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getSpecifiedInsertable() { - return this.specifiedInsertable; - } - - public void setSpecifiedInsertable(Boolean newSpecifiedInsertable) { - Boolean oldSpecifiedInsertable = this.specifiedInsertable; - this.specifiedInsertable = newSpecifiedInsertable; - if (oldSpecifiedInsertable != newSpecifiedInsertable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setInsertable(newSpecifiedInsertable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedInsertable != null) { - addColumnResource(); - getColumnResource().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 getUpdatable() { - return (this.getSpecifiedUpdatable() == null) ? this.getDefaultUpdatable() : this.getSpecifiedUpdatable(); - } - - public Boolean getDefaultUpdatable() { - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getSpecifiedUpdatable() { - return this.specifiedUpdatable; - } - - public void setSpecifiedUpdatable(Boolean newSpecifiedUpdatable) { - Boolean oldSpecifiedUpdatable = this.specifiedUpdatable; - this.specifiedUpdatable = newSpecifiedUpdatable; - if (oldSpecifiedUpdatable != newSpecifiedUpdatable) { - if (this.getColumnResource() != null) { - this.getColumnResource().setUpdatable(newSpecifiedUpdatable); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedUpdatable != null) { - addColumnResource(); - getColumnResource().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); - } - - @Override - protected String tableName() { - return this.getTable(); - } - - - public TextRange getTableTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getTableTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - @Override - protected void initialize(T column) { - super.initialize(column); - this.specifiedTable = this.specifiedTable(column); - this.defaultTable = this.defaultTable(); - //TODO default from java for all of these settings - this.specifiedNullable = this.specifiedNullable(column); - this.specifiedUpdatable = this.specifiedUpdatable(column); - this.specifiedUnique = this.specifiedUnique(column); - this.specifiedInsertable = this.specifiedInsertable(column); - } - - @Override - protected void update(T column) { - super.update(column); - setSpecifiedTable_(this.specifiedTable(column)); - setDefaultTable(this.defaultTable()); - setSpecifiedNullable_(this.specifiedNullable(column)); - setSpecifiedUpdatable_(this.specifiedUpdatable(column)); - setSpecifiedUnique_(this.specifiedUnique(column)); - setSpecifiedInsertable_(this.specifiedInsertable(column)); - } - - protected String specifiedTable(T column) { - return column == null ? null : column.getTable(); - } - - protected Boolean specifiedNullable(T column) { - return column == null ? null : column.getNullable(); - } - - protected Boolean specifiedUpdatable(T column) { - return column == null ? null : column.getUpdatable(); - } - - protected Boolean specifiedUnique(T column) { - return column == null ? null : column.getUnique(); - } - - protected Boolean specifiedInsertable(T column) { - return column == null ? null : column.getInsertable(); - } - - protected String defaultTable() { - return getOwner().getDefaultTableName(); - } - -} 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 aa9c1baa60..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ /dev/null @@ -1,361 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.BaseEmbeddedMapping; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBaseEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.java.AbstractJavaBaseEmbeddedMapping; -import org.eclipse.jpt.core.resource.orm.BaseXmlEmbedded; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -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; - - -public abstract class AbstractOrmBaseEmbeddedMapping<T extends BaseXmlEmbedded> extends AbstractOrmAttributeMapping<T> implements OrmBaseEmbeddedMapping -{ - protected final List<OrmAttributeOverride> specifiedAttributeOverrides; - - protected final List<OrmAttributeOverride> virtualAttributeOverrides; - - private Embeddable embeddable; - - protected AbstractOrmBaseEmbeddedMapping(OrmPersistentAttribute parent) { - super(parent); - this.specifiedAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - } - - @Override - public void initializeFromOrmBaseEmbeddedMapping(OrmBaseEmbeddedMapping oldMapping) { - super.initializeFromOrmBaseEmbeddedMapping(oldMapping); - int index = 0; - for (OrmAttributeOverride attributeOverride : CollectionTools.iterable(oldMapping.specifiedAttributeOverrides())) { - OrmAttributeOverride newAttributeOverride = addSpecifiedAttributeOverride(index++); - newAttributeOverride.setName(attributeOverride.getName()); - newAttributeOverride.getColumn().initializeFrom(attributeOverride.getColumn()); - } - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAttributeOverride> attributeOverrides() { - return new CompositeListIterator<OrmAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<OrmAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.virtualAttributeOverrides); - } - protected void addVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - public ListIterator<OrmAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected OrmAttributeOverride addSpecifiedAttributeOverride(int index) { - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride attributeOverride = buildAttributeOverride(xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, attributeOverride); - this.getAttributeMapping().getAttributeOverrides().add(index, xmlAttributeOverride); - this.fireItemAdded(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - return attributeOverride; - } - - protected void addSpecifiedAttributeOverride(int index, OrmAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.getAttributeMapping().getAttributeOverrides().move(targetIndex, sourceIndex); - fireItemMoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverride getAttributeOverrideNamed(String name) { - return (OrmAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - protected BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(overrides)) { - String overrideName = override.getName(); - if (overrideName == null && name == null) { - return override; - } - if (overrideName != null && overrideName.equals(name)) { - return override; - } - } - return null; - } - - //****************** AttributeOverride.Owner implemenation ******************* - - public boolean isVirtual(BaseOverride override) { - return this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // Add a new attribute override - if (virtual) { - return setVirtual((OrmAttributeOverride) override); - } - return setSpecified((OrmAttributeOverride) override); - } - - protected OrmAttributeOverride setVirtual(OrmAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - OrmAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(attributeOverrideName); - } - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - } - } - } - - getAttributeMapping().getAttributeOverrides().remove(index); - fireItemRemoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected OrmAttributeOverride setSpecified(OrmAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride newAttributeOverride = getJpaFactory().buildOrmAttributeOverride(this, this, xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - getAttributeMapping().getAttributeOverrides().add(xmlAttributeOverride); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - public ColumnMapping getColumnMapping(String attributeName) { - return MappingTools.getColumnMapping(attributeName, getEmbeddable()); - } - - public Embeddable getEmbeddable() { - return this.embeddable; - } - - public Iterator<String> allOverridableAttributeNames() { - return new TransformationIterator<PersistentAttribute, String>(this.allOverridableAttributes()) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - if (this.getEmbeddable() == null) { - return EmptyIterator.instance(); - } - return new FilteringIterator<PersistentAttribute, PersistentAttribute>(this.getEmbeddable().getPersistentType().attributes()) { - @Override - protected boolean accept(PersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - public AbstractJavaBaseEmbeddedMapping<?> getJavaEmbeddedMapping() { - JavaPersistentAttribute javaPersistentAttribute = getJavaPersistentAttribute(); - if (javaPersistentAttribute != null && javaPersistentAttribute.getMappingKey() == getKey()) { - return (AbstractJavaBaseEmbeddedMapping<?>) javaPersistentAttribute.getMapping(); - } - return null; - } - - @Override - public void initialize(T embedded) { - super.initialize(embedded); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); - this.initializeSpecifiedAttributeOverrides(embedded); - this.initializeVirtualAttributeOverrides(); - } - - protected void initializeSpecifiedAttributeOverrides(T embedded) { - for (XmlAttributeOverride attributeOverride : embedded.getAttributeOverrides()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride(attributeOverride)); - } - } - - protected void initializeVirtualAttributeOverrides() { - if (getPersistentAttribute().isVirtual()) { - //specifiedAttributeOverrides are used if the persistentAttribute is virtual - return; - } - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - OrmAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(persistentAttribute.getName()); - } - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - - protected OrmAttributeOverride buildVirtualAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - return buildAttributeOverride(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - - protected XmlAttributeOverride buildVirtualXmlAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - XmlColumn xmlColumn; - if (javaAttributeOverride == null) { - ColumnMapping columnMapping = (ColumnMapping) persistentAttribute.getMapping(); - xmlColumn = new VirtualXmlColumn(getTypeMapping(), columnMapping.getColumn(), false); - } - else { - xmlColumn = new VirtualXmlColumn(getTypeMapping(), javaAttributeOverride.getColumn(), true); - } - return new VirtualXmlAttributeOverride(persistentAttribute.getName(), xmlColumn); - } - - protected OrmAttributeOverride buildAttributeOverride(XmlAttributeOverride attributeOverride) { - return getJpaFactory().buildOrmAttributeOverride(this, this, attributeOverride); - } - - @Override - public void update(T embedded) { - super.update(embedded); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); - this.updateSpecifiedAttributeOverrides(embedded); - this.updateVirtualAttributeOverrides(); - } - - protected void updateSpecifiedAttributeOverrides(T embedded) { - ListIterator<OrmAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<XmlAttributeOverride> resourceAttributeOverrides = new CloneListIterator<XmlAttributeOverride>(embedded.getAttributeOverrides());//prevent ConcurrentModificiationException - - while (attributeOverrides.hasNext()) { - OrmAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update(resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride(resourceAttributeOverrides.next())); - } - } - - protected void updateVirtualAttributeOverrides() { - Iterator<PersistentAttribute> overridableAttributes = allOverridableAttributes(); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = virtualAttributeOverrides(); - - if (!getPersistentAttribute().isVirtual()) { - //specifiedAttributeOverrides are used if the persistentAttribute is virtual - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(overridableAttributes)) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (ormAttributeOverride != null && !ormAttributeOverride.isVirtual()) { - continue; - } - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEmbeddedMapping() != null) { - javaAttributeOverride = getJavaEmbeddedMapping().getAttributeOverrideNamed(persistentAttribute.getName()); - } - if (ormAttributeOverride != null) { - if (virtualAttributeOverrides.hasNext()) { - OrmAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - virtualAttributeOverride.update(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - for (OrmAttributeOverride virtualAttributeOverride : CollectionTools.iterable(virtualAttributeOverrides)) { - removeVirtualAttributeOverride(virtualAttributeOverride); - } - - } - - //************ static methods ************ - - public static Embeddable embeddableFor(JavaPersistentAttribute javaPersistentAttribute) { - if (javaPersistentAttribute == null) { - return null; - } - return MappingTools.getEmbeddableFor(javaPersistentAttribute); - } -} 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 048751dafa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmGenerator.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.java.JavaGenerator; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlGenerator; -import org.eclipse.jpt.core.utility.TextRange; - - -public abstract class AbstractOrmGenerator<T extends XmlGenerator> extends AbstractOrmJpaContextNode - implements OrmGenerator -{ - - protected String name; - - protected Integer specifiedInitialValue; - protected Integer defaultInitialValue; - - protected Integer specifiedAllocationSize; - protected Integer defaultAllocationSize; - - protected T generatorResource; - - protected AbstractOrmGenerator(OrmJpaContextNode parent) { - super(parent); - } - - public boolean isVirtual() { - return getGeneratorResource().isVirtual(); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - getGeneratorResource().setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public Integer getInitialValue() { - return (this.getSpecifiedInitialValue() == null) ? this.getDefaultInitialValue() : this.getSpecifiedInitialValue(); - } - - public Integer getSpecifiedInitialValue() { - return this.specifiedInitialValue; - } - - public void setSpecifiedInitialValue(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - getGeneratorResource().setInitialValue(newSpecifiedInitialValue); - firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - protected void setSpecifiedInitialValue_(Integer newSpecifiedInitialValue) { - Integer oldSpecifiedInitialValue = this.specifiedInitialValue; - this.specifiedInitialValue = newSpecifiedInitialValue; - firePropertyChanged(SPECIFIED_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newSpecifiedInitialValue); - } - - public Integer getDefaultInitialValue() { - return this.defaultInitialValue; - } - - protected void setDefaultInitialValue(Integer newDefaultInitialValue) { - Integer oldSpecifiedInitialValue = this.defaultInitialValue; - this.defaultInitialValue = newDefaultInitialValue; - firePropertyChanged(DEFAULT_INITIAL_VALUE_PROPERTY, oldSpecifiedInitialValue, newDefaultInitialValue); - } - - public Integer getAllocationSize() { - return (this.getSpecifiedAllocationSize() == null) ? this.getDefaultAllocationSize() : this.getSpecifiedAllocationSize(); - } - - public Integer getSpecifiedAllocationSize() { - return this.specifiedAllocationSize; - } - - public void setSpecifiedAllocationSize(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - getGeneratorResource().setAllocationSize(newSpecifiedAllocationSize); - firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - protected void setSpecifiedAllocationSize_(Integer newSpecifiedAllocationSize) { - Integer oldSpecifiedAllocationSize = this.specifiedAllocationSize; - this.specifiedAllocationSize = newSpecifiedAllocationSize; - firePropertyChanged(SPECIFIED_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newSpecifiedAllocationSize); - } - - public Integer getDefaultAllocationSize() { - return this.defaultAllocationSize; - } - - protected void setDefaultAllocationSize(Integer newDefaultAllocationSize) { - Integer oldSpecifiedAllocationSize = this.defaultAllocationSize; - this.defaultAllocationSize = newDefaultAllocationSize; - firePropertyChanged(DEFAULT_ALLOCATION_SIZE_PROPERTY, oldSpecifiedAllocationSize, newDefaultAllocationSize); - } - - - public void initialize(T generatorResource) { - this.generatorResource = generatorResource; - this.name = this.name(generatorResource); - this.specifiedInitialValue = this.specifiedInitialValue(generatorResource); - this.specifiedAllocationSize = this.specifiedAllocationSize(generatorResource); - //TODO defaults - } - - public void update(T generatorResource) { - this.generatorResource = generatorResource; - this.setName_(this.name(generatorResource)); - this.setSpecifiedInitialValue_(this.specifiedInitialValue(generatorResource)); - this.setSpecifiedAllocationSize_(this.specifiedAllocationSize(generatorResource)); - //TODO defaults - } - - public boolean overrides(Generator generator) { - if (getName() == null) { - return false; - } - // this isn't ideal, but it will have to do until we have further adopter input - return this.getName().equals(generator.getName()) && generator instanceof JavaGenerator; - } - - protected T getGeneratorResource() { - return this.generatorResource; - } - - protected String name(XmlGenerator generatorResource) { - return generatorResource.getName(); - } - - protected Integer specifiedInitialValue(XmlGenerator generatorResource) { - return generatorResource.getInitialValue(); - } - - protected Integer specifiedAllocationSize(XmlGenerator generatorResource) { - return generatorResource.getAllocationSize(); - } - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.getGeneratorResource().getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - TextRange nameTextRange = this.getGeneratorResource().getNameTextRange(); - return nameTextRange != null ? nameTextRange : getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java deleted file mode 100644 index 6041d883b5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmJpaContextNode.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaNode; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractOrmJpaContextNode extends AbstractJpaContextNode implements OrmJpaContextNode -{ - // ********** constructor ********** - - protected AbstractOrmJpaContextNode(JpaNode parent) { - super(parent); - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List<IMessage>)} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages) { - - } - -} 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 e283baf41b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ /dev/null @@ -1,374 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.FetchType; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.MapKey; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlMultiRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmMultiRelationshipMapping<T extends XmlMultiRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> - implements OrmMultiRelationshipMapping -{ - - protected String mappedBy; - - protected String orderBy;//TODO change this to defaultOrderBy and specifiedOrderBy? - - protected boolean isNoOrdering; - - protected boolean isPkOrdering; - - protected boolean isCustomOrdering; - - protected final OrmJoinTable joinTable; - - protected String mapKey; - - protected AbstractOrmMultiRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.joinTable = getJpaFactory().buildOrmJoinTable(this); - } - - @Override - public void initializeFromXmlMulitRelationshipMapping(OrmMultiRelationshipMapping oldMapping) { - super.initializeFromXmlMulitRelationshipMapping(oldMapping); - getJoinTable().initializeFrom(oldMapping.getJoinTable()); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - public FetchType getDefaultFetch() { - return MultiRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - getAttributeMapping().setMappedBy(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public String getOrderBy() { - return this.orderBy; - } - - public void setOrderBy(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - getAttributeMapping().setOrderBy(newOrderBy); - firePropertyChanged(ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - protected void setOrderBy_(String newOrderBy) { - String oldOrderBy = this.orderBy; - this.orderBy = newOrderBy; - firePropertyChanged(ORDER_BY_PROPERTY, oldOrderBy, newOrderBy); - } - - public boolean isNoOrdering() { - return this.isNoOrdering; - } - - public void setNoOrdering(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - if (newNoOrdering) { - getAttributeMapping().setOrderBy(null); - } - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - protected void setNoOrdering_(boolean newNoOrdering) { - boolean oldNoOrdering = this.isNoOrdering; - this.isNoOrdering = newNoOrdering; - firePropertyChanged(NO_ORDERING_PROPERTY, oldNoOrdering, newNoOrdering); - } - - public boolean isPkOrdering() { - return this.isPkOrdering; - } - - public void setPkOrdering(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - if (newPkOrdering) { - getAttributeMapping().setOrderBy(""); - } - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - protected void setPkOrdering_(boolean newPkOrdering) { - boolean oldPkOrdering = this.isPkOrdering; - this.isPkOrdering = newPkOrdering; - firePropertyChanged(PK_ORDERING_PROPERTY, oldPkOrdering, newPkOrdering); - } - - public boolean isCustomOrdering() { - return this.isCustomOrdering; - } - - public void setCustomOrdering(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - if (newCustomOrdering) { - setOrderBy(""); - } - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - protected void setCustomOrdering_(boolean newCustomOrdering) { - boolean oldCustomOrdering = this.isCustomOrdering; - this.isCustomOrdering = newCustomOrdering; - firePropertyChanged(CUSTOM_ORDERING_PROPERTY, oldCustomOrdering, newCustomOrdering); - } - - public OrmJoinTable getJoinTable() { - return this.joinTable; - } - - public boolean isJoinTableSpecified() { - return getJoinTable().isSpecified(); - } - - public String getMapKey() { - return this.mapKey; - } - - public void setMapKey(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - if (oldMapKey != newMapKey) { - if (this.getMapKeyResource() != null) { - this.getMapKeyResource().setName(newMapKey); - if (this.getMapKeyResource().isAllFeaturesUnset()) { - removeMapKeyResource(); - } - } - else if (newMapKey != null) { - addMapKeyResource(); - getMapKeyResource().setName(newMapKey); - } - } - firePropertyChanged(MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected void setMapKey_(String newMapKey) { - String oldMapKey = this.mapKey; - this.mapKey = newMapKey; - firePropertyChanged(MAP_KEY_PROPERTY, oldMapKey, newMapKey); - } - - protected MapKey getMapKeyResource() { - return getAttributeMapping().getMapKey(); - } - - protected void removeMapKeyResource() { - getAttributeMapping().setMapKey(null); - } - - protected void addMapKeyResource() { - getAttributeMapping().setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - } - - public Iterator<String> candidateMapKeyNames() { - return this.allTargetEntityAttributeNames(); - } - -// public void refreshDefaults(DefaultsContext defaultsContext) { -// super.refreshDefaults(defaultsContext); -// // TODO -// // if (isOrderByPk()) { -// // refreshDefaultOrderBy(defaultsContext); -// // } -// } -// -// //primary key ordering when just the @OrderBy annotation is present -// protected void refreshDefaultOrderBy(DefaultsContext defaultsContext) { -// IEntity targetEntity = getResolvedTargetEntity(); -// if (targetEntity != null) { -// setOrderBy(targetEntity.primaryKeyAttributeName() + " ASC"); -// } -// } -// -// //TODO copied from JavaMultiRelationshipMapping -// /** -// * extract the element type from the specified container signature and -// * convert it into a reference entity type name; -// * return null if the type is not a valid reference entity type (e.g. it's -// * another container or an array or a primitive or other Basic type) -// */ -// @Override -// protected String javaDefaultTargetEntity(ITypeBinding typeBinding) { -// String typeName = super.javaDefaultTargetEntity(typeBinding); -// return JavaRelationshipMapping.typeNamedIsContainer(typeName) ? this.javaDefaultTargetEntityFromContainer(typeBinding) : null; -// } -// -// protected String javaDefaultTargetEntityFromContainer(ITypeBinding typeBinding) { -// return JavaMultiRelationshipMapping.javaDefaultTargetEntityFromContainer(typeBinding); -// } - - public TextRange getMappedByTextRange() { - TextRange mappedByTextRange = getAttributeMapping().getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getValidationTextRange(); - } - - @Override - public void initialize(T multiRelationshipMapping) { - super.initialize(multiRelationshipMapping); - this.mappedBy = multiRelationshipMapping.getMappedBy(); - this.mapKey = this.mapKey(multiRelationshipMapping); - this.orderBy = this.orderBy(multiRelationshipMapping); - if (this.orderBy == null) { - this.isNoOrdering = true; - } - else { - this.isCustomOrdering = true; - } - this.joinTable.initialize(multiRelationshipMapping); - } - - @Override - public void update(T multiRelationshipMapping) { - super.update(multiRelationshipMapping); - this.setMappedBy_(multiRelationshipMapping.getMappedBy()); - this.setMapKey_(this.mapKey(multiRelationshipMapping)); - this.setOrderBy_(this.orderBy(multiRelationshipMapping)); - if (getOrderBy() == null) { - setNoOrdering_(true); - setPkOrdering_(false); - setCustomOrdering_(false); - } - else { - setNoOrdering_(false); - setPkOrdering_(false); - setCustomOrdering_(true); - } - this.joinTable.update(multiRelationshipMapping); - } - - protected String mapKey(T multiRelationshipMapping) { - return multiRelationshipMapping.getMapKey() == null ? null : multiRelationshipMapping.getMapKey().getName(); - } - - protected String orderBy(T multiRelationshipMapping) { - return multiRelationshipMapping.getOrderBy(); - } - - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource) { - if (!persistentAttributeResource.typeIsContainer()) { - return null; - } - return persistentAttributeResource.getQualifiedReferenceEntityElementTypeName(); - } - - //****************** validation ******************8 - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned() && (this.isJoinTableSpecified() || isRelationshipOwner())) { - getJoinTable().addToMessages(messages); - } - if (getMappedBy() != null) { - addMappedByMessages(messages); - } - } - - protected void addMappedByMessages(List<IMessage> messages) { - if (isJoinTableSpecified()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_WITH_JOIN_TABLE, - getJoinTable(), - getJoinTable().getValidationTextRange()) - ); - } - - if (getResolvedTargetEntity() == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = getResolvedTargetEntity().getPersistentType().resolveAttribute(getMappedBy()); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {getMappedBy()}, - this, - getMappedByTextRange()) - ); - return; - } - - if (! mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {getMappedBy()}, - this, - getMappedByTextRange()) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, - getMappedByTextRange()) - ); - } - } -} 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 f07f27ee7c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmNamedColumn.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.NamedColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.XmlNamedColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; - - -public abstract class AbstractOrmNamedColumn<T extends XmlNamedColumn> extends AbstractOrmJpaContextNode - implements OrmNamedColumn -{ - protected Owner owner; - - protected String specifiedName; - - protected String defaultName; - - protected String columnDefinition; - - protected AbstractOrmNamedColumn(OrmJpaContextNode parent, Owner owner) { - super(parent); - this.owner = owner; - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public void initializeFrom(NamedColumn oldColumn) { - setSpecifiedName(oldColumn.getSpecifiedName()); - setColumnDefinition(oldColumn.getColumnDefinition()); - } - - protected abstract T getColumnResource(); - - protected abstract void removeColumnResource(); - - protected abstract void addColumnResource(); - - 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 (oldSpecifiedName != newSpecifiedName) { - if (this.getColumnResource() != null) { - this.getColumnResource().setName(newSpecifiedName); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedName != null) { - addColumnResource(); - getColumnResource().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 (oldColumnDefinition != newColumnDefinition) { - if (this.getColumnResource() != null) { - this.getColumnResource().setColumnDefinition(newColumnDefinition); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newColumnDefinition != null) { - addColumnResource(); - getColumnResource().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.columnNamed(getName()); - } - - public Table getDbTable() { - return getOwner().getDbTable(this.tableName()); - } - - protected abstract String tableName(); - - public boolean isResolved() { - return getDbColumn() != null; - } - - public TextRange getNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - TextRange textRange = getColumnResource().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - return getOwner().getValidationTextRange(); - } - - - // ******************* initialization from orm xml resource model ******************** - - protected void initialize(T column) { - this.specifiedName = this.specifiedName(column); - this.defaultName = this.defaultName(); - this.columnDefinition = this.specifiedColumnDefinition(column); - } - - protected void update(T column) { - setSpecifiedName_(this.specifiedName(column)); - setDefaultName(this.defaultName()); - setColumnDefinition_(this.specifiedColumnDefinition(column)); - } - - protected String specifiedName(T column) { - return column == null ? null : column.getName(); - } - - protected String specifiedColumnDefinition(T column) { - return column == null ? null : column.getColumnDefinition(); - } - - /** - * Return the default column name. - */ - protected String defaultName() { - return this.getOwner().getDefaultColumnName(); - } - - -}
\ No newline at end of file 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 a3cf36ff69..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmQuery.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.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.java.JavaQuery; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -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.iterators.CloneListIterator; - - -public abstract class AbstractOrmQuery<E extends XmlQuery> extends AbstractOrmJpaContextNode - implements OrmQuery -{ - - protected String name; - - protected String query; - - protected final List<OrmQueryHint> hints; - - protected E queryResource; - - protected AbstractOrmQuery(OrmJpaContextNode parent) { - super(parent); - this.hints = new ArrayList<OrmQueryHint>(); - } - - protected E getQueryResource() { - return this.queryResource; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.getQueryResource().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.getQueryResource().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) { - OrmQueryHint queryHint = getJpaFactory().buildOrmQueryHint(this); - this.hints.add(index, queryHint); - this.getQueryResource().getHints().add(index, OrmFactory.eINSTANCE.createXmlQueryHint()); - this.fireItemAdded(Query.HINTS_LIST, index, queryHint); - return queryHint; - } - - protected void addHint(int index, OrmQueryHint queryHint) { - addItemToList(index, queryHint, this.hints, Query.HINTS_LIST); - } - - public void removeHint(QueryHint queryHint) { - removeHint(this.hints.indexOf(queryHint)); - } - - public void removeHint(int index) { - OrmQueryHint queryHint = this.hints.remove(index); - this.queryResource.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.queryResource.getHints().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.hints, Query.HINTS_LIST); - - } - - - public void initialize(E queryResource) { - this.queryResource = queryResource; - this.name = queryResource.getName(); - this.query = queryResource.getQuery(); - this.initializeHints(queryResource); - } - - protected void initializeHints(E queryResource) { - for (XmlQueryHint queryhint : queryResource.getHints()) { - this.hints.add(createHint(queryhint)); - } - } - - protected OrmQueryHint createHint(XmlQueryHint queryHint) { - OrmQueryHint ormQueryHint = getJpaFactory().buildOrmQueryHint(this); - ormQueryHint.initialize(queryHint); - return ormQueryHint; - } - - public void update(E queryResource) { - this.queryResource = queryResource; - this.setName(queryResource.getName()); - this.setQuery(queryResource.getQuery()); - this.updateHints(queryResource); - } - - protected void updateHints(E queryResource) { - ListIterator<OrmQueryHint> hints = hints(); - ListIterator<XmlQueryHint> resourceHints = new CloneListIterator<XmlQueryHint>(queryResource.getHints());//prevent ConcurrentModificiationException - - while (hints.hasNext()) { - OrmQueryHint hint = hints.next(); - if (resourceHints.hasNext()) { - hint.update(resourceHints.next()); - } - else { - removeHint_(hint); - } - } - - while (resourceHints.hasNext()) { - addHint(hintsSize(), createHint(resourceHints.next())); - } - } - - public boolean overrides(Query query) { - if (getName() == null) { - return false; - } - // this isn't ideal, but it will have to do until we have further adopter input - return this.getName().equals(query.getName()) && query instanceof JavaQuery; - } - - public TextRange getValidationTextRange() { - return this.getQueryResource().getValidationTextRange(); - } - - public TextRange getNameTextRange() { - return this.getQueryResource().getNameTextRange(); - } -} 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 941670e156..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public abstract class AbstractOrmRelationshipMapping<T extends XmlRelationshipMapping> extends AbstractOrmAttributeMapping<T> - implements OrmRelationshipMapping -{ - - protected String specifiedTargetEntity; - - protected String defaultTargetEntity; - - protected Entity resolvedTargetEntity; - - protected FetchType specifiedFetch; - - protected final OrmCascade cascade; - - - protected AbstractOrmRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.cascade = new OrmCascade(this); - } - - public String getTargetEntity() { - return (this.getSpecifiedTargetEntity() == null) ? getDefaultTargetEntity() : this.getSpecifiedTargetEntity(); - } - - public String getSpecifiedTargetEntity() { - return this.specifiedTargetEntity; - } - - public void setSpecifiedTargetEntity(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - getAttributeMapping().setTargetEntity(newSpecifiedTargetEntity); - firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - protected void setSpecifiedTargetEntity_(String newSpecifiedTargetEntity) { - String oldSpecifiedTargetEntity = this.specifiedTargetEntity; - this.specifiedTargetEntity = newSpecifiedTargetEntity; - firePropertyChanged(SPECIFIED_TARGET_ENTITY_PROPERTY, oldSpecifiedTargetEntity, newSpecifiedTargetEntity); - } - - public String getDefaultTargetEntity() { - return this.defaultTargetEntity; - } - - protected void setDefaultTargetEntity(String newDefaultTargetEntity) { - String oldDefaultTargetEntity = this.defaultTargetEntity; - this.defaultTargetEntity = newDefaultTargetEntity; - firePropertyChanged(DEFAULT_TARGET_ENTITY_PROPERTY, oldDefaultTargetEntity, newDefaultTargetEntity); - } - - public Entity getResolvedTargetEntity() { - return this.resolvedTargetEntity; - } - - protected void setResolvedTargetEntity(Entity newResolvedTargetEntity) { - Entity oldResolvedTargetEntity = this.resolvedTargetEntity; - this.resolvedTargetEntity = newResolvedTargetEntity; - firePropertyChanged(RESOLVED_TARGET_ENTITY_PROPERTY, oldResolvedTargetEntity, newResolvedTargetEntity); - } - - public FetchType getFetch() { - return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); - } - - public FetchType getSpecifiedFetch() { - return this.specifiedFetch; - } - - public void setSpecifiedFetch(FetchType newSpecifiedFetch) { - FetchType oldFetch = this.specifiedFetch; - this.specifiedFetch = newSpecifiedFetch; - this.getAttributeMapping().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 OrmCascade getCascade() { - return this.cascade; - } - - - @Override - public void initializeFromXmlRelationshipMapping(OrmRelationshipMapping oldMapping) { - super.initializeFromXmlRelationshipMapping(oldMapping); - setSpecifiedTargetEntity(oldMapping.getSpecifiedTargetEntity()); - setSpecifiedFetch(oldMapping.getSpecifiedFetch()); - getCascade().initializeFrom(oldMapping.getCascade()); - //TODO should we set the fetch type from a BasicMapping?? - } - - public Iterator<String> allTargetEntityAttributeNames() { - Entity targetEntity = this.getResolvedTargetEntity(); - return (targetEntity == null) ? EmptyIterator.<String> instance() : targetEntity.getPersistentType().allAttributeNames(); - } - - public Iterator<String> candidateMappedByAttributeNames() { - return this.allTargetEntityAttributeNames(); - } - - public Entity getEntity() { - if (getTypeMapping() instanceof Entity) { - return (Entity) getTypeMapping(); - } - return null; - } - - public boolean targetEntityIsValid(String targetEntity) { - return MappingTools.targetEntityIsValid(targetEntity); - } - - @Override - public void initialize(T relationshipMapping) { - super.initialize(relationshipMapping); - this.specifiedTargetEntity = relationshipMapping.getTargetEntity(); - this.defaultTargetEntity = this.defaultTargetEntity(); - this.resolvedTargetEntity = this.resolveTargetEntity(); - this.specifiedFetch = this.specifiedFetch(relationshipMapping); - this.cascade.initialize(relationshipMapping); - } - - @Override - public void update(T relationshipMapping) { - super.update(relationshipMapping); - this.setSpecifiedTargetEntity_(relationshipMapping.getTargetEntity()); - this.setDefaultTargetEntity(this.defaultTargetEntity()); - this.setResolvedTargetEntity(this.resolveTargetEntity()); - this.setSpecifiedFetch_(this.specifiedFetch(relationshipMapping)); - this.cascade.update(relationshipMapping); - } - - protected FetchType specifiedFetch(XmlRelationshipMapping relationshipMapping) { - return FetchType.fromOrmResourceModel(relationshipMapping.getFetch()); - } - - protected RelationshipMapping javaRelationshipMapping() { - if (findJavaPersistentAttribute() == null) { - return null; - } - AttributeMapping javaAttributeMapping = findJavaPersistentAttribute().getMapping(); - if (javaAttributeMapping instanceof RelationshipMapping) { - return ((RelationshipMapping) javaAttributeMapping); - } - return null; - } - - protected String defaultTargetEntity() { - RelationshipMapping javaMapping = javaRelationshipMapping(); - if (javaMapping != null) { - if (getPersistentAttribute().isVirtual() && !getTypeMapping().isMetadataComplete()) { - return javaMapping.getTargetEntity(); - } - } - if (findJavaPersistentAttribute() != null) { - return defaultTargetEntity(findJavaPersistentAttribute().getResourcePersistentAttribute()); - } - return null; - } - - protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource); - - protected Entity resolveTargetEntity() { - if (getTargetEntity() == null) { - return null; - } - PersistentType persistentType = getTargetPersistentType(); - if (persistentType != null && persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; - } - - protected PersistentType getTargetPersistentType() { - // try to resolve by only the locally specified name - PersistentType persistentType = getPersistenceUnit().getPersistentType(getTargetEntity()); - if (persistentType == null) { - // try to resolve by prepending the global package name - persistentType = getPersistenceUnit().getPersistentType(getEntityMappings().getPackage() + "." + getTargetEntity()); - } - return persistentType; - } -} 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 5b02eba937..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.SingleRelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlSingleRelationshipMapping; -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.CloneListIterator; -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; - - -public abstract class AbstractOrmSingleRelationshipMapping<T extends XmlSingleRelationshipMapping> - extends AbstractOrmRelationshipMapping<T> implements OrmSingleRelationshipMapping -{ - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected OrmJoinColumn defaultJoinColumn; - - protected Boolean specifiedOptional; - - protected AbstractOrmSingleRelationshipMapping(OrmPersistentAttribute parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - } - - @Override - public void initializeFromXmlSingleRelationshipMapping(OrmSingleRelationshipMapping oldMapping) { - super.initializeFromXmlSingleRelationshipMapping(oldMapping); - int index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldMapping.specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - public FetchType getDefaultFetch() { - return SingleRelationshipMapping.DEFAULT_FETCH_TYPE; - } - - //***************** ISingleRelationshipMapping implementation ***************** - public ListIterator<OrmJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - 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; - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn oldDefaultJoinColumn = this.getDefaultJoinColumn(); - 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 xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - OrmJoinColumn joinColumn = buildJoinColumn(xmlJoinColumn); - this.specifiedJoinColumns.add(index, joinColumn); - this.getAttributeMapping().getJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - if (oldDefaultJoinColumn != null) { - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, oldDefaultJoinColumn, null); - } - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //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 = buildJoinColumn(null); - } - this.getAttributeMapping().getJoinColumns().remove(index); - fireItemRemoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(SingleRelationshipMapping.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getAttributeMapping().getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public Boolean getOptional() { - return getSpecifiedOptional() == null ? getDefaultOptional() : getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - getAttributeMapping().setOptional(newSpecifiedOptional); - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - protected void setSpecifiedOptional_(Boolean newSpecifiedOptional) { - Boolean oldSpecifiedOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - firePropertyChanged(Nullable.SPECIFIED_OPTIONAL_PROPERTY, oldSpecifiedOptional, newSpecifiedOptional); - } - - @Override - public void initialize(T singleRelationshipMapping) { - super.initialize(singleRelationshipMapping); - this.specifiedOptional = singleRelationshipMapping.getOptional(); - //TODO defaultOptional - this.initializeSpecifiedJoinColumns(singleRelationshipMapping); - this.initializeDefaultJoinColumn(); - } - - protected void initializeSpecifiedJoinColumns(T singleRelationshipMapping) { - if (singleRelationshipMapping == null) { - return; - } - for (XmlJoinColumn joinColumn : singleRelationshipMapping.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(joinColumn)); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns() && isRelationshipOwner(); - } - - protected void initializeDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(null); - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - @Override - public void update(T singleRelationshipMapping) { - super.update(singleRelationshipMapping); - this.setSpecifiedOptional_(singleRelationshipMapping.getOptional()); - this.updateSpecifiedJoinColumns(singleRelationshipMapping); - this.updateDefaultJoinColumn(); - } - - protected void updateSpecifiedJoinColumns(T singleRelationshipMapping) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = EmptyListIterator.instance(); - if (singleRelationshipMapping != null) { - resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(singleRelationshipMapping.getJoinColumns());//prevent ConcurrentModificiationException - } - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected void updateDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(null)); - } - else { - this.defaultJoinColumn.update(null); - } - } - - /** - * eliminate any "container" types - */ - @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource) { - if (persistentAttributeResource.typeIsContainer()) { - return null; - } - return persistentAttributeResource.getQualifiedReferenceEntityTypeName(); - } - - //********************* validation ****************** - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (addJoinColumnMessages()) { - addJoinColumnMessages(messages); - } - } - - //bug 192287 - do not want joinColumn validation errors on the non-owning side - //of a bidirectional relationship. This is a low risk fix for RC3, but a better - //solution would be to not have the default joinColumns on the non-owning side. - //This would fix another bug that we show default joinColumns in this situation. - protected boolean addJoinColumnMessages() { - return (entityOwned() && isRelationshipOwner()); - } - - protected void addJoinColumnMessages(List<IMessage> messages) { - boolean doContinue = this.connectionProfileIsActive(); - - for (OrmJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - String table = joinColumn.getTable(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_TABLE, - new String[] {table, joinColumn.getName()}, - joinColumn, - joinColumn.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! joinColumn.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getName()}, - joinColumn, - joinColumn.getNameTextRange()) - ); - } - } - - if (doContinue && ! joinColumn.isReferencedColumnResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_COLUMN_REFERENCED_COLUMN_UNRESOLVED_NAME, - new String[] {joinColumn.getReferencedColumnName(), joinColumn.getName()}, - joinColumn, - joinColumn.getReferencedColumnNameTextRange()) - ); - } - } - } - } - - - public class JoinColumnOwner implements OrmJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping().getTableName(); - } - - public Entity getTargetEntity() { - return AbstractOrmSingleRelationshipMapping.this.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return AbstractOrmSingleRelationshipMapping.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return AbstractOrmSingleRelationshipMapping.this; - } - - public boolean tableNameIsInvalid(String tableName) { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return AbstractOrmSingleRelationshipMapping.this.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return AbstractOrmSingleRelationshipMapping.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return AbstractOrmSingleRelationshipMapping.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - return AbstractOrmSingleRelationshipMapping.this.getValidationTextRange(); - } - } -} 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 c2cc70db36..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTable.java +++ /dev/null @@ -1,409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBaseTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.NameTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public abstract class AbstractOrmTable extends AbstractOrmJpaContextNode implements UniqueConstraint.Owner -{ - protected String specifiedName; - - protected String defaultName; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected String specifiedSchema; - - protected String defaultSchema; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - protected AbstractOrmTable(OrmJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public void initializeFrom(Table oldTable) { - setSpecifiedName(oldTable.getSpecifiedName()); - setSpecifiedCatalog(oldTable.getSpecifiedCatalog()); - setSpecifiedSchema(oldTable.getSpecifiedSchema()); - } - - - public String getName() { - return (this.getSpecifiedName() == null) ? this.getDefaultName() : this.getSpecifiedName(); - } - - public String getSpecifiedName() { - return this.specifiedName; - } - - /** - * Return null if no table resource element exists - */ - protected abstract XmlBaseTable getTableResource(); - - protected abstract void removeTableResource(); - - protected abstract void addTableResource(); - - public void setSpecifiedName(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - if (oldSpecifiedName != newSpecifiedName) { - if (this.getTableResource() != null) { - this.getTableResource().setName(newSpecifiedName); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedName != null) { - addTableResource(); - getTableResource().setName(newSpecifiedName); - } - } - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - protected void setSpecifiedName_(String newSpecifiedName) { - String oldSpecifiedName = this.specifiedName; - this.specifiedName = newSpecifiedName; - firePropertyChanged(Table.SPECIFIED_NAME_PROPERTY, oldSpecifiedName, newSpecifiedName); - } - - public String getDefaultName() { - return this.defaultName; - } - - protected void setDefaultName(String newDefaultName) { - String oldDefaultName = this.defaultName; - this.defaultName = newDefaultName; - firePropertyChanged(Table.DEFAULT_NAME_PROPERTY, oldDefaultName, newDefaultName); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - if (oldSpecifiedCatalog != newSpecifiedCatalog) { - if (this.getTableResource() != null) { - this.getTableResource().setCatalog(newSpecifiedCatalog); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedCatalog != null) { - addTableResource(); - getTableResource().setCatalog(newSpecifiedCatalog); - } - } - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - protected void setSpecifiedCatalog_(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - firePropertyChanged(Table.SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(Table.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - if (oldSpecifiedSchema != newSpecifiedSchema) { - if (this.getTableResource() != null) { - this.getTableResource().setSchema(newSpecifiedSchema); - if (this.getTableResource().isAllFeaturesUnset()) { - removeTableResource(); - } - } - else if (newSpecifiedSchema != null) { - addTableResource(); - getTableResource().setSchema(newSpecifiedSchema); - } - } - - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(Table.SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(Table.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - - // ********** unique constraints ********** - - public ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - OrmUniqueConstraint uniqueConstraint = buildUniqueConstraint(uniqueConstraintResource); - this.uniqueConstraints.add(index, uniqueConstraint); - - if (this.getTableResource() == null) { - addTableResource(); - } - - getTableResource().getUniqueConstraints().add(index, uniqueConstraintResource); - fireItemAdded(Table.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - getTableResource().getUniqueConstraints().remove(index); - fireItemRemoved(Table.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, Table.UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getTableResource().getUniqueConstraints().move(targetIndex, sourceIndex); - fireItemMoved(Table.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - public org.eclipse.jpt.db.Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.tableNamed(getName()); - } - - public Schema getDbSchema() { - return getConnectionProfile().getDatabase().schemaNamed(getSchema()); - } - - public boolean hasResolvedSchema() { - return getDbSchema() != null; - } - - public boolean isResolved() { - return getDbTable() != null; - } - - protected void initialize(XmlBaseTable table) { - this.specifiedName = this.specifiedName(table); - this.specifiedSchema = this.specifiedSchema(table); - this.specifiedCatalog = this.specifiedCatalog(table); - this.defaultName = this.defaultName(); - this.defaultSchema = this.defaultSchema(); - this.defaultCatalog = this.defaultCatalog(); - this.initializeUniqueContraints(table); - } - - protected void initializeUniqueContraints(XmlBaseTable table) { - if (table == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : table.getUniqueConstraints()) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraint)); - } - } - - protected void update(XmlBaseTable table) { - this.setSpecifiedName_(this.specifiedName(table)); - this.setSpecifiedSchema_(this.specifiedSchema(table)); - this.setSpecifiedCatalog_(this.specifiedCatalog(table)); - this.setDefaultName(this.defaultName()); - this.setDefaultSchema(this.defaultSchema()); - this.setDefaultCatalog(this.defaultCatalog()); - this.updateUniqueConstraints(table); - } - - protected String specifiedName(XmlBaseTable table) { - return table == null ? null : table.getName(); - } - - protected String specifiedSchema(XmlBaseTable table) { - return table == null ? null : table.getSchema(); - } - - protected String specifiedCatalog(XmlBaseTable table) { - return table == null ? null : table.getCatalog(); - } - - protected abstract String defaultName(); - - protected abstract String defaultSchema(); - - protected abstract String defaultCatalog(); - - protected void updateUniqueConstraints(XmlBaseTable table) { - ListIterator<OrmUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<XmlUniqueConstraint> resourceUniqueConstraints; - if (table == null) { - resourceUniqueConstraints = EmptyListIterator.instance(); - } - else { - resourceUniqueConstraints = new CloneListIterator<XmlUniqueConstraint>(table.getUniqueConstraints());//prevent ConcurrentModificiationException - } - while (uniqueConstraints.hasNext()) { - OrmUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint xmlUniqueConstraint) { - return getJpaFactory().buildOrmUniqueConstraint(this, this, xmlUniqueConstraint); - } - - - public String qualifiedName() { - return NameTools.buildQualifiedDatabaseObjectName(this.getCatalog(), this.getSchema(), this.getName()); - } - - protected TextRange getNameTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - protected TextRange getCatalogTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getCatalogTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - protected TextRange getSchemaTextRange() { - if (getTableResource() != null) { - TextRange textRange = getTableResource().getSchemaTextRange(); - if (textRange != null) { - return textRange; - } - } - return this.getParent().getValidationTextRange(); - } - - public TextRange getValidationTextRange() { - if (getTableResource() != null) { - TextRange textRange = this.getTableResource().getValidationTextRange(); - if (textRange != null) { - return textRange; - } - } - return getParent().getValidationTextRange(); - } - - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(qualifiedName()); - } - - @Override - public String displayString() { - return qualifiedName(); - } -}
\ No newline at end of file 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 60cc1eff0e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java +++ /dev/null @@ -1,367 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -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.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.AbstractXmlTypeMapping; -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.StringTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> extends AbstractOrmJpaContextNode implements OrmTypeMapping -{ - - protected String class_; - - public AccessType defaultAccess; - - protected AccessType specifiedAccess; - - public boolean defaultMetadataComplete; - - protected Boolean specifiedMetadataComplete; - - protected JavaPersistentType javaPersistentType; - - protected T typeMapping; - - protected AbstractOrmTypeMapping(OrmPersistentType parent) { - super(parent); - } - - public boolean isMapped() { - return true; - } - - public String getTableName() { - return null; - } - - public String getClass_() { - return this.class_; - } - - public void setClass(String newClass) { - String oldClass = this.class_; - this.class_ = newClass; - this.getTypeMappingResource().setClassName(newClass); - firePropertyChanged(CLASS_PROPERTY, oldClass, newClass); - getPersistentType().classChanged(oldClass, newClass); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - AccessType oldSpecifiedAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - this.getTypeMappingResource().setAccess(AccessType.toXmlResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldSpecifiedAccess, newSpecifiedAccess); - } - - public AccessType getAccess() { - return (this.getSpecifiedAccess() == null) ? this.getDefaultAccess() : this.getSpecifiedAccess(); - } - - 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.getTypeMappingResource().setMetadataComplete(newSpecifiedMetadataComplete); - firePropertyChanged(SPECIFIED_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newSpecifiedMetadataComplete); - } - - public OrmPersistentType getPersistentType() { - return (OrmPersistentType) getParent(); - } - - /** - * ITypeMapping is changed and various ITypeMappings may have - * common settings. In this method initialize the new ITypeMapping (this) - * fromthe old ITypeMapping (oldMapping) - * @param oldMapping - */ - public void initializeFrom(OrmTypeMapping oldMapping) { - this.setClass(oldMapping.getClass_()); - this.setSpecifiedAccess(oldMapping.getSpecifiedAccess()); - this.setSpecifiedMetadataComplete(oldMapping.getSpecifiedMetadataComplete()); - this.setDefaultAccess(oldMapping.getDefaultAccess()); - this.setDefaultMetadataComplete(oldMapping.isDefaultMetadataComplete()); - } - - public Table getPrimaryDbTable() { - return null; - } - - public Table getDbTable(String tableName) { - return null; - } - - public Schema getDbSchema() { - return null; - } - - /** - * @see TypeMapping#attributeMappingKeyAllowed(String) - * - * Default implementation: override where needed - */ - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return true; - } - - public Iterator<OrmPersistentAttribute> overridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAttributes() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAttributeNames() { - return EmptyIterator.instance(); - } - - public Iterator<OrmPersistentAttribute> overridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> overridableAssociationNames() { - return EmptyIterator.instance(); - } - - public Iterator<PersistentAttribute> allOverridableAssociations() { - return EmptyIterator.instance(); - } - - public Iterator<String> allOverridableAssociationNames() { - return EmptyIterator.instance(); - } - - public T getTypeMappingResource() { - return this.typeMapping; - } - - protected PersistenceUnitMetadata getPersistenceUnitMetadata() { - return getEntityMappings().getPersistenceUnitMetadata(); - } - - protected boolean defaultMetadataComplete() { - return getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); - } - - protected AccessType defaultAccess() { - if (!isMetadataComplete()) { - if (getJavaPersistentType() != null) { - if (getJavaPersistentType().hasAnyAttributeMappingAnnotations()) { - return getJavaPersistentType().getAccess(); - } - if (getPersistentType().getParentPersistentType() != null) { - return getPersistentType().getParentPersistentType().getAccess(); - } - } - } - return getEntityMappings().getAccess(); - } - - public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType newJavaPersistentType) { - JavaPersistentType oldJavaPersistentType = this.javaPersistentType; - this.javaPersistentType = newJavaPersistentType; - firePropertyChanged(JAVA_PERSISTENT_TYPE_PROPERTY, oldJavaPersistentType, newJavaPersistentType); - } - - protected void initializeJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJavaResourcePersistentType(); - if (persistentTypeResource != null) { - this.javaPersistentType = buildJavaPersistentType(persistentTypeResource); - } - } - - protected JavaResourcePersistentType getJavaResourcePersistentType() { - // try to resolve by only the locally specified name - JavaResourcePersistentType persistentTypeResource = getJpaProject().getJavaPersistentTypeResource(getClass_()); - if (persistentTypeResource == null) { - // try to resolve by prepending the global package name - persistentTypeResource = getJpaProject().getJavaPersistentTypeResource(getEntityMappings().getPackage() + "." + getClass_()); - } - return persistentTypeResource; - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJavaResourcePersistentType(); - if (persistentTypeResource == null) { - setJavaPersistentType(null); - } - else { - if (getJavaPersistentType() != null) { - getJavaPersistentType().update(persistentTypeResource); - } - else { - setJavaPersistentType(buildJavaPersistentType(persistentTypeResource)); - } - } - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType resourcePersistentType) { - return getJpaFactory().buildJavaPersistentType(this, resourcePersistentType); - } - - public void initialize(T typeMapping) { - this.typeMapping = typeMapping; - this.class_ = typeMapping.getClassName(); - this.initializeJavaPersistentType(); - this.specifiedMetadataComplete = this.metadataComplete(typeMapping); - this.defaultMetadataComplete = this.defaultMetadataComplete(); - this.specifiedAccess = AccessType.fromXmlResourceModel(typeMapping.getAccess()); - this.defaultAccess = this.defaultAccess(); - } - - public void update(T typeMapping) { - this.typeMapping = typeMapping; - this.setClass(typeMapping.getClassName()); - this.updateJavaPersistentType(); - this.setSpecifiedMetadataComplete(this.metadataComplete(typeMapping)); - this.setDefaultMetadataComplete(this.defaultMetadataComplete()); - this.setSpecifiedAccess(AccessType.fromXmlResourceModel(typeMapping.getAccess())); - this.setDefaultAccess(this.defaultAccess()); - } - - protected Boolean metadataComplete(AbstractXmlTypeMapping typeMapping) { - return typeMapping.getMetadataComplete(); - } - - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int offset) { - if (this.typeMapping.containsOffset(offset)) { - return getPersistentType(); - } - return null; - } - - public TextRange getSelectionTextRange() { - return this.typeMapping.getSelectionTextRange(); - } - - public TextRange getClassTextRange() { - return this.typeMapping.getClassTextRange(); - } - - public TextRange getAttributesTextRange() { - return this.typeMapping.getAttributesTextRange(); - } - - public boolean containsOffset(int textOffset) { - if (this.typeMapping == null) { - return false; - } - return this.typeMapping.containsOffset(textOffset); - } - - //************************* validation ************************ - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addClassMessages(messages); - } - protected void addClassMessages(List<IMessage> messages) { - addUnspecifiedClassMessage(messages); - addUnresolvedClassMessage(messages); - } - - protected void addUnspecifiedClassMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getClass_())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CLASS, - this, - this.getClassTextRange()) - ); - } - } - - protected void addUnresolvedClassMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getClass_()) - && getJavaPersistentType() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENT_TYPE_UNRESOLVED_CLASS, - new String[] {getClass_()}, - this, - this.getClassTextRange()) - ); - } - } - - public TextRange getValidationTextRange() { - return this.typeMapping.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java deleted file mode 100644 index 4b7293fb34..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java +++ /dev/null @@ -1,868 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQuery; -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.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -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.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -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.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericEntityMappings extends AbstractOrmJpaContextNode implements EntityMappings -{ - protected XmlEntityMappings xmlEntityMappings; - - protected String version; - - protected String description; - - protected String package_; - - protected String defaultSchema; - - protected String specifiedSchema; - - protected String defaultCatalog; - - protected String specifiedCatalog; - - protected AccessType defaultAccess; - - protected AccessType specifiedAccess; - - protected final PersistenceUnitMetadata persistenceUnitMetadata; - - protected final List<OrmPersistentType> persistentTypes; - - protected final List<OrmSequenceGenerator> sequenceGenerators; - - protected final List<OrmTableGenerator> tableGenerators; - - protected final List<OrmNamedQuery> namedQueries; - - protected final List<OrmNamedNativeQuery> namedNativeQueries; - - - public GenericEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.persistenceUnitMetadata = getJpaFactory().buildPersistenceUnitMetadata(this, xmlEntityMappings); - this.persistentTypes = new ArrayList<OrmPersistentType>(); - this.sequenceGenerators = new ArrayList<OrmSequenceGenerator>(); - this.tableGenerators = new ArrayList<OrmTableGenerator>(); - this.namedQueries = new ArrayList<OrmNamedQuery>(); - this.namedNativeQueries = new ArrayList<OrmNamedNativeQuery>(); - this.initialize(xmlEntityMappings); - } - - public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; - } - - @Override - public EntityMappings getEntityMappings() { - return this; - } - - @Override - public OrmXml getParent() { - return (OrmXml) super.getParent(); - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(ormPersistentTypes())) { - if (ormPersistentType.isFor(fullyQualifiedTypeName)) { - return ormPersistentType; - } - } - return null; - } - - 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.version; - } - - 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); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - this.xmlEntityMappings.setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? this.getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - this.xmlEntityMappings.setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? this.getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public AccessType getAccess() { - return (this.getSpecifiedAccess() == null) ? this.getDefaultAccess() : this.getSpecifiedAccess(); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; - } - - public void setSpecifiedAccess(AccessType newSpecifiedAccess) { - AccessType oldSpecifiedAccess = this.specifiedAccess; - this.specifiedAccess = newSpecifiedAccess; - this.xmlEntityMappings.setAccess(AccessType.toXmlResourceModel(newSpecifiedAccess)); - firePropertyChanged(SPECIFIED_ACCESS_PROPERTY, oldSpecifiedAccess, newSpecifiedAccess); - } - - public ListIterator<OrmPersistentType> ormPersistentTypes() { - return new CloneListIterator<OrmPersistentType>(this.persistentTypes); - } - - public int ormPersistentTypesSize() { - return this.persistentTypes.size(); - } - - public OrmPersistentType addOrmPersistentType(String mappingKey, String className) { - OrmPersistentType persistentType = getJpaFactory().buildOrmPersistentType(this, mappingKey); - 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); - } - AbstractXmlTypeMapping typeMapping = persistentType.getMapping().addToResourceModel(this.xmlEntityMappings); - typeMapping.setClassName(className); - fireItemAdded(PERSISTENT_TYPES_LIST, index, persistentType); - return persistentType; - } - - protected void addOrmPersistentType(OrmPersistentType ormPersistentType) { - addItemToList(ormPersistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - protected int insertionIndex(OrmPersistentType ormPersistentType) { - return CollectionTools.insertionIndexOf(this.persistentTypes, ormPersistentType, buildMappingComparator()); - } - - private Comparator<OrmPersistentType> buildMappingComparator() { - return 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 removeOrmPersistentType(int index) { - OrmPersistentType ormPersistentType = this.persistentTypes.get(index); - ormPersistentType.dispose(); - this.persistentTypes.remove(index); - ormPersistentType.getMapping().removeFromResourceModel(this.xmlEntityMappings); - fireItemRemoved(PERSISTENT_TYPES_LIST, index, ormPersistentType); - } - - public void removeOrmPersistentType(OrmPersistentType ormPersistentType) { - removeOrmPersistentType(this.persistentTypes.indexOf(ormPersistentType)); - } - - protected void removeOrmPersistentType_(OrmPersistentType ormPersistentType) { - ormPersistentType.dispose(); - removeItemFromList(ormPersistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); - } - - public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { - 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); - //TODO are the source and target correct in this case, or is target off by one??? - fireItemMoved(PERSISTENT_TYPES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmSequenceGenerator> sequenceGenerators() { - return new CloneListIterator<OrmSequenceGenerator>(this.sequenceGenerators); - } - - public int sequenceGeneratorsSize() { - return this.sequenceGenerators.size(); - } - - public OrmSequenceGenerator addSequenceGenerator(int index) { - OrmSequenceGenerator ormSequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - this.sequenceGenerators.add(index, ormSequenceGenerator); - XmlSequenceGenerator sequenceGenerator = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormSequenceGenerator.initialize(sequenceGenerator); - this.xmlEntityMappings.getSequenceGenerators().add(index, sequenceGenerator); - fireItemAdded(SEQUENCE_GENERATORS_LIST, index, ormSequenceGenerator); - return ormSequenceGenerator; - } - - protected void addSequenceGenerator(int index, OrmSequenceGenerator sequenceGenerator) { - addItemToList(index, sequenceGenerator, this.sequenceGenerators, EntityMappings.SEQUENCE_GENERATORS_LIST); - } - - 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); - } - - public ListIterator<OrmTableGenerator> tableGenerators() { - return new CloneListIterator<OrmTableGenerator>(this.tableGenerators); - } - - public int tableGeneratorsSize() { - return this.tableGenerators.size(); - } - - public OrmTableGenerator addTableGenerator(int index) { - OrmTableGenerator xmlTableGenerator = getJpaFactory().buildOrmTableGenerator(this); - this.tableGenerators.add(index, xmlTableGenerator); - XmlTableGenerator tableGenerator = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - xmlTableGenerator.initialize(tableGenerator); - this.xmlEntityMappings.getTableGenerators().add(index, tableGenerator); - fireItemAdded(TABLE_GENERATORS_LIST, index, xmlTableGenerator); - return xmlTableGenerator; - } - - protected void addTableGenerator(int index, OrmTableGenerator tableGenerator) { - addItemToList(index, tableGenerator, this.tableGenerators, EntityMappings.TABLE_GENERATORS_LIST); - } - - 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); - } - - public ListIterator<OrmNamedQuery> namedQueries() { - return new CloneListIterator<OrmNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public OrmNamedQuery addNamedQuery(int index) { - OrmNamedQuery namedQuery = getJpaFactory().buildOrmNamedQuery(this); - this.namedQueries.add(index, namedQuery); - this.xmlEntityMappings.getNamedQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedQuery()); - this.fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - this.removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - OrmNamedQuery namedQuery = this.namedQueries.remove(index); - this.xmlEntityMappings.getNamedQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - } - - protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - this.xmlEntityMappings.getNamedQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public ListIterator<OrmNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<OrmNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public OrmNamedNativeQuery addNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - this.xmlEntityMappings.getNamedNativeQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - this.fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); - this.xmlEntityMappings.getNamedNativeQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - } - - protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - this.xmlEntityMappings.getNamedNativeQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - //TODO what about qualified name? package + class - //this needs to be handled both for className and persistentType.getName(). - //moving on for now since I am just trying to get the ui compiled! just a warning that this isn't good api - public boolean containsPersistentType(String className) { - for (OrmPersistentType persistentType : CollectionTools.iterable(ormPersistentTypes())) { - if (persistentType.getName().equals(className)) { - return true; - } - } - return false; - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - return getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.xmlEntityMappings = entityMappings; - this.version = entityMappings.getVersion(); - this.description = entityMappings.getDescription(); - this.package_ = entityMappings.getPackage(); - this.specifiedSchema = entityMappings.getSchema(); - this.specifiedCatalog = entityMappings.getCatalog(); - this.specifiedAccess = this.specifiedAccess(entityMappings); - this.defaultAccess = getPersistenceUnit().getDefaultAccess(); - this.defaultCatalog = getPersistenceUnit().getDefaultCatalog(); - this.defaultSchema = getPersistenceUnit().getDefaultSchema(); - this.initializePersistentTypes(entityMappings); - this.initializeTableGenerators(entityMappings); - this.initializeSequenceGenerators(entityMappings); - this.initializeNamedQueries(entityMappings); - this.initializeNamedNativeQueries(entityMappings); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializePersistentTypes(XmlEntityMappings entityMappings) { - this.initializeMappedSuperclasses(entityMappings); - this.initializeEntities(entityMappings); - this.initializeEmbeddables(entityMappings); - } - - protected void initializeMappedSuperclasses(XmlEntityMappings entityMappings) { - for (XmlMappedSuperclass mappedSuperclass : entityMappings.getMappedSuperclasses()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - ormPersistentType.initialize(mappedSuperclass); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeEntities(XmlEntityMappings entityMappings) { - for (XmlEntity entity : entityMappings.getEntities()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.ENTITY_TYPE_MAPPING_KEY); - ormPersistentType.initialize(entity); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeEmbeddables(XmlEntityMappings entityMappings) { - for (XmlEmbeddable embeddable : entityMappings.getEmbeddables()) { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - ormPersistentType.initialize(embeddable); - this.persistentTypes.add(ormPersistentType); - } - } - - protected void initializeTableGenerators(XmlEntityMappings entityMappings) { - for (XmlTableGenerator tableGenerator : entityMappings.getTableGenerators()) { - this.tableGenerators.add(buildTableGenerator(tableGenerator)); - } - } - - protected void initializeSequenceGenerators(XmlEntityMappings entityMappings) { - for (XmlSequenceGenerator sequenceGenerator : entityMappings.getSequenceGenerators()) { - this.sequenceGenerators.add(buildSequenceGenerator(sequenceGenerator)); - } - } - - protected void initializeNamedQueries(XmlEntityMappings entityMappings) { - for (XmlNamedQuery namedQuery : entityMappings.getNamedQueries()) { - this.namedQueries.add(buildNamedQuery(namedQuery)); - } - } - - protected void initializeNamedNativeQueries(XmlEntityMappings entityMappings) { - for (XmlNamedNativeQuery namedNativeQuery : entityMappings.getNamedNativeQueries()) { - this.namedNativeQueries.add(buildNamedNativeQuery(namedNativeQuery)); - } - } - - public void update(XmlEntityMappings entityMappings) { - this.xmlEntityMappings = entityMappings; - getJpaFile(entityMappings.getResource().getResourceModel()).addRootStructureNode(this.getMappingFileName(), this); - this.setDescription(entityMappings.getDescription()); - this.setPackage(entityMappings.getPackage()); - this.setSpecifiedSchema(entityMappings.getSchema()); - this.setSpecifiedCatalog(entityMappings.getCatalog()); - this.setSpecifiedAccess(this.specifiedAccess(entityMappings)); - this.persistenceUnitMetadata.update(entityMappings); - this.setDefaultAccess(getPersistenceUnit().getDefaultAccess()); - this.setDefaultCatalog(getPersistenceUnit().getDefaultCatalog()); - this.setDefaultSchema(getPersistenceUnit().getDefaultSchema()); - this.updatePersistentTypes(entityMappings); - this.updateTableGenerators(entityMappings); - this.updateSequenceGenerators(entityMappings); - this.updateNamedQueries(entityMappings); - this.updateNamedNativeQueries(entityMappings); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String getMappingFileName() { - return getParent().getParent().getFileName(); - } - - protected AccessType specifiedAccess(XmlEntityMappings entityMappings) { - return AccessType.fromXmlResourceModel(entityMappings.getAccess()); - } - - protected void updatePersistentTypes(XmlEntityMappings entityMappings) { - ListIterator<OrmPersistentType> ormPersistentTypes = this.ormPersistentTypes(); - this.updateMappedSuperclasses(entityMappings, ormPersistentTypes); - this.updateEntities(entityMappings, ormPersistentTypes); - this.updateEmbeddables(entityMappings, ormPersistentTypes); - - while (ormPersistentTypes.hasNext()) { - this.removeOrmPersistentType_(ormPersistentTypes.next()); - } - } - - protected void updateMappedSuperclasses(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlMappedSuperclass> mappedSuperclasses = new CloneListIterator<XmlMappedSuperclass>(entityMappings.getMappedSuperclasses());//prevent ConcurrentModificiationException - for (XmlMappedSuperclass mappedSuperclass : CollectionTools.iterable(mappedSuperclasses)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(mappedSuperclass); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - ormPersistentType.initialize(mappedSuperclass); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateEntities(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlEntity> entities = new CloneListIterator<XmlEntity>(entityMappings.getEntities());//prevent ConcurrentModificiationException - for (XmlEntity entity : CollectionTools.iterable(entities)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(entity); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.ENTITY_TYPE_MAPPING_KEY); - ormPersistentType.initialize(entity); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateEmbeddables(XmlEntityMappings entityMappings, ListIterator<OrmPersistentType> ormPersistentTypes) { - ListIterator<XmlEmbeddable> embeddables = new CloneListIterator<XmlEmbeddable>(entityMappings.getEmbeddables());//prevent ConcurrentModificiationException - for (XmlEmbeddable embeddable : CollectionTools.iterable(embeddables)) { - if (ormPersistentTypes.hasNext()) { - ormPersistentTypes.next().update(embeddable); - } - else { - OrmPersistentType ormPersistentType = getJpaFactory().buildOrmPersistentType(this, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - ormPersistentType.initialize(embeddable); - addOrmPersistentType(ormPersistentType); - } - } - } - - protected void updateTableGenerators(XmlEntityMappings entityMappings) { - ListIterator<OrmTableGenerator> tableGenerators = tableGenerators(); - ListIterator<XmlTableGenerator> resourceTableGenerators = new CloneListIterator<XmlTableGenerator>(entityMappings.getTableGenerators());//prevent ConcurrentModificiationException - while (tableGenerators.hasNext()) { - OrmTableGenerator tableGenerator = tableGenerators.next(); - if (resourceTableGenerators.hasNext()) { - tableGenerator.update(resourceTableGenerators.next()); - } - else { - removeTableGenerator_(tableGenerator); - } - } - - while (resourceTableGenerators.hasNext()) { - addTableGenerator(tableGeneratorsSize(), buildTableGenerator(resourceTableGenerators.next())); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void updateSequenceGenerators(XmlEntityMappings entityMappings) { - ListIterator<OrmSequenceGenerator> sequenceGenerators = sequenceGenerators(); - ListIterator<XmlSequenceGenerator> resourceSequenceGenerators = new CloneListIterator<XmlSequenceGenerator>(entityMappings.getSequenceGenerators());//prevent ConcurrentModificiationException - while (sequenceGenerators.hasNext()) { - OrmSequenceGenerator sequenceGenerator = sequenceGenerators.next(); - if (resourceSequenceGenerators.hasNext()) { - sequenceGenerator.update(resourceSequenceGenerators.next()); - } - else { - removeSequenceGenerator_(sequenceGenerator); - } - } - - while (resourceSequenceGenerators.hasNext()) { - addSequenceGenerator(sequenceGeneratorsSize(), buildSequenceGenerator(resourceSequenceGenerators.next())); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator sequenceGeneratorResource) { - OrmSequenceGenerator sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - sequenceGenerator.initialize(sequenceGeneratorResource); - return sequenceGenerator; - } - - protected void updateNamedQueries(XmlEntityMappings entityMappings) { - ListIterator<OrmNamedQuery> namedQueries = namedQueries(); - ListIterator<XmlNamedQuery> resourceNamedQueries = new CloneListIterator<XmlNamedQuery>(entityMappings.getNamedQueries());//prevent ConcurrentModificiationException - - while (namedQueries.hasNext()) { - OrmNamedQuery namedQuery = namedQueries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update(resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(namedQueriesSize(), buildNamedQuery(resourceNamedQueries.next())); - } - } - - protected OrmNamedQuery buildNamedQuery(XmlNamedQuery namedQuery) { - OrmNamedQuery ormNamedQuery = getJpaFactory().buildOrmNamedQuery(this); - ormNamedQuery.initialize(namedQuery); - return ormNamedQuery; - } - - protected void updateNamedNativeQueries(XmlEntityMappings entityMappings) { - ListIterator<OrmNamedNativeQuery> namedNativeQueries = namedNativeQueries(); - ListIterator<XmlNamedNativeQuery> resourceNamedNativeQueries = new CloneListIterator<XmlNamedNativeQuery>(entityMappings.getNamedNativeQueries());//prevent ConcurrentModificiationException - - while (namedNativeQueries.hasNext()) { - OrmNamedNativeQuery namedQuery = namedNativeQueries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update(resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(namedNativeQueriesSize(), buildNamedNativeQuery(resourceNamedNativeQueries.next())); - } - } - - protected OrmNamedNativeQuery buildNamedNativeQuery(XmlNamedNativeQuery namedQuery) { - OrmNamedNativeQuery ormNamedNativeQuery =getJpaFactory().buildOrmNamedNativeQuery(this); - ormNamedNativeQuery.initialize(namedQuery); - return ormNamedNativeQuery; - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - for (Generator generator : CollectionTools.iterable(tableGenerators())) { - getPersistenceUnit().addGenerator(generator); - } - - for (Generator generator : CollectionTools.iterable(sequenceGenerators())) { - getPersistenceUnit().addGenerator(generator); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentType persistentType: CollectionTools.iterable(ormPersistentTypes())) { - if (persistentType.contains(textOffset)) { - return persistentType.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (this.xmlEntityMappings == null) { - return false; - } - return this.xmlEntityMappings.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.xmlEntityMappings.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return null; - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - try { - addGeneratorMessages(messages); - addQueryMessages(messages); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(this.ormPersistentTypes())) { - try { - ormPersistentType.addToMessages(messages); - } catch (Throwable exception) { - JptCorePlugin.log(exception); - } - } - } - - @SuppressWarnings("unchecked") - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = new CompositeIterator<OrmGenerator>(this.tableGenerators(), this.sequenceGenerators()); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - masterList.add(current); - } - } - - @SuppressWarnings("unchecked") - protected void addQueryMessages(List<IMessage> messages) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<OrmQuery> stream = new CompositeIterator<OrmQuery>(this.namedQueries(), this.namedNativeQueries()); stream.hasNext() ; ) { - OrmQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - masterList.add(current); - } - } - - public void dispose() { - if (this.xmlEntityMappings.getResource() != null) { - //the resource is null if the orm.xml file was deleted - //rootStructureNodes are cleared in the dispose of JpaFile - JpaFile jpaFile = getJpaFile(this.xmlEntityMappings.getResource().getResourceModel()); - - if (jpaFile != null) { - //yes, this can also be null, seems that sometimes the resource is null and - //something it is not yet null, but we will have no jpaFile for it after a delete. - jpaFile.removeRootStructureNode(getMappingFileName()); - } - } - //still need to dispose these even in the case of a file being deleted. - //JpaFile.dispose() just removes the root structure nodes for this file, not other files (java files) - for (OrmPersistentType ormPersistentType : CollectionTools.iterable(ormPersistentTypes())) { - ormPersistentType.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java deleted file mode 100644 index 92f2999299..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAssociationOverride.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Entity; -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.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class GenericOrmAssociationOverride extends AbstractOrmJpaContextNode - implements OrmAssociationOverride -{ - - protected String name; - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected final List<OrmJoinColumn> defaultJoinColumns; - - private final AssociationOverride.Owner owner; - - protected XmlAssociationOverride associationOverride; - - - public GenericOrmAssociationOverride(OrmJpaContextNode parent, AssociationOverride.Owner owner, XmlAssociationOverride associationOverride) { - super(parent); - this.owner = owner; - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - this.defaultJoinColumns = new ArrayList<OrmJoinColumn>(); - this.initialize(associationOverride); - } - - public OrmAssociationOverride setVirtual(boolean virtual) { - return (OrmAssociationOverride) getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - // ********** IAssociationOverride implementation ********** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.associationOverride.setName(newName); - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - - public ListIterator<OrmJoinColumn> joinColumns() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumns() : this.specifiedJoinColumns(); - } - - public int joinColumnsSize() { - return this.specifiedJoinColumns.isEmpty() ? this.defaultJoinColumnsSize() : this.specifiedJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> defaultJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.defaultJoinColumns); - } - - public int defaultJoinColumnsSize() { - return this.defaultJoinColumns.size(); - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, createJoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - this.associationOverride.getJoinColumns().add(index, OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - this.fireItemAdded(AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected OrmJoinColumn.Owner createJoinColumnOwner() { - return new JoinColumnOwner(); - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - this.associationOverride.getJoinColumns().remove(index); - fireItemRemoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedJoinColumn); - } - - protected void removeSpecifiedJoinColumn(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - this.associationOverride.getJoinColumns().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.specifiedJoinColumns, AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - protected void initialize(XmlAssociationOverride associationOverride) { - this.associationOverride = associationOverride; - this.name = associationOverride.getName(); - initializeSpecifiedJoinColumns(associationOverride); - } - - protected void initializeSpecifiedJoinColumns(XmlAssociationOverride associationOverride) { - for (XmlJoinColumn joinColumn : associationOverride.getJoinColumns()) { - this.specifiedJoinColumns.add(createJoinColumn(joinColumn)); - } - } - - public void update(XmlAssociationOverride associationOverride) { - this.associationOverride = associationOverride; - this.setName(associationOverride.getName()); - updateSpecifiedJoinColumns(associationOverride); - } - - protected void updateSpecifiedJoinColumns(XmlAssociationOverride associationOverride) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(associationOverride.getJoinColumns());//prevent ConcurrentModificiationException - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), createJoinColumn(resourceJoinColumns.next())); - } - } - - protected OrmJoinColumn createJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - class JoinColumnOwner implements OrmJoinColumn.Owner - { - - public JoinColumnOwner() { - super(); - } - - /** - * by default, the join column is in the type mapping's primary table - */ - public String getDefaultTableName() { - return GenericOrmAssociationOverride.this.owner.getTypeMapping().getTableName(); - } - - public String getDefaultColumnName() { - return null; - } - - public Entity getTargetEntity() { - RelationshipMapping relationshipMapping = getRelationshipMapping(); - return relationshipMapping == null ? null : relationshipMapping.getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericOrmAssociationOverride.this.getName(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmAssociationOverride.this.owner.getRelationshipMapping(GenericOrmAssociationOverride.this.getName()); - } - - public boolean tableNameIsInvalid(String tableName) { - return getTypeMapping().tableNameIsInvalid(tableName); - } - - /** - * the join column can be on a secondary table - */ - public boolean tableIsAllowed() { - return true; - } - - public TypeMapping getTypeMapping() { - return GenericOrmAssociationOverride.this.owner.getTypeMapping(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmAssociationOverride.this.defaultJoinColumns.contains(joinColumn); - } - - public int joinColumnsSize() { - return GenericOrmAssociationOverride.this.joinColumnsSize(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java deleted file mode 100644 index 5344708385..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmAttributeOverride.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.AttributeOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -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.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmAttributeOverride extends AbstractOrmJpaContextNode - implements OrmAttributeOverride, OrmColumn.Owner -{ - - protected String name; - - private final Owner owner; - - protected XmlAttributeOverride attributeOverride; - - - protected final OrmColumn column; - - public GenericOrmAttributeOverride(OrmJpaContextNode parent, AttributeOverride.Owner owner, XmlAttributeOverride xmlAttributeOverride) { - super(parent); - this.owner = owner; - this.column = getJpaFactory().buildOrmColumn(this, this); - this.initialize(xmlAttributeOverride); - } - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public OrmAttributeOverride setVirtual(boolean virtual) { - return (OrmAttributeOverride) getOwner().setVirtual(virtual, this); - } - - public Owner getOwner() { - return this.owner; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.attributeOverride.setName(newName); - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - protected void setName_(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(BaseOverride.NAME_PROPERTY, oldName, newName); - } - - public OrmColumn getColumn() { - return this.column; - } - - public TypeMapping getTypeMapping() { - return getOwner().getTypeMapping(); - } - - public Table getDbTable(String tablename) { - return this.getTypeMapping().getDbTable(getColumn().getTable()); - } - - public String getDefaultColumnName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - return columnMapping.getColumn().getName(); - } - - public String getDefaultTableName() { - ColumnMapping columnMapping = getColumnMapping(); - if (columnMapping == null) { - return null; - } - String tableName = columnMapping.getColumn().getSpecifiedTable(); - if (tableName != null) { - return tableName; - } - return getOwner().getTypeMapping().getTableName(); - } - - protected ColumnMapping getColumnMapping() { - return getOwner().getColumnMapping(getName()); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - public TextRange getValidationTextRange() { - TextRange textRange = this.attributeOverride.getValidationTextRange(); - return textRange == null ? getParent().getValidationTextRange() : textRange; - } - - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.attributeOverride.getColumn(); - } - - public void addColumnResource() { - this.attributeOverride.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.attributeOverride.setColumn(null); - } - - - //***************** updating **************** - - protected void initialize(XmlAttributeOverride attributeOverride) { - this.attributeOverride = attributeOverride; - this.name = attributeOverride.getName(); - this.column.initialize(attributeOverride.getColumn()); - } - - public void update(XmlAttributeOverride attributeOverride) { - this.attributeOverride = attributeOverride; - this.setName_(attributeOverride.getName()); - this.column.update(attributeOverride.getColumn()); - } - - //****************** validation ******************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - addColumnMessages(messages); - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && !column.isResolved()) { - if (isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_OVERRIDE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java deleted file mode 100644 index c6634e32ea..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.BasicMapping; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.core.context.TemporalType; -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.OrmPersistentAttribute; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -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.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmBasicMapping extends AbstractOrmAttributeMapping<XmlBasic> - implements OrmBasicMapping -{ - protected final OrmColumn column; - - protected FetchType specifiedFetch; - - protected Boolean specifiedOptional; - - protected EnumType specifiedEnumerated; - - protected TemporalType temporal; - - protected boolean lob; - - public GenericOrmBasicMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - 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.getAttributeMapping().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 getOptional() { - return (this.getSpecifiedOptional() == null) ? this.getDefaultOptional() : this.getSpecifiedOptional(); - } - - public Boolean getDefaultOptional() { - return Nullable.DEFAULT_OPTIONAL; - } - - public Boolean getSpecifiedOptional() { - return this.specifiedOptional; - } - - public void setSpecifiedOptional(Boolean newSpecifiedOptional) { - Boolean oldOptional = this.specifiedOptional; - this.specifiedOptional = newSpecifiedOptional; - this.getAttributeMapping().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 boolean isLob() { - return this.lob; - } - - public void setLob(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - this.getAttributeMapping().setLob(newLob); - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - protected void setLob_(boolean newLob) { - boolean oldLob = this.lob; - this.lob = newLob; - firePropertyChanged(BasicMapping.LOB_PROPERTY, oldLob, newLob); - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public EnumType getEnumerated() { - return (this.getSpecifiedEnumerated() == null) ? this.getDefaultEnumerated() : this.getSpecifiedEnumerated(); - } - - public EnumType getDefaultEnumerated() { - return BasicMapping.DEFAULT_ENUMERATED; - } - - public EnumType getSpecifiedEnumerated() { - return this.specifiedEnumerated; - } - - public void setSpecifiedEnumerated(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - this.getAttributeMapping().setEnumerated(EnumType.toOrmResourceModel(newSpecifiedEnumerated)); - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - protected void setSpecifiedEnumerated_(EnumType newSpecifiedEnumerated) { - EnumType oldEnumerated = this.specifiedEnumerated; - this.specifiedEnumerated = newSpecifiedEnumerated; - firePropertyChanged(BasicMapping.SPECIFIED_ENUMERATED_PROPERTY, oldEnumerated, newSpecifiedEnumerated); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmBasicMapping(this); - } - - - @Override - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public int getXmlSequence() { - return 2; - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - public OrmColumn getColumn() { - return this.column; - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void initialize(XmlBasic basic) { - super.initialize(basic); - this.specifiedFetch = this.specifiedFetch(basic); - this.specifiedOptional = this.specifiedOptional(basic); - this.specifiedEnumerated = this.specifiedEnumerated(basic); - this.temporal = this.specifiedTemporal(basic); - this.lob = specifiedLob(basic); - this.column.initialize(basic.getColumn()); - } - - @Override - public void update(XmlBasic basic) { - super.update(basic); - this.setSpecifiedFetch_(this.specifiedFetch(basic)); - this.setSpecifiedOptional_(this.specifiedOptional(basic)); - this.setSpecifiedEnumerated_(this.specifiedEnumerated(basic)); - this.setTemporal_(this.specifiedTemporal(basic)); - this.setLob_(this.specifiedLob(basic)); - this.column.update(basic.getColumn()); - } - - protected Boolean specifiedOptional(XmlBasic basic) { - return basic.getOptional(); - } - - protected FetchType specifiedFetch(XmlBasic basic) { - return FetchType.fromOrmResourceModel(basic.getFetch()); - } - - protected EnumType specifiedEnumerated(XmlBasic basic) { - return EnumType.fromOrmResourceModel(basic.getEnumerated()); - } - - protected TemporalType specifiedTemporal(XmlBasic basic) { - return TemporalType.fromOrmResourceModel(basic.getTemporal()); - } - - protected boolean specifiedLob(XmlBasic basic) { - return basic.isLob(); - } - - public XmlBasic addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlBasic basic = OrmFactory.eINSTANCE.createXmlBasicImpl(); - getPersistentAttribute().initialize(basic); - typeMapping.getAttributes().getBasics().add(basic); - return basic; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getBasics().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - if (entityOwned()) { - addColumnMessages(messages); - } - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java deleted file mode 100644 index bc664fff2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmColumn.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class GenericOrmColumn extends AbstractOrmBaseColumn<XmlColumn> implements OrmColumn -{ - protected Integer specifiedLength; - - protected Integer specifiedPrecision; - - protected Integer specifiedScale; - - public GenericOrmColumn(OrmJpaContextNode parent, OrmColumn.Owner owner) { - super(parent, owner); - } - - @Override - public OrmColumn.Owner getOwner() { - return (OrmColumn.Owner) super.getOwner(); - } - - public void initializeFrom(Column oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedLength(oldColumn.getSpecifiedLength()); - setSpecifiedPrecision(oldColumn.getSpecifiedPrecision()); - setSpecifiedScale(oldColumn.getSpecifiedScale()); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return Column.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (oldSpecifiedLength != newSpecifiedLength) { - if (this.getColumnResource() != null) { - this.getColumnResource().setLength(newSpecifiedLength); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedLength != null) { - addColumnResource(); - getColumnResource().setLength(newSpecifiedLength); - } - } - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - public Integer getPrecision() { - return (this.getSpecifiedPrecision() == null) ? getDefaultPrecision() : this.getSpecifiedPrecision(); - } - - public Integer getDefaultPrecision() { - return Column.DEFAULT_PRECISION; - } - - public Integer getSpecifiedPrecision() { - return this.specifiedPrecision; - } - - public void setSpecifiedPrecision(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - if (oldSpecifiedPrecision != newSpecifiedPrecision) { - if (this.getColumnResource() != null) { - this.getColumnResource().setPrecision(newSpecifiedPrecision); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedPrecision != null) { - addColumnResource(); - getColumnResource().setPrecision(newSpecifiedPrecision); - } - } - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - protected void setSpecifiedPrecision_(Integer newSpecifiedPrecision) { - Integer oldSpecifiedPrecision = this.specifiedPrecision; - this.specifiedPrecision = newSpecifiedPrecision; - firePropertyChanged(SPECIFIED_PRECISION_PROPERTY, oldSpecifiedPrecision, newSpecifiedPrecision); - } - - public Integer getScale() { - return (this.getSpecifiedScale() == null) ? getDefaultScale() : this.getSpecifiedScale(); - } - - public Integer getDefaultScale() { - return Column.DEFAULT_SCALE; - } - - public Integer getSpecifiedScale() { - return this.specifiedScale; - } - - public void setSpecifiedScale(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - if (oldSpecifiedScale != newSpecifiedScale) { - if (this.getColumnResource() != null) { - this.getColumnResource().setScale(newSpecifiedScale); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedScale != null) { - addColumnResource(); - getColumnResource().setScale(newSpecifiedScale); - } - } - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - protected void setSpecifiedScale_(Integer newSpecifiedScale) { - Integer oldSpecifiedScale = this.specifiedScale; - this.specifiedScale = newSpecifiedScale; - firePropertyChanged(SPECIFIED_SCALE_PROPERTY, oldSpecifiedScale, newSpecifiedScale); - } - - @Override - protected XmlColumn getColumnResource() { - return getOwner().getColumnResource(); - } - - @Override - protected void addColumnResource() { - getOwner().addColumnResource(); - } - - @Override - protected void removeColumnResource() { - getOwner().removeColumnResource(); - } - - @Override - public void initialize(XmlColumn column) { - super.initialize(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedPrecision = this.specifiedPrecision(column); - this.specifiedScale = this.specifiedScale(column); - } - - @Override - public void update(XmlColumn column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedPrecision_(this.specifiedPrecision(column)); - this.setSpecifiedScale_(this.specifiedScale(column)); - } - - protected Integer specifiedLength(XmlColumn column) { - return column == null ? null : column.getLength(); - } - - protected Integer specifiedPrecision(XmlColumn column) { - return column == null ? null : column.getPrecision(); - } - - protected Integer specifiedScale(XmlColumn column) { - return column == null ? null : column.getScale(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java deleted file mode 100644 index 0cf8666e95..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmDiscriminatorColumn.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedColumn; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlDiscriminatorColumn; -import org.eclipse.jpt.core.resource.orm.XmlEntity; - -public class GenericOrmDiscriminatorColumn extends AbstractOrmNamedColumn<XmlDiscriminatorColumn> - implements OrmDiscriminatorColumn -{ - - protected DiscriminatorType specifiedDiscriminatorType; - - protected DiscriminatorType defaultDiscriminatorType; - - protected Integer specifiedLength; - - protected XmlEntity entity; - - public GenericOrmDiscriminatorColumn(OrmJpaContextNode parent, OrmNamedColumn.Owner owner) { - super(parent, owner); - } - - public DiscriminatorType getDiscriminatorType() { - return (this.getSpecifiedDiscriminatorType() == null) ? this.getDefaultDiscriminatorType() : this.getSpecifiedDiscriminatorType(); - } - - public DiscriminatorType getDefaultDiscriminatorType() { - return DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE; - } - - public DiscriminatorType getSpecifiedDiscriminatorType() { - return this.specifiedDiscriminatorType; - } - - public void setSpecifiedDiscriminatorType(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - if (oldDiscriminatorType != newSpecifiedDiscriminatorType) { - if (this.getColumnResource() != null) { - this.getColumnResource().setDiscriminatorType(DiscriminatorType.toOrmResourceModel(newSpecifiedDiscriminatorType)); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedDiscriminatorType != null) { - addColumnResource(); - this.getColumnResource().setDiscriminatorType(DiscriminatorType.toOrmResourceModel(newSpecifiedDiscriminatorType)); - } - } - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - protected void setSpecifiedDiscriminatorType_(DiscriminatorType newSpecifiedDiscriminatorType) { - DiscriminatorType oldDiscriminatorType = this.specifiedDiscriminatorType; - this.specifiedDiscriminatorType = newSpecifiedDiscriminatorType; - firePropertyChanged(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY, oldDiscriminatorType, newSpecifiedDiscriminatorType); - } - - public Integer getLength() { - return (this.getSpecifiedLength() == null) ? this.getDefaultLength() : this.getSpecifiedLength(); - } - - public Integer getDefaultLength() { - return DiscriminatorColumn.DEFAULT_LENGTH; - } - - public Integer getSpecifiedLength() { - return this.specifiedLength; - } - - public void setSpecifiedLength(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - if (oldSpecifiedLength != newSpecifiedLength) { - if (this.getColumnResource() != null) { - this.getColumnResource().setLength(newSpecifiedLength); - if (this.getColumnResource().isAllFeaturesUnset()) { - removeColumnResource(); - } - } - else if (newSpecifiedLength != null) { - addColumnResource(); - getColumnResource().setLength(newSpecifiedLength); - } - } - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - protected void setSpecifiedLength_(Integer newSpecifiedLength) { - Integer oldSpecifiedLength = this.specifiedLength; - this.specifiedLength = newSpecifiedLength; - firePropertyChanged(SPECIFIED_LENGTH_PROPERTY, oldSpecifiedLength, newSpecifiedLength); - } - - @Override - protected String tableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - - - @Override - protected XmlDiscriminatorColumn getColumnResource() { - return this.entity.getDiscriminatorColumn(); - } - - @Override - protected void addColumnResource() { - this.entity.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - } - - @Override - protected void removeColumnResource() { - this.entity.setDiscriminatorColumn(null); - } - - public void initialize(XmlEntity entity) { - this.entity = entity; - this.initialize(this.getColumnResource()); - } - - public void update(XmlEntity entity) { - this.entity = entity; - this.update(this.getColumnResource()); - } - - - @Override - protected void initialize(XmlDiscriminatorColumn column) { - super.initialize(column); - this.specifiedLength = this.specifiedLength(column); - this.specifiedDiscriminatorType = this.specifiedDiscriminatorType(column); - //TODO defaultLength, discriminator type java column - } - - @Override - protected void update(XmlDiscriminatorColumn column) { - super.update(column); - this.setSpecifiedLength_(this.specifiedLength(column)); - this.setSpecifiedDiscriminatorType_(this.specifiedDiscriminatorType(column)); - //TODO defaultLength, scale, precision from java column - } - - protected Integer specifiedLength(XmlDiscriminatorColumn column) { - return column == null ? null : column.getLength(); - } - - protected DiscriminatorType specifiedDiscriminatorType(XmlDiscriminatorColumn column) { - return column == null ? null : DiscriminatorType.fromOrmResourceModel(column.getDiscriminatorType()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java deleted file mode 100644 index 437e498d60..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddable.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - - -public class GenericOrmEmbeddable extends AbstractOrmTypeMapping<XmlEmbeddable> implements OrmEmbeddable -{ - public GenericOrmEmbeddable(OrmPersistentType parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - public int getXmlSequence() { - return 2; - } - - @Override - public boolean attributeMappingKeyAllowed(String attributeMappingKey) { - return attributeMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY || attributeMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - protected Boolean metadataComplete(XmlEmbeddable embeddable) { - return embeddable.getMetadataComplete(); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEmbeddables().remove(this.getTypeMappingResource()); - } - - public XmlEmbeddable addToResourceModel(XmlEntityMappings entityMappings) { - XmlEmbeddable embeddable = OrmFactory.eINSTANCE.createXmlEmbeddable(); - getPersistentType().initialize(embeddable); - entityMappings.getEmbeddables().add(embeddable); - return embeddable; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java deleted file mode 100644 index d39b238566..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedIdMapping.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; - - -public class GenericOrmEmbeddedIdMapping extends AbstractOrmBaseEmbeddedMapping<XmlEmbeddedId> implements OrmEmbeddedIdMapping -{ - - public GenericOrmEmbeddedIdMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedIdMapping(this); - } - - public int getXmlSequence() { - return 1; - } - - //*************** AttributeMapping implementation ********************* - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public XmlEmbeddedId addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlEmbeddedId embeddedId = OrmFactory.eINSTANCE.createXmlEmbeddedIdImpl(); - getPersistentAttribute().initialize(embeddedId); - typeMapping.getAttributes().getEmbeddedIds().add(embeddedId); - return embeddedId; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getEmbeddedIds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlEmbeddedId embedded) { - super.initialize(embedded); - } - - @Override - public void update(XmlEmbeddedId embedded) { - super.update(embedded); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java deleted file mode 100644 index 62d01d0053..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEmbeddedMapping.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; - - -public class GenericOrmEmbeddedMapping extends AbstractOrmBaseEmbeddedMapping<XmlEmbedded> implements OrmEmbeddedMapping -{ - - public GenericOrmEmbeddedMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmEmbeddedMapping(this); - } - - public int getXmlSequence() { - return 8; - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public XmlEmbedded addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlEmbedded embedded = OrmFactory.eINSTANCE.createXmlEmbeddedImpl(); - getPersistentAttribute().initialize(embedded); - typeMapping.getAttributes().getEmbeddeds().add(embedded); - return embedded; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getEmbeddeds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlEmbedded embedded) { - super.initialize(embedded); - } - - @Override - public void update(XmlEmbedded embedded) { - super.update(embedded); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java deleted file mode 100644 index 3637306b43..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmEntity.java +++ /dev/null @@ -1,1988 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.MappingKeys; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -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.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.core.context.RelationshipMapping; -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.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -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.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -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.OrmGenerator; -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.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmQuery; -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.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.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.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -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.utility.TextRange; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -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.SingleElementIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmEntity extends AbstractOrmTypeMapping<XmlEntity> implements OrmEntity -{ - protected String specifiedName; - - protected String defaultName; - - protected String idClass; - - protected final OrmTable table; - - 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 discriminatorValueAllowed; - - protected final OrmDiscriminatorColumn discriminatorColumn; - - protected OrmSequenceGenerator sequenceGenerator; - - protected OrmTableGenerator tableGenerator; - - protected final List<OrmAttributeOverride> specifiedAttributeOverrides; - - protected final List<OrmAttributeOverride> virtualAttributeOverrides; - - protected final List<OrmAssociationOverride> specifiedAssociationOverrides; - - protected final List<OrmAssociationOverride> virtualAssociationOverrides; - - protected final List<OrmNamedQuery> namedQueries; - - protected final List<OrmNamedNativeQuery> namedNativeQueries; - - public GenericOrmEntity(OrmPersistentType parent) { - super(parent); - this.table = getJpaFactory().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.specifiedAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.virtualAttributeOverrides = new ArrayList<OrmAttributeOverride>(); - this.specifiedAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.virtualAssociationOverrides = new ArrayList<OrmAssociationOverride>(); - this.namedQueries = new ArrayList<OrmNamedQuery>(); - this.namedNativeQueries = new ArrayList<OrmNamedNativeQuery>(); - } - - protected OrmDiscriminatorColumn buildDiscriminatorColumn() { - return getJpaFactory().buildOrmDiscriminatorColumn(this, buildDiscriminatorColumnOwner()); - } - - protected OrmNamedColumn.Owner buildDiscriminatorColumnOwner() { - return new OrmNamedColumn.Owner(){ - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericOrmEntity.this.getDbTable(tableName); - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - public String getDefaultColumnName() { - //TODO default column name from java here or in XmlDiscriminatorColumn? - return DiscriminatorColumn.DEFAULT_NAME; - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - - }; - } - - // ******************* ITypeMapping implementation ******************** - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - @Override - public String getTableName() { - return getTable().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getPrimaryDbTable() { - return getTable().getDbTable(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - for (Iterator<Table> stream = this.associatedTablesIncludingInherited(); stream.hasNext();) { - org.eclipse.jpt.db.Table dbTable = stream.next().getDbTable(); - if (dbTable != null && dbTable.matchesShortJavaClassName(tableName)) { - return dbTable; - } - } - return null; - } - - @Override - public Schema getDbSchema() { - return getTable().getDbSchema(); - } - - public JavaEntity getJavaEntity() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null && javaPersistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (JavaEntity) javaPersistentType.getMapping(); - } - return null; - } - - 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.getTypeMappingResource().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); - } - - 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)"); - } - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTableImpl(); - OrmSecondaryTable secondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(index, secondaryTable); - getTypeMappingResource().getSecondaryTables().add(index, secondaryTableResource); - fireItemAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); - return secondaryTable; - } - - protected void addSpecifiedSecondaryTable(int index, OrmSecondaryTable secondaryTable) { - addItemToList(index, secondaryTable, this.specifiedSecondaryTables, Entity.SPECIFIED_SECONDARY_TABLES_LIST); - } - - public void removeSpecifiedSecondaryTable(SecondaryTable secondaryTable) { - this.removeSpecifiedSecondaryTable(this.specifiedSecondaryTables.indexOf(secondaryTable)); - } - - public void removeSpecifiedSecondaryTable(int index) { - OrmSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - getTypeMappingResource().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.getTypeMappingResource().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> virtualSecondaryTables = CollectionTools.list(this.virtualSecondaryTables()); - List<OrmSecondaryTable> virtualSecondaryTable2 = 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 : virtualSecondaryTable2) { - XmlSecondaryTable secondaryTableResource = OrmFactory.eINSTANCE.createXmlSecondaryTableImpl(); - OrmSecondaryTable specifiedSecondaryTable = buildSecondaryTable(secondaryTableResource); - this.specifiedSecondaryTables.add(specifiedSecondaryTable); - getTypeMappingResource().getSecondaryTables().add(secondaryTableResource); - specifiedSecondaryTable.initializeFrom(virtualSecondaryTable); - } - //fire change notification at the end - fireItemsRemoved(OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST, 0, virtualSecondaryTables); - fireItemsAdded(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, this.specifiedSecondaryTables); - } - } - - protected void removeSecondaryTablesFromXml() { - if (specifiedSecondaryTablesSize() != 0) { - List<OrmSecondaryTable> specifiedSecondaryTables = 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(); - } - getTypeMappingResource().getSecondaryTables().remove(index); - } - fireItemsRemoved(Entity.SPECIFIED_SECONDARY_TABLES_LIST, 0, specifiedSecondaryTables); - 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, String>(this.tableNames(tables)) { - @Override - protected boolean accept(String o) { - return o != null; - } - }; - } - - public Iterator<Table> associatedTables() { - return new CompositeIterator<Table>(this.getTable(), this.secondaryTables()); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return new CompositeIterator<Table>(new TransformationIterator<TypeMapping, Iterator<Table>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<Table> transform(TypeMapping mapping) { - return new FilteringIterator<Table, Table>(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) { - return !CollectionTools.contains(this.associatedTableNamesIncludingInherited(), tableName); - } - - 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.inheritanceResource() != null) { - this.inheritanceResource().setStrategy(InheritanceType.toOrmResourceModel(newInheritanceType)); - if (this.inheritanceResource().isAllFeaturesUnset()) { - removeInheritanceResource(); - } - } - else if (newInheritanceType != null) { - addInheritanceResource(); - inheritanceResource().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 inheritanceResource() { - return getTypeMappingResource().getInheritance(); - } - - protected void addInheritanceResource() { - getTypeMappingResource().setInheritance(OrmFactory.eINSTANCE.createInheritance()); - } - - protected void removeInheritanceResource() { - getTypeMappingResource().setInheritance(null); - } - - public OrmDiscriminatorColumn getDiscriminatorColumn() { - return this.discriminatorColumn; - } - - public OrmSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - this.sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - getTypeMappingResource().setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); - } - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.getTypeMappingResource().setSequenceGenerator(null); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public OrmSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(OrmSequenceGenerator newSequenceGenerator) { - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - public OrmTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - getTypeMappingResource().setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); - } - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.getTypeMappingResource().setTableGenerator(null); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public OrmTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(OrmTableGenerator newTableGenerator) { - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmGenerator> generators() { - return new CompositeIterator<OrmGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - 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; - getTypeMappingResource().setDiscriminatorValue(newSpecifiedDiscriminatorValue); - firePropertyChanged(SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY, oldSpecifiedDiscriminatorValue, newSpecifiedDiscriminatorValue); - } - - public String getDiscriminatorValue() { - return (this.getSpecifiedDiscriminatorValue() == null) ? getDefaultDiscriminatorValue() : this.getSpecifiedDiscriminatorValue(); - } - - public boolean isDiscriminatorValueAllowed() { - return this.discriminatorValueAllowed; - } - - protected void setDiscriminatorValueAllowed(boolean newDiscriminatorValueAllowed) { - boolean oldDiscriminatorValueAllowed = this.discriminatorValueAllowed; - this.discriminatorValueAllowed = newDiscriminatorValueAllowed; - firePropertyChanged(Entity.DISCRIMINATOR_VALUE_ALLOWED_PROPERTY, oldDiscriminatorValueAllowed, newDiscriminatorValueAllowed); - } - - 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"); - } - - 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 xmlPrimaryKeyJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = buildPrimaryKeyJoinColumn(xmlPrimaryKeyJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - this.getTypeMappingResource().getPrimaryKeyJoinColumns().add(index, xmlPrimaryKeyJoinColumn); - - this.fireItemAdded(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - this.fireListCleared(OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST); - return primaryKeyJoinColumn; - } - - 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); - } - - 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.getTypeMappingResource().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); - } - } - - 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.getTypeMappingResource().getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAttributeOverride> attributeOverrides() { - return new CompositeListIterator<OrmAttributeOverride>(specifiedAttributeOverrides(), virtualAttributeOverrides()); - } - - public int attributeOverridesSize() { - return this.specifiedAttributeOverridesSize() + this.virtualAttributeOverridesSize(); - } - - public ListIterator<OrmAttributeOverride> virtualAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.virtualAttributeOverrides); - } - - public int virtualAttributeOverridesSize() { - return this.virtualAttributeOverrides.size(); - } - - protected void addVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - addItemToList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeVirtualAttributeOverride(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.virtualAttributeOverrides, Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST); - } - - protected OrmAttributeOverride setAttributeOverrideVirtual(boolean virtual, OrmAttributeOverride attributeOverride) { - if (virtual) { - return setAttributeOverrideVirtual(attributeOverride); - } - return setAttributeOverrideSpecified(attributeOverride); - } - - protected OrmAttributeOverride setAttributeOverrideVirtual(OrmAttributeOverride attributeOverride) { - int index = this.specifiedAttributeOverrides.indexOf(attributeOverride); - this.specifiedAttributeOverrides.remove(index); - String attributeOverrideName = attributeOverride.getName(); - //add the virtual attribute override so that I can control the order that change notification is sent. - //otherwise when we remove the annotation from java we will get an update and add the attribute override - //during the udpate. This causes the UI to be flaky, since change notification might not occur in the correct order - OrmAttributeOverride virtualAttributeOverride = null; - if (attributeOverrideName != null) { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - if (persistentAttribute.getName().equals(attributeOverrideName)) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(attributeOverrideName); - } - //store the virtualAttributeOverride so we can fire change notification later - virtualAttributeOverride = buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride); - this.virtualAttributeOverrides.add(virtualAttributeOverride); - } - } - } - - getTypeMappingResource().getAttributeOverrides().remove(index); - fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); - - if (virtualAttributeOverride != null) { - fireItemAdded(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, virtualAttributeOverridesSize() - 1, virtualAttributeOverride); - } - return virtualAttributeOverride; - } - - protected OrmAttributeOverride setAttributeOverrideSpecified(OrmAttributeOverride oldAttributeOverride) { - int index = specifiedAttributeOverridesSize(); - XmlAttributeOverride xmlAttributeOverride = OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl(); - OrmAttributeOverride newAttributeOverride = getJpaFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), xmlAttributeOverride); - this.specifiedAttributeOverrides.add(index, newAttributeOverride); - - getTypeMappingResource().getAttributeOverrides().add(xmlAttributeOverride); - - int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); - this.virtualAttributeOverrides.remove(defaultIndex); - - newAttributeOverride.setName(oldAttributeOverride.getName()); - newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); - - this.fireItemRemoved(Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST, defaultIndex, oldAttributeOverride); - this.fireItemAdded(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, newAttributeOverride); - - return newAttributeOverride; - } - - public ListIterator<OrmAttributeOverride> specifiedAttributeOverrides() { - return new CloneListIterator<OrmAttributeOverride>(this.specifiedAttributeOverrides); - } - - public int specifiedAttributeOverridesSize() { - return this.specifiedAttributeOverrides.size(); - } - - protected void addSpecifiedAttributeOverride(int index, OrmAttributeOverride attributeOverride) { - addItemToList(index, attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - protected void removeSpecifiedAttributeOverride_(OrmAttributeOverride attributeOverride) { - removeItemFromList(attributeOverride, this.specifiedAttributeOverrides, Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST); - } - - public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.getTypeMappingResource().getAttributeOverrides().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmAssociationOverride> associationOverrides() { - return new CompositeListIterator<OrmAssociationOverride>(specifiedAssociationOverrides(), virtualAssociationOverrides()); - } - - public int associationOverridesSize() { - return this.specifiedAssociationOverridesSize() + this.virtualAssociationOverridesSize(); - } - - public ListIterator<OrmAssociationOverride> virtualAssociationOverrides() { - return new CloneListIterator<OrmAssociationOverride>(this.virtualAssociationOverrides); - } - - public int virtualAssociationOverridesSize() { - return this.virtualAssociationOverrides.size(); - } - - public ListIterator<OrmAssociationOverride> specifiedAssociationOverrides() { - return new CloneListIterator<OrmAssociationOverride>(this.specifiedAssociationOverrides); - } - - public int specifiedAssociationOverridesSize() { - return this.specifiedAssociationOverrides.size(); - } - - protected void addSpecifiedAssociationOverride(int index, OrmAssociationOverride associationOverride) { - addItemToList(index, associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - protected void removeSpecifiedAssociationOverride_(OrmAssociationOverride associationOverride) { - removeItemFromList(associationOverride, this.specifiedAssociationOverrides, Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST); - } - - public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.getTypeMappingResource().getAssociationOverrides().move(targetIndex, sourceIndex); - fireItemMoved(Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); - } - - public OrmAttributeOverride getAttributeOverrideNamed(String name) { - return (OrmAttributeOverride) getOverrideNamed(name, attributeOverrides()); - } - - public boolean containsAttributeOverride(String name) { - return containsOverride(name, attributeOverrides()); - } - - public boolean containsDefaultAttributeOverride(String name) { - return containsOverride(name, virtualAttributeOverrides()); - } - - public boolean containsSpecifiedAttributeOverride(String name) { - return containsOverride(name, specifiedAttributeOverrides()); - } - - public OrmAssociationOverride getAssociationOverrideNamed(String name) { - return (OrmAssociationOverride) getOverrideNamed(name, associationOverrides()); - } - - public boolean containsAssociationOverride(String name) { - return containsOverride(name, associationOverrides()); - } - - public boolean containsSpecifiedAssociationOverride(String name) { - return containsOverride(name, specifiedAssociationOverrides()); - } - - public boolean containsDefaultAssociationOverride(String name) { - return containsOverride(name, virtualAssociationOverrides()); - } - - private BaseOverride getOverrideNamed(String name, ListIterator<? extends BaseOverride> overrides) { - for (BaseOverride override : CollectionTools.iterable(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, ListIterator<? extends BaseOverride> overrides) { - return getOverrideNamed(name, overrides) != null; - } - - - public ListIterator<OrmNamedQuery> namedQueries() { - return new CloneListIterator<OrmNamedQuery>(this.namedQueries); - } - - public int namedQueriesSize() { - return this.namedQueries.size(); - } - - public OrmNamedQuery addNamedQuery(int index) { - OrmNamedQuery namedQuery = getJpaFactory().buildOrmNamedQuery(this); - this.namedQueries.add(index, namedQuery); - XmlNamedQuery xmlNamedQuery = OrmFactory.eINSTANCE.createXmlNamedQuery(); - namedQuery.initialize(xmlNamedQuery); - this.getTypeMappingResource().getNamedQueries().add(index, xmlNamedQuery); - this.fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - return namedQuery; - } - - protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void removeNamedQuery(NamedQuery namedQuery) { - removeNamedQuery(this.namedQueries.indexOf(namedQuery)); - } - - public void removeNamedQuery(int index) { - OrmNamedQuery namedQuery = this.namedQueries.remove(index); - this.getTypeMappingResource().getNamedQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); - } - - protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); - } - - public void moveNamedQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.getTypeMappingResource().getNamedQueries().move(targetIndex, sourceIndex); - fireItemMoved(QueryHolder.NAMED_QUERIES_LIST, targetIndex, sourceIndex); - } - - public ListIterator<OrmNamedNativeQuery> namedNativeQueries() { - return new CloneListIterator<OrmNamedNativeQuery>(this.namedNativeQueries); - } - - public int namedNativeQueriesSize() { - return this.namedNativeQueries.size(); - } - - public OrmNamedNativeQuery addNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - this.namedNativeQueries.add(index, namedNativeQuery); - XmlNamedNativeQuery xmlNamedNativeQuery = OrmFactory.eINSTANCE.createXmlNamedNativeQuery(); - namedNativeQuery.initialize(xmlNamedNativeQuery); - this.getTypeMappingResource().getNamedNativeQueries().add(index, OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - this.fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - return namedNativeQuery; - } - - protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void removeNamedNativeQuery(NamedNativeQuery namedNativeQuery) { - this.removeNamedNativeQuery(this.namedNativeQueries.indexOf(namedNativeQuery)); - } - - public void removeNamedNativeQuery(int index) { - OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); - this.getTypeMappingResource().getNamedNativeQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); - } - - protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); - } - - public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { - CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.getTypeMappingResource().getNamedNativeQueries().move(targetIndex, sourceIndex); - fireItemMoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmQuery> queries() { - return new CompositeIterator<OrmQuery>(this.namedQueries(), this.namedNativeQueries()); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (oldIdClass != newIdClass) { - if (this.idClassResource() != null) { - this.idClassResource().setClassName(newIdClass); - if (this.idClassResource().isAllFeaturesUnset()) { - removeIdClassResource(); - } - } - else if (newIdClass != null) { - addIdClassResource(); - idClassResource().setClassName(newIdClass); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass idClassResource() { - return getTypeMappingResource().getIdClass(); - } - - protected void addIdClassResource() { - getTypeMappingResource().setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeIdClassResource() { - getTypeMappingResource().setIdClass(null); - } - - public Entity getParentEntity() { - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - TypeMapping typeMapping = i.next().getMapping(); - if (typeMapping != this && typeMapping instanceof Entity) { - return (Entity) typeMapping; - } - } - return this; - } - - public Entity getRootEntity() { - Entity rootEntity = null; - for (Iterator<PersistentType> i = getPersistentType().inheritanceHierarchy(); i.hasNext();) { - PersistentType persistentType = i.next(); - if (persistentType.getMapping() instanceof Entity) { - rootEntity = (Entity) persistentType.getMapping(); - } - } - return rootEntity; - } - -// 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> inheritanceHierarchy() { - return new TransformationIterator<PersistentType, TypeMapping>(getPersistentType().inheritanceHierarchy()) { - @Override - protected TypeMapping transform(PersistentType type) { - return type.getMapping(); - } - }; - } - - @Override - public Iterator<PersistentAttribute> allOverridableAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<TypeMapping, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(TypeMapping mapping) { - return mapping.overridableAttributes(); - } - }); - } - - @Override - 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(); - } - }); - } - - @Override - 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 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(); -// } - - - @Override - public void initialize(XmlEntity entity) { - super.initialize(entity); - this.specifiedName = entity.getName(); - this.defaultName = this.defaultName(); - this.initializeInheritance(this.inheritanceResource()); - this.discriminatorColumn.initialize(entity); - this.specifiedDiscriminatorValue = entity.getDiscriminatorValue(); - this.defaultDiscriminatorValue = this.defaultDiscriminatorValue(); - this.discriminatorValueAllowed = this.discriminatorValueIsAllowed(); - this.table.initialize(entity); - this.initializeSpecifiedSecondaryTables(entity); - this.initializeVirtualSecondaryTables(); - this.initializeSequenceGenerator(entity); - this.initializeTableGenerator(entity); - this.initializeSpecifiedPrimaryKeyJoinColumns(entity); - this.initializeDefaultPrimaryKeyJoinColumns(); - this.initializeSpecifiedAttributeOverrides(entity); - this.initializeVirtualAttributeOverrides(); - this.initializeSpecifiedAssociationOverrides(entity); - this.initializeNamedQueries(entity); - this.initializeNamedNativeQueries(entity); - this.initializeIdClass(this.idClassResource()); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected void initializeInheritance(Inheritance inheritanceResource) { - this.specifiedInheritanceStrategy = this.specifiedInheritanceStrategy(inheritanceResource); - this.defaultInheritanceStrategy = this.defaultInheritanceStrategy(); - } - - protected void initializeSpecifiedSecondaryTables(XmlEntity entity) { - for (XmlSecondaryTable secondaryTable : entity.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 initializeTableGenerator(XmlEntity entity) { - if (entity.getTableGenerator() != null) { - this.tableGenerator = buildTableGenerator(entity.getTableGenerator()); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void initializeSequenceGenerator(XmlEntity entity) { - if (entity.getSequenceGenerator() != null) { - this.sequenceGenerator = buildSequenceGenerator(entity.getSequenceGenerator()); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator xmlSequenceGenerator) { - OrmSequenceGenerator sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - sequenceGenerator.initialize(xmlSequenceGenerator); - return sequenceGenerator; - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(XmlEntity entity) { - for (XmlPrimaryKeyJoinColumn primaryKeyJoinColumn : entity.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(primaryKeyJoinColumn)); - } - } - - protected void initializeSpecifiedAttributeOverrides(XmlEntity entity) { - for (XmlAttributeOverride attributeOverride : entity.getAttributeOverrides()) { - this.specifiedAttributeOverrides.add(buildAttributeOverride(attributeOverride)); - } - } - - protected void initializeVirtualAttributeOverrides() { - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(allOverridableAttributes())) { - OrmAttributeOverride attributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (attributeOverride == null) { - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(persistentAttribute.getName()); - } - this.virtualAttributeOverrides.add(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - } - - protected OrmAttributeOverride buildVirtualAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - return buildAttributeOverride(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - - protected XmlAttributeOverride buildVirtualXmlAttributeOverride(PersistentAttribute persistentAttribute, JavaAttributeOverride javaAttributeOverride) { - XmlColumn xmlColumn; - if (javaAttributeOverride == null) { - ColumnMapping columnMapping = (ColumnMapping) persistentAttribute.getMapping(); - xmlColumn = new VirtualXmlColumn(this, columnMapping.getColumn(), false); - } - else { - xmlColumn = new VirtualXmlColumn(this, javaAttributeOverride.getColumn(), isMetadataComplete()); - } - return new VirtualXmlAttributeOverride(persistentAttribute.getName(), xmlColumn); - } - - protected void initializeSpecifiedAssociationOverrides(XmlEntity entity) { - for (XmlAssociationOverride associationOverride : entity.getAssociationOverrides()) { - this.specifiedAssociationOverrides.add(buildAssociationOverride(associationOverride)); - } - } - - protected void initializeNamedQueries(XmlEntity entity) { - for (XmlNamedQuery namedQuery : entity.getNamedQueries()) { - this.namedQueries.add(buildNamedQuery(namedQuery)); - } - } - - protected void initializeNamedNativeQueries(XmlEntity entity) { - for (XmlNamedNativeQuery namedNativeQuery : entity.getNamedNativeQueries()) { - this.namedNativeQueries.add(buildNamedNativeQuery(namedNativeQuery)); - } - } - - protected void initializeIdClass(XmlIdClass idClassResource) { - this.idClass = this.idClass(idClassResource); - } - - protected String idClass(XmlIdClass idClassResource) { - return idClassResource == null ? null : idClassResource.getClassName(); - } - - @Override - public void update(XmlEntity entity) { - super.update(entity); - this.setSpecifiedName(entity.getName()); - this.setDefaultName(this.defaultName()); - this.updateInheritance(this.inheritanceResource()); - this.discriminatorColumn.update(entity); - this.setSpecifiedDiscriminatorValue(entity.getDiscriminatorValue()); - this.setDefaultDiscriminatorValue(defaultDiscriminatorValue()); - this.setDiscriminatorValueAllowed(this.discriminatorValueIsAllowed()); - this.table.update(entity); - this.updateSpecifiedSecondaryTables(entity); - this.updateVirtualSecondaryTables(); - this.updateSequenceGenerator(entity); - this.updateTableGenerator(entity); - this.updateSpecifiedPrimaryKeyJoinColumns(entity); - this.updateDefaultPrimaryKeyJoinColumns(); - this.updateSpecifiedAttributeOverrides(entity); - this.updateVirtualAttributeOverrides(); - this.updateSpecifiedAssociationOverrides(entity); - this.updateNamedQueries(entity); - this.updateNamedNativeQueries(entity); - this.updateIdClass(this.idClassResource()); - this.updatePersistenceUnitGeneratorsAndQueries(); - } - - protected String defaultName() { - if (!isMetadataComplete()) { - JavaEntity javaEntity = getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getName(); - } - } - String className = getClass_(); - if (className != null) { - return ClassTools.shortNameForClassNamed(className); - } - return null; - } - - protected String defaultDiscriminatorValue() { - //TODO default discriminator value - return null; - } - - protected boolean discriminatorValueIsAllowed() { - JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); - return javaResourcePersistentType == null ? false : !javaResourcePersistentType.isAbstract(); - } - - protected void updateInheritance(Inheritance inheritanceResource) { - this.setSpecifiedInheritanceStrategy_(this.specifiedInheritanceStrategy(inheritanceResource)); - this.setDefaultInheritanceStrategy(this.defaultInheritanceStrategy()); - } - - protected void updateSpecifiedSecondaryTables(XmlEntity entity) { - ListIterator<OrmSecondaryTable> secondaryTables = specifiedSecondaryTables(); - ListIterator<XmlSecondaryTable> resourceSecondaryTables = new CloneListIterator<XmlSecondaryTable>(entity.getSecondaryTables());//prevent ConcurrentModificiationException - - while (secondaryTables.hasNext()) { - OrmSecondaryTable secondaryTable = secondaryTables.next(); - if (resourceSecondaryTables.hasNext()) { - secondaryTable.update(resourceSecondaryTables.next()); - } - else { - removeSpecifiedSecondaryTable_(secondaryTable); - } - } - - while (resourceSecondaryTables.hasNext()) { - addSpecifiedSecondaryTable(specifiedSecondaryTablesSize(), buildSecondaryTable(resourceSecondaryTables.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 getJpaFactory().buildOrmSecondaryTable(this, xmlSecondaryTable); - } - - protected OrmSecondaryTable buildVirtualSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - return buildSecondaryTable(new VirtualXmlSecondaryTable(javaSecondaryTable)); - } - - protected void updateTableGenerator(XmlEntity entity) { - if (entity.getTableGenerator() == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(entity.getTableGenerator())); - } - else { - getTableGenerator().update(entity.getTableGenerator()); - } - } - } - - protected void updateSequenceGenerator(XmlEntity entity) { - if (entity.getSequenceGenerator() == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(entity.getSequenceGenerator())); - } - else { - getSequenceGenerator().update(entity.getSequenceGenerator()); - } - } - } - - protected InheritanceType specifiedInheritanceStrategy(Inheritance inheritanceResource) { - if (inheritanceResource == null) { - return null; - } - return InheritanceType.fromOrmResourceModel(inheritanceResource.getStrategy()); - } - - protected InheritanceType defaultInheritanceStrategy() { - if (inheritanceResource() == null && !isMetadataComplete()) { - if (getJavaEntity() != null) { - return getJavaEntity().getInheritanceStrategy(); - } - } - if (getRootEntity() == this) { - return InheritanceType.SINGLE_TABLE; - } - return getRootEntity().getInheritanceStrategy(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(XmlEntity entity) { - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePrimaryKeyJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(entity.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - - while (primaryKeyJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.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 primaryKeyJoinColumn) { - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - ormPrimaryKeyJoinColumn.initialize(primaryKeyJoinColumn); - return ormPrimaryKeyJoinColumn; - } - - protected void updateSpecifiedAttributeOverrides(XmlEntity entity) { - ListIterator<OrmAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<XmlAttributeOverride> resourceAttributeOverrides = new CloneListIterator<XmlAttributeOverride>(entity.getAttributeOverrides());//prevent ConcurrentModificiationException - - while (attributeOverrides.hasNext()) { - OrmAttributeOverride attributeOverride = attributeOverrides.next(); - if (resourceAttributeOverrides.hasNext()) { - attributeOverride.update(resourceAttributeOverrides.next()); - } - else { - removeSpecifiedAttributeOverride_(attributeOverride); - } - } - - while (resourceAttributeOverrides.hasNext()) { - addSpecifiedAttributeOverride(specifiedAttributeOverridesSize(), buildAttributeOverride(resourceAttributeOverrides.next())); - } - } - - protected void updateVirtualAttributeOverrides() { - Iterator<PersistentAttribute> overridableAttributes = allOverridableAttributes(); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = virtualAttributeOverrides(); - - for (PersistentAttribute persistentAttribute : CollectionTools.iterable(overridableAttributes)) { - OrmAttributeOverride ormAttributeOverride = getAttributeOverrideNamed(persistentAttribute.getName()); - if (ormAttributeOverride != null && !ormAttributeOverride.isVirtual()) { - continue; - } - JavaAttributeOverride javaAttributeOverride = null; - if (getJavaEntity() != null) { - javaAttributeOverride = getJavaEntity().getAttributeOverrideNamed(persistentAttribute.getName()); - } - if (ormAttributeOverride != null) { - if (virtualAttributeOverrides.hasNext()) { - OrmAttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - virtualAttributeOverride.update(buildVirtualXmlAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - else { - addVirtualAttributeOverride(buildVirtualAttributeOverride(persistentAttribute, javaAttributeOverride)); - } - } - for (OrmAttributeOverride virtualAttributeOverride : CollectionTools.iterable(virtualAttributeOverrides)) { - removeVirtualAttributeOverride(virtualAttributeOverride); - } - } - - protected OrmAttributeOverride buildAttributeOverride(XmlAttributeOverride attributeOverride) { - return getJpaFactory().buildOrmAttributeOverride(this, createAttributeOverrideOwner(), attributeOverride); - } - - protected AttributeOverride.Owner createAttributeOverrideOwner() { - return new AttributeOverrideOwner(); - } - - protected void updateSpecifiedAssociationOverrides(XmlEntity entity) { - ListIterator<OrmAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - ListIterator<XmlAssociationOverride> resourceAssociationOverrides = new CloneListIterator<XmlAssociationOverride>(entity.getAssociationOverrides());//prevent ConcurrentModificiationException - - while (associationOverrides.hasNext()) { - OrmAssociationOverride associationOverride = associationOverrides.next(); - if (resourceAssociationOverrides.hasNext()) { - associationOverride.update(resourceAssociationOverrides.next()); - } - else { - removeSpecifiedAssociationOverride_(associationOverride); - } - } - - while (resourceAssociationOverrides.hasNext()) { - addSpecifiedAssociationOverride(specifiedAssociationOverridesSize(), buildAssociationOverride(resourceAssociationOverrides.next())); - } - } - - protected OrmAssociationOverride buildAssociationOverride(XmlAssociationOverride associationOverride) { - return getJpaFactory().buildOrmAssociationOverride(this, createAssociationOverrideOwner(), associationOverride); - } - - protected AssociationOverride.Owner createAssociationOverrideOwner() { - return new AssociationOverrideOwner(); - } - - protected void updateNamedQueries(XmlEntity entity) { - ListIterator<OrmNamedQuery> namedQueries = namedQueries(); - ListIterator<XmlNamedQuery> resourceNamedQueries = new CloneListIterator<XmlNamedQuery>(entity.getNamedQueries());//prevent ConcurrentModificiationException - - while (namedQueries.hasNext()) { - OrmNamedQuery namedQuery = namedQueries.next(); - if (resourceNamedQueries.hasNext()) { - namedQuery.update(resourceNamedQueries.next()); - } - else { - removeNamedQuery_(namedQuery); - } - } - - while (resourceNamedQueries.hasNext()) { - addNamedQuery(namedQueriesSize(), buildNamedQuery(resourceNamedQueries.next())); - } - } - - protected OrmNamedQuery buildNamedQuery(XmlNamedQuery namedQuery) { - OrmNamedQuery ormNamedQuery = getJpaFactory().buildOrmNamedQuery(this); - ormNamedQuery.initialize(namedQuery); - return ormNamedQuery; - } - - protected void updateNamedNativeQueries(XmlEntity entity) { - ListIterator<OrmNamedNativeQuery> namedNativeQueries = namedNativeQueries(); - ListIterator<XmlNamedNativeQuery> resourceNamedNativeQueries = new CloneListIterator<XmlNamedNativeQuery>(entity.getNamedNativeQueries());//prevent ConcurrentModificiationException - - while (namedNativeQueries.hasNext()) { - OrmNamedNativeQuery namedQuery = namedNativeQueries.next(); - if (resourceNamedNativeQueries.hasNext()) { - namedQuery.update(resourceNamedNativeQueries.next()); - } - else { - removeNamedNativeQuery_(namedQuery); - } - } - - while (resourceNamedNativeQueries.hasNext()) { - addNamedNativeQuery(namedNativeQueriesSize(), buildNamedNativeQuery(resourceNamedNativeQueries.next())); - } - } - - protected OrmNamedNativeQuery buildNamedNativeQuery(XmlNamedNativeQuery namedQuery) { - OrmNamedNativeQuery ormNamedNativeQuery = getJpaFactory().buildOrmNamedNativeQuery(this); - ormNamedNativeQuery.initialize(namedQuery); - return ormNamedNativeQuery; - } - - protected void updateIdClass(XmlIdClass idClassResource) { - this.setIdClass_(this.idClass(idClassResource)); - } - - protected void updatePersistenceUnitGeneratorsAndQueries() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - - for (Query query : CollectionTools.iterable(namedQueries())) { - getPersistenceUnit().addQuery(query); - } - - for (Query query : CollectionTools.iterable(namedNativeQueries())) { - getPersistenceUnit().addQuery(query); - } - } - - - // ************************************************************************* - - public String getPrimaryKeyColumnName() { - return getPrimaryKeyColumnName(getPersistentType().allAttributes()); - } - - //copied in GenericJavaEntity to avoid an API change for fixing bug 229423 in RC1 - public String getPrimaryKeyColumnName(Iterator<PersistentAttribute> attributes) { - String pkColumnName = null; - for (Iterator<PersistentAttribute> stream = attributes; stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - String name = attribute.getPrimaryKeyColumnName(); - if (name != null) { - //if the attribute is a primary key then we need to check if there is an attribute override - //and use its column name instead (bug 229423) - AttributeOverride attributeOverride = getAttributeOverrideNamed(attribute.getName()); - if (attributeOverride != null) { - name = attributeOverride.getColumn().getName(); - } - } - 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; - } - - //********** Validation ************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - getTable().addToMessages(messages); - addIdMessages(messages); - addGeneratorMessages(messages); - addQueryMessages(messages); - for (OrmSecondaryTable secondaryTable : CollectionTools.iterable(secondaryTables())) { - secondaryTable.addToMessages(messages); - } - - for (OrmAttributeOverride attributeOverride : CollectionTools.iterable(attributeOverrides())) { - attributeOverride.addToMessages(messages); - } - - for (OrmAssociationOverride associationOverride : CollectionTools.iterable(associationOverrides())) { - associationOverride.addToMessages(messages); - } - } - - protected void addIdMessages(List<IMessage> messages) { - addNoIdMessage(messages); - } - - protected void addNoIdMessage(List<IMessage> messages) { - if (entityHasNoId()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_NO_ID, - new String[] {this.getName()}, - this, - this.getValidationTextRange()) - ); - } - } - - private boolean entityHasNoId() { - return ! this.entityHasId(); - } - - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = this.generators(); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } - - protected void addQueryMessages(List<IMessage> messages) { - List<Query> masterList = CollectionTools.list(getPersistenceUnit().allQueries()); - - for (Iterator<OrmQuery> stream = this.queries(); stream.hasNext() ; ) { - OrmQuery current = stream.next(); - masterList.remove(current); - - for (Query each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } - - private boolean entityHasId() { - for (Iterator<PersistentAttribute> stream = this.getPersistentType().allAttributes(); stream.hasNext(); ) { - if (stream.next().isIdAttribute()) { - return true; - } - } - return false; - } - - public TypeMapping typeMapping() { - return this; - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getEntities().remove(this.getTypeMappingResource()); - } - - public XmlEntity addToResourceModel(XmlEntityMappings entityMappings) { - XmlEntity entity = OrmFactory.eINSTANCE.createXmlEntity(); - getPersistentType().initialize(entity); - entityMappings.getEntities().add(entity); - return entity; - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - return GenericOrmEntity.this.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity parentEntity = GenericOrmEntity.this.getParentEntity(); - return (parentEntity == null) ? null : parentEntity.getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericOrmEntity.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmEntity.this.defaultPrimaryKeyJoinColumns.contains(joinColumn); - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return GenericOrmEntity.this.getParentEntity().getPrimaryKeyColumnName(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - } - - class AttributeOverrideOwner implements AttributeOverride.Owner { - - public ColumnMapping getColumnMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof ColumnMapping) { - return (ColumnMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmEntity.this.virtualAttributeOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - return GenericOrmEntity.this.setAttributeOverrideVirtual(virtual, (OrmAttributeOverride) override); - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - - } - - class AssociationOverrideOwner implements AssociationOverride.Owner { - - public RelationshipMapping getRelationshipMapping(String attributeName) { - if (attributeName == null) { - return null; - } - for (Iterator<PersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute persAttribute = stream.next(); - if (attributeName.equals(persAttribute.getName())) { - if (persAttribute.getMapping() instanceof RelationshipMapping) { - return (RelationshipMapping) persAttribute.getMapping(); - } - } - } - return null; - } - - public boolean isVirtual(BaseOverride override) { - return GenericOrmEntity.this.virtualAssociationOverrides.contains(override); - } - - public BaseOverride setVirtual(boolean virtual, BaseOverride override) { - // TODO Auto-generated method stub - return null; - } - - public TypeMapping getTypeMapping() { - return GenericOrmEntity.this; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java deleted file mode 100644 index 2fe5dac4af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericOrmGeneratedValue extends AbstractOrmJpaContextNode implements OrmGeneratedValue -{ - - protected GenerationType specifiedStrategy; - - protected String specifiedGenerator; - protected String defaultGenerator; - - protected XmlGeneratedValue generatedValue; - - public GenericOrmGeneratedValue(OrmJpaContextNode parent) { - super(parent); - } - - @Override - public OrmJpaContextNode getParent() { - return (OrmJpaContextNode) super.getParent(); - } - - public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); - } - - public GenerationType getDefaultStrategy() { - return GeneratedValue.DEFAULT_STRATEGY; - } - - public GenerationType getSpecifiedStrategy() { - return this.specifiedStrategy; - } - - public void setSpecifiedStrategy(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - this.generatedValue.setStrategy(GenerationType.toOrmResourceModel(newSpecifiedStrategy)); - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); - } - - protected void setSpecifiedStrategy_(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); - } - - public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); - } - - public String getDefaultGenerator() { - return this.defaultGenerator; - } - - protected void setDefaultGenerator(String newDefaultGenerator) { - String oldGenerator = this.defaultGenerator; - this.defaultGenerator = newDefaultGenerator; - firePropertyChanged(DEFAULT_GENERATOR_PROPERTY, oldGenerator, newDefaultGenerator); - } - - public String getSpecifiedGenerator() { - return this.specifiedGenerator; - } - - public void setSpecifiedGenerator(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - this.generatedValue.setGenerator(newSpecifiedGenerator); - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); - } - - protected void setSpecifiedGenerator_(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); - } - - public TextRange getGeneratorTextRange() { - TextRange textRange = this.generatedValue.getGeneratorTextRange(); - return textRange != null ? textRange : getValidationTextRange(); - } - - - // ********** resource model -> java context model ********** - - public void initialize(XmlGeneratedValue generatedValue) { - this.generatedValue = generatedValue; - this.specifiedStrategy = this.strategy(generatedValue); - this.specifiedGenerator = this.generator(generatedValue); - //TODO - this.defaultGenerator = null; - } - - public void update(XmlGeneratedValue generatedValue) { - this.generatedValue = generatedValue; - this.setSpecifiedStrategy_(this.strategy(generatedValue)); - this.setSpecifiedGenerator_(this.generator(generatedValue)); - //TODO - this.setDefaultGenerator(null); - } - - protected GenerationType strategy(XmlGeneratedValue generatedValue) { - return GenerationType.fromOrmResourceModel(generatedValue.getStrategy()); - } - - protected String generator(XmlGeneratedValue generatedValue) { - return generatedValue.getGenerator(); - } - - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.generatedValue.getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java deleted file mode 100644 index 04b3f75f3b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java +++ /dev/null @@ -1,494 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.ColumnMapping; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.TemporalType; -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.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -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.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.db.Table; -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.SingleElementIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmIdMapping extends AbstractOrmAttributeMapping<XmlId> - implements OrmIdMapping -{ - protected final OrmColumn column; - - protected OrmGeneratedValue generatedValue; - - protected TemporalType temporal; - - protected OrmTableGenerator tableGenerator; - protected OrmSequenceGenerator sequenceGenerator; - - - public GenericOrmIdMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - - 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 initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - - public OrmColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public OrmGeneratedValue addGeneratedValue() { - if (getGeneratedValue() != null) { - throw new IllegalStateException("gemeratedValue already exists"); - } - this.generatedValue = getJpaFactory().buildOrmGeneratedValue(this); - this.getAttributeMapping().setGeneratedValue(OrmFactory.eINSTANCE.createXmlGeneratedValueImpl()); - 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"); - } - OrmGeneratedValue oldGeneratedValue = this.generatedValue; - this.generatedValue = null; - this.getAttributeMapping().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 OrmSequenceGenerator addSequenceGenerator() { - if (getSequenceGenerator() != null) { - throw new IllegalStateException("sequenceGenerator already exists"); - } - this.sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - this.getAttributeMapping().setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); - return this.sequenceGenerator; - } - - public void removeSequenceGenerator() { - if (getSequenceGenerator() == null) { - throw new IllegalStateException("sequenceGenerator does not exist, cannot be removed"); - } - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = null; - this.getAttributeMapping().setSequenceGenerator(null); - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, null); - } - - public OrmSequenceGenerator getSequenceGenerator() { - return this.sequenceGenerator; - } - - protected void setSequenceGenerator(OrmSequenceGenerator newSequenceGenerator) { - OrmSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; - this.sequenceGenerator = newSequenceGenerator; - firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator, newSequenceGenerator); - } - - public OrmTableGenerator addTableGenerator() { - if (getTableGenerator() != null) { - throw new IllegalStateException("tableGenerator already exists"); - } - this.tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - this.getAttributeMapping().setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); - return this.tableGenerator; - } - - public void removeTableGenerator() { - if (getTableGenerator() == null) { - throw new IllegalStateException("tableGenerator does not exist, cannot be removed"); - } - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = null; - this.getAttributeMapping().setTableGenerator(null); - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); - } - - public OrmTableGenerator getTableGenerator() { - return this.tableGenerator; - } - - protected void setTableGenerator(OrmTableGenerator newTableGenerator) { - OrmTableGenerator oldTableGenerator = this.tableGenerator; - this.tableGenerator = newTableGenerator; - firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, newTableGenerator); - } - - @SuppressWarnings("unchecked") - protected Iterator<OrmGenerator> generators() { - return new CompositeIterator<OrmGenerator>( - (getSequenceGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getSequenceGenerator()), - (getTableGenerator() == null) ? EmptyIterator.instance() : new SingleElementIterator(getTableGenerator())); - } - - @Override - public String getPrimaryKeyColumnName() { - return this.getColumn().getName(); - } - - @Override - public boolean isOverridableAttributeMapping() { - return true; - } - - @Override - public boolean isIdMapping() { - return true; - } - - public XmlId addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlId id = OrmFactory.eINSTANCE.createXmlIdImpl(); - getPersistentAttribute().initialize(id); - typeMapping.getAttributes().getIds().add(id); - return id; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getIds().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - @Override - public void initialize(XmlId id) { - super.initialize(id); - this.temporal = this.specifiedTemporal(id); - this.column.initialize(id.getColumn()); - this.initializeSequenceGenerator(id); - this.initializeTableGenerator(id); - this.initializeGeneratedValue(id); - this.updatePersistenceUnitGenerators(); - } - - protected TemporalType specifiedTemporal(XmlId id) { - return TemporalType.fromOrmResourceModel(id.getTemporal()); - } - - protected void initializeSequenceGenerator(XmlId id) { - if (id.getSequenceGenerator() != null) { - this.sequenceGenerator = buildSequenceGenerator(id.getSequenceGenerator()); - } - } - - protected OrmSequenceGenerator buildSequenceGenerator(XmlSequenceGenerator xmlSequenceGenerator) { - OrmSequenceGenerator sequenceGenerator = getJpaFactory().buildOrmSequenceGenerator(this); - sequenceGenerator.initialize(xmlSequenceGenerator); - return sequenceGenerator; - } - - protected void initializeTableGenerator(XmlId id) { - if (id.getTableGenerator() != null) { - this.tableGenerator = buildTableGenerator(id.getTableGenerator()); - } - } - - protected OrmTableGenerator buildTableGenerator(XmlTableGenerator tableGeneratorResource) { - OrmTableGenerator tableGenerator = getJpaFactory().buildOrmTableGenerator(this); - tableGenerator.initialize(tableGeneratorResource); - return tableGenerator; - } - - protected void initializeGeneratedValue(XmlId id) { - if (id.getGeneratedValue() != null) { - this.generatedValue = buildGeneratedValue(id.getGeneratedValue()); - } - } - - protected OrmGeneratedValue buildGeneratedValue(XmlGeneratedValue xmlGeneratedValue) { - OrmGeneratedValue ormGeneratedValue = getJpaFactory().buildOrmGeneratedValue(this); - ormGeneratedValue.initialize(xmlGeneratedValue); - return ormGeneratedValue; - } - @Override - public void update(XmlId id) { - super.update(id); - this.setTemporal_(this.specifiedTemporal(id)); - this.column.update(id.getColumn()); - this.updateSequenceGenerator(id); - this.updateTableGenerator(id); - this.updateGeneratedValue(id); - this.updatePersistenceUnitGenerators(); - } - - protected void updateSequenceGenerator(XmlId id) { - if (id.getSequenceGenerator() == null) { - if (getSequenceGenerator() != null) { - setSequenceGenerator(null); - } - } - else { - if (getSequenceGenerator() == null) { - setSequenceGenerator(buildSequenceGenerator(id.getSequenceGenerator())); - } - else { - getSequenceGenerator().update(id.getSequenceGenerator()); - } - } - } - - protected void updateTableGenerator(XmlId id) { - if (id.getTableGenerator() == null) { - if (getTableGenerator() != null) { - setTableGenerator(null); - } - } - else { - if (getTableGenerator() == null) { - setTableGenerator(buildTableGenerator(id.getTableGenerator())); - } - else { - getTableGenerator().update(id.getTableGenerator()); - } - } - } - - protected void updateGeneratedValue(XmlId id) { - if (id.getGeneratedValue() == null) { - if (getGeneratedValue() != null) { - setGeneratedValue(null); - } - } - else { - if (getGeneratedValue() == null) { - setGeneratedValue(buildGeneratedValue(id.getGeneratedValue())); - getGeneratedValue().initialize(id.getGeneratedValue()); - } - else { - getGeneratedValue().update(id.getGeneratedValue()); - } - } - } - - protected void updatePersistenceUnitGenerators() { - if (getTableGenerator() != null) { - getPersistenceUnit().addGenerator(getTableGenerator()); - } - - if (getSequenceGenerator() != null) { - getPersistenceUnit().addGenerator(getSequenceGenerator()); - } - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned()) { - addColumnMessages(messages); - } - addGeneratedValueMessages(messages); - addGeneratorMessages(messages); - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = this.connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getPersistentAttribute().getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getPersistentAttribute().getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } - - protected void addGeneratedValueMessages(List<IMessage> messages) { - OrmGeneratedValue generatedValue = getGeneratedValue(); - if (generatedValue == null) { - return; - } - String generatorName = generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Generator nextMasterGenerator : CollectionTools.iterable(getPersistenceUnit().allGenerators())) { - if (generatorName.equals(nextMasterGenerator.getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - generatedValue.getGeneratorTextRange()) - ); - } - - protected void addGeneratorMessages(List<IMessage> messages) { - List<Generator> masterList = CollectionTools.list(getPersistenceUnit().allGenerators()); - - for (Iterator<OrmGenerator> stream = this.generators(); stream.hasNext() ; ) { - OrmGenerator current = stream.next(); - if (current.isVirtual()) { - return; - } - masterList.remove(current); - - for (Generator each : masterList) { - if (! each.overrides(current) && each.getName() != null && each.getName().equals(current.getName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {current.getName()}, - current, - current.getNameTextRange()) - ); - } - } - - masterList.add(current); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java deleted file mode 100644 index 6a8c21895d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinColumn.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -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.resource.orm.XmlJoinColumn; -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; - -public class GenericOrmJoinColumn extends AbstractOrmBaseColumn<XmlJoinColumn> implements OrmJoinColumn -{ - - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected XmlJoinColumn joinColumn; - - public GenericOrmJoinColumn(OrmJpaContextNode parent, OrmJoinColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(JoinColumn oldColumn) { - super.initializeFrom(oldColumn); - setSpecifiedReferencedColumnName(oldColumn.getSpecifiedReferencedColumnName()); - } - - public String getReferencedColumnName() { - return (this.getSpecifiedReferencedColumnName() == null) ? getDefaultReferencedColumnName() : this.getSpecifiedReferencedColumnName(); - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - public OrmJoinColumn.Owner getOwner() { - return (OrmJoinColumn.Owner) this.owner; - } - - public Table dbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - public Column getDbReferencedColumn() { - Table table = dbReferencedColumnTable(); - return (table == null) ? null : table.columnNamed(getReferencedColumnName()); - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - @Override - protected XmlJoinColumn getColumnResource() { - return this.joinColumn; - } - - @Override - protected void addColumnResource() { - //joinColumns are part of a collection, the join-column element will be removed/added - //when the XmlJoinColumn is removed/added to the XmlEntity collection - } - - @Override - protected void removeColumnResource() { - //joinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlJoinColumn is removed/added to the XmlEntity collection - } - - - @Override - public void initialize(XmlJoinColumn column) { - this.joinColumn = column; - super.initialize(column); - this.specifiedReferencedColumnName = specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = defaultReferencedColumnName(); - } - - @Override - public void update(XmlJoinColumn column) { - this.joinColumn = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(XmlJoinColumn column) { - return column == null ? null : column.getReferencedColumnName(); - } - - @Override - protected String defaultName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!getOwner().getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultName(this); - } - - protected String defaultReferencedColumnName() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - return MappingTools.buildJoinColumnDefaultReferencedColumnName(this); - } - - @Override - protected String defaultTable() { - RelationshipMapping relationshipMapping = getOwner().getRelationshipMapping(); - if (relationshipMapping == null) { - return null; - } - if (!relationshipMapping.isRelationshipOwner()) { - return null; - } - return super.defaultTable(); - } - - - //******************* validation *********************** - - /** used internally as a mechanism to short circuit continued message adding */ - private boolean doContinue; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.doContinue = this.connectionProfileIsActive(); - - OrmRelationshipMapping mapping = (OrmRelationshipMapping) getOwner().getRelationshipMapping(); - //TODO why is this commented out? i copied it like this from the maintenance stream -// if (doContinue && typeMapping.tableNameIsInvalid(table)) { -// if (mapping.isVirtual()) { -// messages.add( -// JpaValidationMessages.buildMessage( -// IMessage.HIGH_SEVERITY, -// IJpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, -// new String[] {mapping.getPersistentAttribute().getName(), table, column.getName()}, -// column, column.getTableTextRange()) -// ); -// } -// else { -// messages.add( -// JpaValidationMessages.buildMessage( -// IMessage.HIGH_SEVERITY, -// IJpaValidationMessages.COLUMN_UNRESOLVED_TABLE, -// new String[] {table, column.getName()}, -// column, column.getTableTextRange()) -// ); -// } -// doContinue = false; -// } -// - if (this.doContinue && ! isResolved()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {mapping.getName(), getName()}, - this, - getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java deleted file mode 100644 index 03e0a0a091..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmJoinTable.java +++ /dev/null @@ -1,698 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.AttributeMapping; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.NonOwningMapping; -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.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -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.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -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; - - -public class GenericOrmJoinTable extends AbstractOrmTable implements OrmJoinTable -{ - - protected final List<OrmJoinColumn> specifiedJoinColumns; - - protected OrmJoinColumn defaultJoinColumn; - - protected final List<OrmJoinColumn> specifiedInverseJoinColumns; - - protected OrmJoinColumn defaultInverseJoinColumn; - - protected XmlRelationshipMapping relationshipMappingResource; - - public GenericOrmJoinTable(OrmRelationshipMapping parent) { - super(parent); - this.specifiedJoinColumns = new ArrayList<OrmJoinColumn>(); - this.specifiedInverseJoinColumns = new ArrayList<OrmJoinColumn>(); - } - - @Override - public OrmRelationshipMapping getParent() { - return (OrmRelationshipMapping) super.getParent(); - } - - public OrmRelationshipMapping getRelationshipMapping() { - return getParent(); - } - - public void initializeFrom(JoinTable oldJoinTable) { - super.initializeFrom(oldJoinTable); - int index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldJoinTable.specifiedJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - index = 0; - for (JoinColumn joinColumn : CollectionTools.iterable(oldJoinTable.specifiedInverseJoinColumns())) { - OrmJoinColumn newJoinColumn = addSpecifiedInverseJoinColumn(index++); - newJoinColumn.initializeFrom(joinColumn); - } - } - - //******************* AbstractOrmTable implementation ***************** - - @Override - protected String defaultCatalog() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return getEntityMappings().getCatalog(); - } - - @Override - protected String defaultName() { - return MappingTools.buildJoinTableDefaultName(getRelationshipMapping()); - } - - @Override - protected String defaultSchema() { - if (!getRelationshipMapping().isRelationshipOwner()) { - return null; - } - return getEntityMappings().getSchema(); - } - - @Override - protected void removeTableResource() { - this.relationshipMappingResource.setJoinTable(null); - } - - @Override - protected void addTableResource() { - this.relationshipMappingResource.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - - } - - @Override - protected XmlJoinTable getTableResource() { - return this.relationshipMappingResource.getJoinTable(); - } - - - //******************* JoinTable implementation ***************** - - //****************** join columns ********************** - public ListIterator<OrmJoinColumn> joinColumns() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumns() : this.defaultJoinColumns(); - } - - public int joinColumnsSize() { - return this.containsSpecifiedJoinColumns() ? this.specifiedJoinColumnsSize() : this.defaultJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> specifiedJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedJoinColumns); - } - - public int specifiedJoinColumnsSize() { - return this.specifiedJoinColumns.size(); - } - - 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; - } - - public OrmJoinColumn getDefaultJoinColumn() { - return this.defaultJoinColumn; - } - - protected void setDefaultJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultJoinColumn; - this.defaultJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - public boolean containsSpecifiedJoinColumns() { - return !this.specifiedJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedJoinColumn(int index) { - if (getTableResource() == null) { - addTableResource(); - } - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - this.specifiedJoinColumns.add(index, joinColumn); - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - joinColumn.initialize(xmlJoinColumn); - this.getTableResource().getJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedJoinColumn(this.specifiedJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedJoinColumns.remove(index); - if (!containsSpecifiedJoinColumns()) { - //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 = buildJoinColumn(null); - } - this.getTableResource().getJoinColumns().remove(index); - fireItemRemoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_JOIN_COLUMN, null, this.defaultJoinColumn); - } - } - - protected void removeSpecifiedJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedJoinColumns, JoinTable.SPECIFIED_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedJoinColumns, targetIndex, sourceIndex); - this.getTableResource().getJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - //****************** inverse join columns ********************** - - public ListIterator<OrmJoinColumn> inverseJoinColumns() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumns() : this.defaultInverseJoinColumns(); - } - - public int inverseJoinColumnsSize() { - return this.containsSpecifiedInverseJoinColumns() ? this.specifiedInverseJoinColumnsSize() : this.defaultInverseJoinColumnsSize(); - } - - public ListIterator<OrmJoinColumn> specifiedInverseJoinColumns() { - return new CloneListIterator<OrmJoinColumn>(this.specifiedInverseJoinColumns); - } - - public int specifiedInverseJoinColumnsSize() { - return this.specifiedInverseJoinColumns.size(); - } - - protected ListIterator<OrmJoinColumn> defaultInverseJoinColumns() { - if (this.defaultInverseJoinColumn != null) { - return new SingleElementListIterator<OrmJoinColumn>(this.defaultInverseJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultInverseJoinColumnsSize() { - return (this.defaultInverseJoinColumn == null) ? 0 : 1; - } - - public OrmJoinColumn getDefaultInverseJoinColumn() { - return this.defaultInverseJoinColumn; - } - - protected void setDefaultInverseJoinColumn(OrmJoinColumn newJoinColumn) { - OrmJoinColumn oldJoinColumn = this.defaultInverseJoinColumn; - this.defaultInverseJoinColumn = newJoinColumn; - firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, oldJoinColumn, newJoinColumn); - } - - public boolean containsSpecifiedInverseJoinColumns() { - return !this.specifiedInverseJoinColumns.isEmpty(); - } - - public OrmJoinColumn addSpecifiedInverseJoinColumn(int index) { - if (getTableResource() == null) { - addTableResource(); - } - OrmJoinColumn joinColumn = getJpaFactory().buildOrmJoinColumn(this, new InverseJoinColumnOwner()); - this.specifiedInverseJoinColumns.add(index, joinColumn); - XmlJoinColumn xmlJoinColumn = OrmFactory.eINSTANCE.createXmlJoinColumnImpl(); - joinColumn.initialize(xmlJoinColumn); - this.getTableResource().getInverseJoinColumns().add(index, xmlJoinColumn); - this.fireItemAdded(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, joinColumn); - return joinColumn; - } - - protected void addSpecifiedInverseJoinColumn(int index, OrmJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedInverseJoinColumn(JoinColumn joinColumn) { - this.removeSpecifiedInverseJoinColumn(this.specifiedInverseJoinColumns.indexOf(joinColumn)); - } - - public void removeSpecifiedInverseJoinColumn(int index) { - OrmJoinColumn removedJoinColumn = this.specifiedInverseJoinColumns.remove(index); - if (!containsSpecifiedInverseJoinColumns()) { - //create the defaultInverseJoinColumn 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.defaultInverseJoinColumn = buildInverseJoinColumn(null); - } - this.getTableResource().getInverseJoinColumns().remove(index); - fireItemRemoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, index, removedJoinColumn); - if (this.defaultInverseJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(JoinTable.DEFAULT_INVERSE_JOIN_COLUMN, null, this.defaultInverseJoinColumn); - } - } - - protected void removeSpecifiedInverseJoinColumn_(OrmJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.specifiedInverseJoinColumns, JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedInverseJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedInverseJoinColumns, targetIndex, sourceIndex); - this.getTableResource().getInverseJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - // ****************** OrmJoinTable implementation ***************** - public boolean isSpecified() { - return this.getTableResource() != null && getTableResource().isSpecified(); - } - - public void initialize(XmlRelationshipMapping relationshipMapping) { - this.relationshipMappingResource = relationshipMapping; - this.initialize(this.getTableResource()); - } - - public void update(XmlRelationshipMapping relationshipMapping) { - this.relationshipMappingResource = relationshipMapping; - this.update(this.getTableResource()); - } - - protected void initialize(XmlJoinTable joinTable) { - super.initialize(joinTable); - this.initializeSpecifiedJoinColumns(joinTable); - this.initializeDefaultJoinColumn(); - this.initializeSpecifiedInverseJoinColumns(joinTable); - this.initializeDefaultInverseJoinColumn(); - } - - protected void initializeSpecifiedJoinColumns(XmlJoinTable joinTable) { - if (joinTable == null) { - return; - } - for (XmlJoinColumn joinColumn : joinTable.getJoinColumns()) { - this.specifiedJoinColumns.add(buildJoinColumn(joinColumn)); - } - } - - protected void initializeDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - return; - } - this.defaultJoinColumn = buildJoinColumn(null); - } - - protected void initializeSpecifiedInverseJoinColumns(XmlJoinTable joinTable) { - if (joinTable == null) { - return; - } - for (XmlJoinColumn joinColumn : joinTable.getInverseJoinColumns()) { - this.specifiedInverseJoinColumns.add(buildInverseJoinColumn(joinColumn)); - } - } - - protected void initializeDefaultInverseJoinColumn() { - if (!shouldBuildDefaultInverseJoinColumn()) { - return; - } - this.defaultInverseJoinColumn = buildInverseJoinColumn(null); - } - - protected void update(XmlJoinTable joinTable) { - super.update(joinTable); - this.updateSpecifiedJoinColumns(joinTable); - this.updateDefaultJoinColumn(); - this.updateSpecifiedInverseJoinColumns(joinTable); - this.updateDefaultInverseJoinColumn(); - } - - protected void updateSpecifiedJoinColumns(XmlJoinTable joinTable) { - ListIterator<OrmJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<XmlJoinColumn> resourceJoinColumns = EmptyListIterator.instance(); - if (joinTable != null) { - resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(joinTable.getJoinColumns());//prevent ConcurrentModificiationException - } - - while (joinColumns.hasNext()) { - OrmJoinColumn joinColumn = joinColumns.next(); - if (resourceJoinColumns.hasNext()) { - joinColumn.update(resourceJoinColumns.next()); - } - else { - removeSpecifiedJoinColumn_(joinColumn); - } - } - - while (resourceJoinColumns.hasNext()) { - addSpecifiedJoinColumn(specifiedJoinColumnsSize(), buildJoinColumn(resourceJoinColumns.next())); - } - } - - protected boolean shouldBuildDefaultJoinColumn() { - return !containsSpecifiedJoinColumns(); - } - - protected void updateDefaultJoinColumn() { - if (!shouldBuildDefaultJoinColumn()) { - setDefaultJoinColumn(null); - return; - } - if (getDefaultJoinColumn() == null) { - this.setDefaultJoinColumn(buildJoinColumn(null)); - } - else { - this.defaultJoinColumn.update(null); - } - } - - protected void updateSpecifiedInverseJoinColumns(XmlJoinTable joinTable) { - ListIterator<OrmJoinColumn> inverseJoinColumns = specifiedInverseJoinColumns(); - ListIterator<XmlJoinColumn> resourceInverseJoinColumns = EmptyListIterator.instance(); - if (joinTable != null) { - resourceInverseJoinColumns = new CloneListIterator<XmlJoinColumn>(joinTable.getInverseJoinColumns());//prevent ConcurrentModificiationException - } - - while (inverseJoinColumns.hasNext()) { - OrmJoinColumn joinColumn = inverseJoinColumns.next(); - if (resourceInverseJoinColumns.hasNext()) { - joinColumn.update(resourceInverseJoinColumns.next()); - } - else { - removeSpecifiedInverseJoinColumn_(joinColumn); - } - } - - while (resourceInverseJoinColumns.hasNext()) { - addSpecifiedInverseJoinColumn(specifiedInverseJoinColumnsSize(), buildInverseJoinColumn(resourceInverseJoinColumns.next())); - } - } - - protected boolean shouldBuildDefaultInverseJoinColumn() { - return !containsSpecifiedInverseJoinColumns(); - } - - protected void updateDefaultInverseJoinColumn() { - if (!shouldBuildDefaultInverseJoinColumn()) { - setDefaultInverseJoinColumn(null); - return; - } - if (getDefaultInverseJoinColumn() == null) { - this.setDefaultInverseJoinColumn(buildInverseJoinColumn(null)); - } - else { - this.defaultInverseJoinColumn.update(null); - } - } - - protected OrmJoinColumn buildJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new JoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - protected OrmJoinColumn buildInverseJoinColumn(XmlJoinColumn joinColumn) { - OrmJoinColumn ormJoinColumn = getJpaFactory().buildOrmJoinColumn(this, new InverseJoinColumnOwner()); - ormJoinColumn.initialize(joinColumn); - return ormJoinColumn; - } - - - // ************************** validation *********************** - - /** used internally as a mechanism to short circuit continued message adding */ - private boolean doContinue; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.addTableMessages(messages); - - if (this.doContinue) { - for (OrmJoinColumn joinColumn : CollectionTools.iterable(joinColumns())) { - joinColumn.addToMessages(messages); - } - - for (OrmJoinColumn joinColumn : CollectionTools.iterable(inverseJoinColumns())) { - joinColumn.addToMessages(messages); - } - } - } - - protected void addTableMessages(List<IMessage> messages) { - this.doContinue = connectionProfileIsActive(); - String schema = getSchema(); - OrmRelationshipMapping mapping = getRelationshipMapping(); - - if (this.doContinue && ! hasResolvedSchema()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {mapping.getName(), schema, getName()}, - this, - getSchemaTextRange()) - ); - - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange()) - ); - } - this.doContinue = false; - } - - if (this.doContinue && ! isResolved()) { - if (mapping.getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_TABLE_UNRESOLVED_NAME, - new String[] {mapping.getName(), getName()}, - this, - getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.JOIN_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - } - /** - * just a little common behavior - */ - abstract class AbstractJoinColumnOwner implements OrmJoinColumn.Owner - { - AbstractJoinColumnOwner() { - super(); - } - - public TypeMapping getTypeMapping() { - return getRelationshipMapping().getTypeMapping(); - } - - public RelationshipMapping getRelationshipMapping() { - return GenericOrmJoinTable.this.getRelationshipMapping(); - } - - /** - * the default table name is always valid and a specified table name - * is prohibited (which will be handled elsewhere) - */ - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - /** - * the join column can only be on the join table itself - */ - public boolean tableIsAllowed() { - return false; - } - - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - if (GenericOrmJoinTable.this.getName() == null) { - return null; - } - return (GenericOrmJoinTable.this.getName().equals(tableName)) ? GenericOrmJoinTable.this.getDbTable() : null; - } - - /** - * by default, the join column is, obviously, in the join table; - * not sure whether it can be anywhere else... - */ - public String getDefaultTableName() { - return GenericOrmJoinTable.this.getName(); - } - - public TextRange getValidationTextRange() { - return GenericOrmJoinTable.this.getValidationTextRange(); - } - } - - - /** - * owner for "forward-pointer" JoinColumns; - * these point at the target/inverse entity - */ - class InverseJoinColumnOwner extends AbstractJoinColumnOwner - { - public InverseJoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericOrmJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - } - - public String getAttributeName() { - return GenericOrmJoinTable.this.getRelationshipMapping().getName(); - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - Entity targetEntity = getTargetEntity(); - return (targetEntity == null) ? null : targetEntity.getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultInverseJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.inverseJoinColumnsSize(); - } - - } - - - /** - * owner for "back-pointer" JoinColumns; - * these point at the source/owning entity - */ - class JoinColumnOwner extends AbstractJoinColumnOwner - { - public JoinColumnOwner() { - super(); - } - - public Entity getTargetEntity() { - return GenericOrmJoinTable.this.getRelationshipMapping().getEntity(); - } - - public String getAttributeName() { - Entity targetEntity = GenericOrmJoinTable.this.getRelationshipMapping().getResolvedTargetEntity(); - if (targetEntity == null) { - return null; - } - String attributeName = GenericOrmJoinTable.this.getRelationshipMapping().getName(); - for (Iterator<PersistentAttribute> stream = targetEntity.getPersistentType().allAttributes(); stream.hasNext();) { - PersistentAttribute attribute = stream.next(); - AttributeMapping mapping = attribute.getMapping(); - if (mapping instanceof NonOwningMapping) { - String mappedBy = ((NonOwningMapping) mapping).getMappedBy(); - if ((mappedBy != null) && mappedBy.equals(attributeName)) { - return attribute.getName(); - } - } - } - return null; - } - - @Override - public org.eclipse.jpt.db.Table getDbTable(String tableName) { - org.eclipse.jpt.db.Table dbTable = super.getDbTable(tableName); - if (dbTable != null) { - return dbTable; - } - return getTypeMapping().getDbTable(tableName); - } - - public org.eclipse.jpt.db.Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmJoinTable.this.defaultJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - // TODO Auto-generated method stub - return null; - } - - public int joinColumnsSize() { - return GenericOrmJoinTable.this.joinColumnsSize(); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java deleted file mode 100644 index c7341a8f49..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToManyMapping.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.AttributeMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; - -public class GenericOrmManyToManyMapping extends AbstractOrmMultiRelationshipMapping<XmlManyToMany> - implements OrmManyToManyMapping -{ - - public GenericOrmManyToManyMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToManyMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public int getXmlSequence() { - return 7; - } - - // ********** NonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - - public XmlManyToMany addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlManyToMany manyToMany = OrmFactory.eINSTANCE.createXmlManyToManyImpl(); - getPersistentAttribute().initialize(manyToMany); - typeMapping.getAttributes().getManyToManys().add(manyToMany); - return manyToMany; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getManyToManys().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java deleted file mode 100644 index 7bf9876ee8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmManyToOneMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; - - -public class GenericOrmManyToOneMapping extends AbstractOrmSingleRelationshipMapping<XmlManyToOne> - implements OrmManyToOneMapping -{ - - public GenericOrmManyToOneMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public int getXmlSequence() { - return 4; - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - //ManyToOne mapping is always the owning side - public boolean isRelationshipOwner() { - return true; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmManyToOneMapping(this); - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - public XmlManyToOne addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlManyToOne manyToOne = OrmFactory.eINSTANCE.createXmlManyToOneImpl(); - getPersistentAttribute().initialize(manyToOne); - typeMapping.getAttributes().getManyToOnes().add(manyToOne); - return manyToOne; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getManyToOnes().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java deleted file mode 100644 index c7d81fdf0f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmMappedSuperclass.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.IdClass; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; - - -public class GenericOrmMappedSuperclass extends AbstractOrmTypeMapping<XmlMappedSuperclass> - implements OrmMappedSuperclass -{ - protected String idClass; - - public GenericOrmMappedSuperclass(OrmPersistentType parent) { - super(parent); - } - - public String getIdClass() { - return this.idClass; - } - - public void setIdClass(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - if (oldIdClass != newIdClass) { - if (this.idClassResource() != null) { - this.idClassResource().setClassName(newIdClass); - if (this.idClassResource().isAllFeaturesUnset()) { - removeIdClassResource(); - } - } - else if (newIdClass != null) { - addIdClassResource(); - idClassResource().setClassName(newIdClass); - } - } - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected void setIdClass_(String newIdClass) { - String oldIdClass = this.idClass; - this.idClass = newIdClass; - firePropertyChanged(IdClass.ID_CLASS_PROPERTY, oldIdClass, newIdClass); - } - - protected XmlIdClass idClassResource() { - return getTypeMappingResource().getIdClass(); - } - - protected void addIdClassResource() { - getTypeMappingResource().setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - } - - protected void removeIdClassResource() { - getTypeMappingResource().setIdClass(null); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public boolean tableNameIsInvalid(String tableName) { - return false; - } - - public Iterator<String> associatedTableNamesIncludingInherited() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTables() { - return EmptyIterator.instance(); - } - - public Iterator<Table> associatedTablesIncludingInherited() { - return EmptyIterator.instance(); - } - - @Override - public Iterator<String> overridableAttributeNames() { - return this.namesOf(this.overridableAttributes()); - } - - @Override - public Iterator<OrmPersistentAttribute> overridableAttributes() { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - return o.isOverridableAttribute(); - } - }; - } - - @Override - public Iterator<String> overridableAssociationNames() { - return this.namesOf(this.overridableAssociations()); - } - - @Override - public Iterator<OrmPersistentAttribute> overridableAssociations() { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(this.getPersistentType().attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - return o.isOverridableAssociation(); - } - }; - } - - private Iterator<String> namesOf(Iterator<OrmPersistentAttribute> attributes) { - return new TransformationIterator<OrmPersistentAttribute, String>(attributes) { - @Override - protected String transform(OrmPersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - public int getXmlSequence() { - return 0; - } - - protected Boolean metadataComplete(XmlMappedSuperclass mappedSuperclass) { - return mappedSuperclass.getMetadataComplete(); - } - - public void removeFromResourceModel(XmlEntityMappings entityMappings) { - entityMappings.getMappedSuperclasses().remove(this.getTypeMappingResource()); - } - - public XmlMappedSuperclass addToResourceModel(XmlEntityMappings entityMappings) { - XmlMappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - getPersistentType().initialize(mappedSuperclass); - entityMappings.getMappedSuperclasses().add(mappedSuperclass); - return mappedSuperclass; - } - - - - @Override - public void initialize(XmlMappedSuperclass mappedSuperclass) { - super.initialize(mappedSuperclass); - this.initializeIdClass(this.idClassResource()); - } - - protected void initializeIdClass(XmlIdClass idClassResource) { - this.idClass = this.idClass(idClassResource); - } - - @Override - public void update(XmlMappedSuperclass mappedSuperclass) { - super.update(mappedSuperclass); - this.updateIdClass(this.idClassResource()); - } - - protected void updateIdClass(XmlIdClass idClassResource) { - this.setIdClass_(this.idClass(idClassResource)); - } - - protected String idClass(XmlIdClass idClassResource) { - return idClassResource == null ? null : idClassResource.getClassName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java deleted file mode 100644 index 11151b5175..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedNativeQuery.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.NamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; - - -public class GenericOrmNamedNativeQuery extends AbstractOrmQuery<XmlNamedNativeQuery> - implements OrmNamedNativeQuery -{ - - protected String resultClass; - - protected String resultSetMapping; - - - public GenericOrmNamedNativeQuery(OrmJpaContextNode parent) { - super(parent); - } - - public String getResultClass() { - return this.resultClass; - } - - public void setResultClass(String newResultClass) { - String oldResultClass = this.resultClass; - this.resultClass = newResultClass; - getQueryResource().setResultClass(newResultClass); - firePropertyChanged(NamedNativeQuery.RESULT_CLASS_PROPERTY, oldResultClass, newResultClass); - } - - public String getResultSetMapping() { - return this.resultSetMapping; - } - - public void setResultSetMapping(String newResultSetMapping) { - String oldResultSetMapping = this.resultSetMapping; - this.resultSetMapping = newResultSetMapping; - getQueryResource().setResultSetMapping(newResultSetMapping); - firePropertyChanged(NamedNativeQuery.RESULT_SET_MAPPING_PROPERTY, oldResultSetMapping, newResultSetMapping); - } - - - @Override - public void initialize(XmlNamedNativeQuery queryResource) { - super.initialize(queryResource); - this.resultClass = queryResource.getResultClass(); - this.resultSetMapping = queryResource.getResultSetMapping(); - } - - @Override - public void update(XmlNamedNativeQuery queryResource) { - super.update(queryResource); - this.setResultClass(queryResource.getResultClass()); - this.setResultSetMapping(queryResource.getResultSetMapping()); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java deleted file mode 100644 index 5bd004150f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNamedQuery.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; - - -public class GenericOrmNamedQuery extends AbstractOrmQuery<XmlNamedQuery> implements OrmNamedQuery -{ - - public GenericOrmNamedQuery(OrmJpaContextNode parent) { - super(parent); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java deleted file mode 100644 index 5ab796605c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmNullAttributeMapping.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; - - -public class GenericOrmNullAttributeMapping extends AbstractOrmAttributeMapping<XmlNullAttributeMapping> -{ - - public GenericOrmNullAttributeMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public int getXmlSequence() { - return -1; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmAttributeMapping(this); - } - - public String getKey() { - return null; - } - - public XmlAttributeMapping addToResourceModel(AbstractXmlTypeMapping typeMapping) { - throw new UnsupportedOperationException(); - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java deleted file mode 100644 index 430dd74a1a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToManyMapping.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.AttributeMapping; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; - - -public class GenericOrmOneToManyMapping extends AbstractOrmMultiRelationshipMapping<XmlOneToMany> - implements OrmOneToManyMapping -{ - - public GenericOrmOneToManyMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToManyMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public int getXmlSequence() { - return 5; - } - - // ********** NonOwningMapping implementation ********** - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - public XmlOneToMany addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlOneToMany oneToMany = OrmFactory.eINSTANCE.createXmlOneToManyImpl(); - getPersistentAttribute().initialize(oneToMany); - typeMapping.getAttributes().getOneToManys().add(oneToMany); - return oneToMany; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getOneToManys().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java deleted file mode 100644 index b9cf47f2f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmOneToOneMapping extends AbstractOrmSingleRelationshipMapping<XmlOneToOne> - implements OrmOneToOneMapping -{ - - protected String mappedBy; - - protected final List<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns; - - - public GenericOrmOneToOneMapping(OrmPersistentAttribute parent) { - super(parent); - this.primaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmOneToOneMapping(this); - } - - @Override - public void initializeFromXmlNonOwningMapping(NonOwningMapping oldMapping) { - super.initializeFromXmlNonOwningMapping(oldMapping); - setMappedBy(oldMapping.getMappedBy()); - } - - public boolean isRelationshipOwner() { - return getMappedBy() == null; - } - - - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.primaryKeyJoinColumns); - } - - public int primaryKeyJoinColumnsSize() { - return this.primaryKeyJoinColumns.size(); - } - - public OrmPrimaryKeyJoinColumn addPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn pkJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, new JoinColumnOwner()); - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - this.primaryKeyJoinColumns.add(index, pkJoinColumn); - this.getAttributeMapping().getPrimaryKeyJoinColumns().add(index, xmlPkJoinColumn); - pkJoinColumn.initialize(xmlPkJoinColumn); - this.fireItemAdded(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, pkJoinColumn); - return pkJoinColumn; - } - - protected void addPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn joinColumn) { - addItemToList(index, joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void removePrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removePrimaryKeyJoinColumn(this.primaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - public void removePrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn removedPkJoinColumn = this.primaryKeyJoinColumns.remove(index); - this.getAttributeMapping().getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, index, removedPkJoinColumn); - } - - protected void removePrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn joinColumn) { - removeItemFromList(joinColumn, this.primaryKeyJoinColumns, OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST); - } - - public void movePrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.primaryKeyJoinColumns, targetIndex, sourceIndex); - this.getAttributeMapping().getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(OneToOneMapping.PRIMAY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - public boolean containsPrimaryKeyJoinColumns() { - return !this.primaryKeyJoinColumns.isEmpty(); - } - - public String getMappedBy() { - return this.mappedBy; - } - - public void setMappedBy(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - getAttributeMapping().setMappedBy(newMappedBy); - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - protected void setMappedBy_(String newMappedBy) { - String oldMappedBy = this.mappedBy; - this.mappedBy = newMappedBy; - firePropertyChanged(MAPPED_BY_PROPERTY, oldMappedBy, newMappedBy); - } - - public boolean mappedByIsValid(AttributeMapping mappedByMapping) { - String mappedByKey = mappedByMapping.getKey(); - return (mappedByKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - - public TextRange getMappedByTextRange() { - TextRange mappedByTextRange = getAttributeMapping().getMappedByTextRange(); - return mappedByTextRange != null ? mappedByTextRange : getValidationTextRange(); - } - - - public int getXmlSequence() { - return 6; - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - @Override - public boolean isOverridableAssociationMapping() { - return true; - } - - public XmlOneToOne addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlOneToOne oneToOne = OrmFactory.eINSTANCE.createXmlOneToOneImpl(); - getPersistentAttribute().initialize(oneToOne); - typeMapping.getAttributes().getOneToOnes().add(oneToOne); - return oneToOne; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getOneToOnes().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - - //***************** Validation *********************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (this.getMappedBy() != null) { - addMappedByMessages(messages); - } - } - - @Override - protected boolean addJoinColumnMessages() { - if (containsPrimaryKeyJoinColumns() && !containsSpecifiedJoinColumns()) { - return false; - } - return super.addJoinColumnMessages(); - } - - protected void addMappedByMessages(List<IMessage> messages) { - String mappedBy = this.getMappedBy(); - Entity targetEntity = this.getResolvedTargetEntity(); - - if (targetEntity == null) { - // already have validation messages for that - return; - } - - PersistentAttribute attribute = targetEntity.getPersistentType().resolveAttribute(mappedBy); - - if (attribute == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_UNRESOLVED_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange()) - ); - return; - } - - if (! this.mappedByIsValid(attribute.getMapping())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_INVALID_MAPPED_BY, - new String[] {mappedBy}, - this, this.getMappedByTextRange()) - ); - return; - } - - NonOwningMapping mappedByMapping; - try { - mappedByMapping = (NonOwningMapping) attribute.getMapping(); - } catch (ClassCastException cce) { - // there is no error then - return; - } - - if (mappedByMapping.getMappedBy() != null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.MAPPING_MAPPED_BY_ON_BOTH_SIDES, - this, this.getMappedByTextRange()) - ); - } - } - - @Override - public void initialize(XmlOneToOne oneToOne) { - super.initialize(oneToOne); - this.mappedBy = oneToOne.getMappedBy(); - this.initializePrimaryKeyJoinColumns(oneToOne); - } - - protected void initializePrimaryKeyJoinColumns(XmlOneToOne oneToOne) { - if (oneToOne == null) { - return; - } - for (XmlPrimaryKeyJoinColumn pkJoinColumn : oneToOne.getPrimaryKeyJoinColumns()) { - this.primaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn(pkJoinColumn)); - } - } - - protected OrmPrimaryKeyJoinColumn buildPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn xmlPkJoinColumn) { - OrmPrimaryKeyJoinColumn ormPkJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, new JoinColumnOwner()); - ormPkJoinColumn.initialize(xmlPkJoinColumn); - return ormPkJoinColumn; - } - - - @Override - public void update(XmlOneToOne oneToOne) { - super.update(oneToOne); - this.setMappedBy_(oneToOne.getMappedBy()); - this.updatePrimaryKeyJoinColumns(oneToOne); - } - - - protected void updatePrimaryKeyJoinColumns(XmlOneToOne oneToOne) { - ListIterator<OrmPrimaryKeyJoinColumn> pkJoinColumns = primaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePkJoinColumns = EmptyListIterator.instance(); - if (oneToOne != null) { - resourcePkJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(oneToOne.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - } - - while (pkJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn pkJoinColumn = pkJoinColumns.next(); - if (resourcePkJoinColumns.hasNext()) { - pkJoinColumn.update(resourcePkJoinColumns.next()); - } - else { - removePrimaryKeyJoinColumn_(pkJoinColumn); - } - } - - while (resourcePkJoinColumns.hasNext()) { - addPrimaryKeyJoinColumn(primaryKeyJoinColumnsSize(), buildPrimaryKeyJoinColumn(resourcePkJoinColumns.next())); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java deleted file mode 100644 index 98d1a5c909..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -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.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -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.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -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.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmPersistentAttribute extends AbstractOrmJpaContextNode - implements OrmPersistentAttribute -{ - - protected List<OrmAttributeMappingProvider> attributeMappingProviders; - - protected OrmAttributeMapping attributeMapping; - - public GenericOrmPersistentAttribute(OrmPersistentType parent, String mappingKey) { - super(parent); - this.attributeMappingProviders = buildAttributeMappingProviders(); - this.attributeMapping = buildAttributeMapping(mappingKey); - } - - protected List<OrmAttributeMappingProvider> buildAttributeMappingProviders() { - List<OrmAttributeMappingProvider> list = new ArrayList<OrmAttributeMappingProvider>(); - list.add(OrmEmbeddedMappingProvider.instance()); //bug 190344 need to test default embedded before basic - list.add(OrmBasicMappingProvider.instance()); - list.add(OrmTransientMappingProvider.instance()); - list.add(OrmIdMappingProvider.instance()); - list.add(OrmManyToManyMappingProvider.instance()); - list.add(OrmOneToManyMappingProvider.instance()); - list.add(OrmManyToOneMappingProvider.instance()); - list.add(OrmOneToOneMappingProvider.instance()); - list.add(OrmVersionMappingProvider.instance()); - list.add(OrmEmbeddedIdMappingProvider.instance()); - return list; - } - - protected OrmAttributeMappingProvider attributeMappingProvider(String key) { - for (OrmAttributeMappingProvider provider : this.attributeMappingProviders) { - if (provider.getKey().equals(key)) { - return provider; - } - } - return OrmNullAttributeMappingProvider.instance(); - } - - protected OrmAttributeMapping buildAttributeMapping(String key) { - return this.attributeMappingProvider(key).buildAttributeMapping(getJpaFactory(), this); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID; - } - - public String getName() { - return getMapping().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.getMapping().getKey(); - } - - public String getDefaultMappingKey() { - return null; - } - - public void setSpecifiedMappingKey(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmAttributeMapping oldMapping = getMapping(); - this.attributeMapping = buildAttributeMapping(newMappingKey); - getPersistentType().changeMapping(this, oldMapping, this.attributeMapping); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - protected void setSpecifiedMappingKey_(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmAttributeMapping oldMapping = getMapping(); - this.attributeMapping = buildAttributeMapping(newMappingKey); - firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, this.attributeMapping); - } - - public Collection<OrmAttributeMappingProvider> attributeMappingProviders() { - return this.attributeMappingProviders; - } - - public OrmPersistentType getPersistentType() { - return (OrmPersistentType) getParent(); - } - - public OrmTypeMapping getTypeMapping() { - return getPersistentType().getMapping(); - } - - public boolean isVirtual() { - return getPersistentType().containsVirtualPersistentAttribute(this); - } - - public void makeVirtual() { - if (isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); - } - getOrmPersistentType().makePersistentAttributeVirtual(this); - } - - public void makeSpecified() { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - if (getMappingKey() == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makeSpecified(String) instead and specify a mapping type"); - } - getOrmPersistentType().makePersistentAttributeSpecified(this); - } - - public void makeSpecified(String mappingKey) { - if (!isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - getOrmPersistentType().makePersistentAttributeSpecified(this, mappingKey); - } - - public String getPrimaryKeyColumnName() { - return getMapping().getPrimaryKeyColumnName(); - } - - public boolean isOverridableAttribute() { - return this.getMapping().isOverridableAttributeMapping(); - } - - public boolean isOverridableAssociation() { - return this.getMapping().isOverridableAssociationMapping(); - } - - public boolean isIdAttribute() { - return this.getMapping().isIdMapping(); - } - - //TODO is there a way to avoid a method for every mapping type? - //I am trying to take adavantage of generics here, but it sure is - //leading to a lot of duplicated code. - KFM - public void initialize(XmlBasic basic) { - ((OrmBasicMapping) getMapping()).initialize(basic); - } - - public void initialize(XmlEmbedded embedded) { - ((OrmEmbeddedMapping) getMapping()).initialize(embedded); - } - - public void initialize(XmlVersion version) { - ((OrmVersionMapping) getMapping()).initialize(version); - } - - public void initialize(XmlManyToOne manyToOne) { - ((OrmManyToOneMapping) getMapping()).initialize(manyToOne); - } - - public void initialize(XmlOneToMany oneToMany) { - ((OrmOneToManyMapping) getMapping()).initialize(oneToMany); - } - - public void initialize(XmlOneToOne oneToOne) { - ((OrmOneToOneMapping) getMapping()).initialize(oneToOne); - } - - public void initialize(XmlManyToMany manyToMany) { - ((OrmManyToManyMapping) getMapping()).initialize(manyToMany); - } - - public void initialize(XmlId id) { - ((OrmIdMapping) getMapping()).initialize(id); - } - - public void initialize(XmlEmbeddedId embeddedId) { - ((OrmEmbeddedIdMapping) getMapping()).initialize(embeddedId); - } - - public void initialize(XmlTransient transientResource) { - ((OrmTransientMapping) getMapping()).initialize(transientResource); - } - - public void initialize(XmlNullAttributeMapping xmlNullAttributeMapping) { - ((GenericOrmNullAttributeMapping) getMapping()).initialize(xmlNullAttributeMapping); - } - - public void update(XmlId id) { - if (getMappingKey() != MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - } - ((OrmIdMapping) getMapping()).update(id); - } - - public void update(XmlEmbeddedId embeddedId) { - if (getMappingKey() != MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - } - ((OrmEmbeddedIdMapping) getMapping()).update(embeddedId); - } - - public void update(XmlBasic basic) { - if (getMappingKey() != MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - } - ((OrmBasicMapping) getMapping()).update(basic); - } - - public void update(XmlVersion version) { - if (getMappingKey() != MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - } - ((OrmVersionMapping) getMapping()).update(version); - } - - public void update(XmlManyToOne manyToOne) { - if (getMappingKey() != MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - ((OrmManyToOneMapping) getMapping()).update(manyToOne); - } - - public void update(XmlOneToMany oneToMany) { - if (getMappingKey() != MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - ((OrmOneToManyMapping) getMapping()).update(oneToMany); - } - - public void update(XmlOneToOne oneToOne) { - if (getMappingKey() != MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - } - ((OrmOneToOneMapping) getMapping()).update(oneToOne); - } - - public void update(XmlManyToMany manyToMany) { - if (getMappingKey() != MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - } - ((OrmManyToManyMapping) getMapping()).update(manyToMany); - } - - public void update(XmlEmbedded embedded) { - if (getMappingKey() != MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - } - ((OrmEmbeddedMapping) getMapping()).update(embedded); - } - - public void update(XmlTransient transientResource) { - if (getMappingKey() != MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - } - ((OrmTransientMapping) getMapping()).update(transientResource); - } - - public void update(XmlNullAttributeMapping xmlNullAttributeMapping) { - if (getMappingKey() != MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - setSpecifiedMappingKey_(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - } - ((GenericOrmNullAttributeMapping) getMapping()).update(xmlNullAttributeMapping); - } - - 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(); - } - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - getMapping().addToMessages(messages); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getPersistentType().getMapping().getAttributesTextRange(); - } - return this.attributeMapping.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - //nothing to dispose - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java deleted file mode 100644 index dc7054e620..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java +++ /dev/null @@ -1,896 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -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.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -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.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -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.context.orm.OrmTypeMappingProvider; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -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.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.XmlId; -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.XmlOneToMany; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ChainIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -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; - - -public class GenericOrmPersistentType extends AbstractOrmJpaContextNode implements OrmPersistentType -{ - protected final List<OrmPersistentAttribute> specifiedPersistentAttributes; - - protected final List<OrmPersistentAttribute> virtualPersistentAttributes; - - protected final Collection<OrmTypeMappingProvider> typeMappingProviders; - - protected OrmTypeMapping ormTypeMapping; - - protected PersistentType parentPersistentType; - - public GenericOrmPersistentType(EntityMappings parent, String mappingKey) { - super(parent); - this.typeMappingProviders = buildTypeMappingProviders(); - this.ormTypeMapping = buildOrmTypeMapping(mappingKey); - this.specifiedPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - this.virtualPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); - } - - public String getId() { - return OrmStructureNodes.PERSISTENT_TYPE_ID; - } - - public boolean isFor(String fullyQualifiedTypeName) { - String className = getMapping().getClass_(); - if (className == null) { - return false; - } - if (className.equals(fullyQualifiedTypeName)) { - return true; - } - if ((getEntityMappings().getPackage() + "." + className).equals(fullyQualifiedTypeName)) { - return true; - } - return false; - } - - protected OrmTypeMapping buildOrmTypeMapping(String key) { - return getTypeMappingProvider(key).buildTypeMapping(getJpaFactory(), this); - } - - protected Collection<OrmTypeMappingProvider> buildTypeMappingProviders() { - Collection<OrmTypeMappingProvider> collection = new ArrayList<OrmTypeMappingProvider>(); - collection.add(new OrmEntityProvider()); - collection.add(new OrmMappedSuperclassProvider()); - collection.add(new OrmEmbeddableProvider()); - return collection; - } - - protected OrmTypeMappingProvider getTypeMappingProvider(String key) { - for (OrmTypeMappingProvider provider : this.typeMappingProviders) { - if (provider.getKey().equals(key)) { - return provider; - } - } - throw new IllegalArgumentException(); - } - - public OrmTypeMapping getMapping() { - return this.ormTypeMapping; - } - - public void setMappingKey(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmTypeMapping oldMapping = getMapping(); - this.ormTypeMapping = buildOrmTypeMapping(newMappingKey); - getEntityMappings().changeMapping(this, oldMapping, this.ormTypeMapping); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.ormTypeMapping); - } - - protected void setMappingKey_(String newMappingKey) { - if (this.getMappingKey() == newMappingKey) { - return; - } - OrmTypeMapping oldMapping = getMapping(); - this.ormTypeMapping = buildOrmTypeMapping(newMappingKey); - firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.ormTypeMapping); - } - - public Iterator<PersistentType> inheritanceHierarchy() { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this) { - @Override - protected PersistentType nextLink(PersistentType pt) { - return pt.getParentPersistentType(); - } - }; - } - - public PersistentType getParentPersistentType() { - return this.parentPersistentType; - } - - public void setParentPersistentType(PersistentType newParentPersistentType) { - if (attributeValueHasNotChanged(this.parentPersistentType, newParentPersistentType)) { - return; - } - PersistentType oldParentPersistentType = this.parentPersistentType; - this.parentPersistentType = newParentPersistentType; - firePropertyChanged(PersistentType.PARENT_PERSISTENT_TYPE_PROPERTY, oldParentPersistentType, newParentPersistentType); - } - - public AccessType getAccess() { - return getMapping().getAccess(); - } - - public void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping) { - int sourceIndex = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - if (sourceIndex != -1) { - this.specifiedPersistentAttributes.remove(sourceIndex); - oldMapping.removeFromResourceModel(getMapping().getTypeMappingResource()); - } - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - int targetIndex = insertionIndex(ormPersistentAttribute); - this.specifiedPersistentAttributes.add(targetIndex, ormPersistentAttribute); - newMapping.addToResourceModel(getMapping().getTypeMappingResource()); - oldMapping.initializeOn(newMapping); - if (sourceIndex != -1) { - //TODO are the source and target correct in this case, or is target off by one??? - fireItemMoved(SPECIFIED_ATTRIBUTES_LIST, targetIndex, sourceIndex); - } - } - - public void makePersistentAttributeVirtual(OrmPersistentAttribute ormPersistentAttribute) { - if (ormPersistentAttribute.isVirtual()) { - throw new IllegalStateException("Attribute is already virtual"); - } - JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getMapping().getJavaPersistentAttribute(); - OrmPersistentAttribute virtualPersistentAttribute = null; - if (javaPersistentAttribute != null) { - virtualPersistentAttribute = createVirtualPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(virtualPersistentAttribute); - } - this.removeSpecifiedPersistentAttribute(ormPersistentAttribute); - if (virtualPersistentAttribute != null) { - fireItemAdded(VIRTUAL_ATTRIBUTES_LIST, virtualAttributesSize() - 1, virtualPersistentAttribute); - } - } - - public void makePersistentAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute) { - makePersistentAttributeSpecified(ormPersistentAttribute, ormPersistentAttribute.getMappingKey()); - } - - public void makePersistentAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute, String mappingKey) { - if (!ormPersistentAttribute.isVirtual()) { - throw new IllegalStateException("Attribute is already specified"); - } - if (mappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - throw new IllegalStateException("Use makePersistentAttributeSpecified(OrmPersistentAttribute, String) instead and specify a mapping type"); - } - - OrmPersistentAttribute newPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, mappingKey); - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - int insertionIndex = insertionIndex(newPersistentAttribute); - this.specifiedPersistentAttributes.add(insertionIndex, newPersistentAttribute); - newPersistentAttribute.getMapping().addToResourceModel(getMapping().getTypeMappingResource()); - - int removalIndex = this.virtualPersistentAttributes.indexOf(ormPersistentAttribute); - this.virtualPersistentAttributes.remove(ormPersistentAttribute); - newPersistentAttribute.getSpecifiedMapping().setName(ormPersistentAttribute.getName()); - - fireItemAdded(PersistentType.SPECIFIED_ATTRIBUTES_LIST, insertionIndex, newPersistentAttribute); - fireItemRemoved(VIRTUAL_ATTRIBUTES_LIST, removalIndex, ormPersistentAttribute); - } - - public Iterator<String> allAttributeNames() { - return this.attributeNames(this.allAttributes()); - } - - public Iterator<PersistentAttribute> allAttributes() { - return new CompositeIterator<PersistentAttribute>(new TransformationIterator<PersistentType, Iterator<PersistentAttribute>>(this.inheritanceHierarchy()) { - @Override - protected Iterator<PersistentAttribute> transform(PersistentType pt) { - return pt.attributes(); - } - }); - } - - protected Iterator<OrmPersistentAttribute> attributesNamed(final String attributeName) { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(attributes()) { - @Override - protected boolean accept(OrmPersistentAttribute o) { - if (attributeName == null && o.getName() == null) { - return true; - } - if (attributeName != null && attributeName.equals(o.getName())) { - return true; - } - return false; - } - }; - } - - public OrmPersistentAttribute getAttributeNamed(String attributeName) { - Iterator<OrmPersistentAttribute> stream = attributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - } - - public Iterator<String> attributeNames() { - return this.attributeNames(this.attributes()); - } - - protected Iterator<String> attributeNames(Iterator<? extends PersistentAttribute> attrs) { - return new TransformationIterator<PersistentAttribute, String>(attrs) { - @Override - protected String transform(PersistentAttribute attribute) { - return attribute.getName(); - } - }; - } - - protected OrmPersistentAttribute specifiedAttributeNamed(String attributeName) { - Iterator<OrmPersistentAttribute> stream = specifiedAttributesNamed(attributeName); - return (stream.hasNext()) ? stream.next() : null; - - } - - protected Iterator<OrmPersistentAttribute> specifiedAttributesNamed(final String attributeName) { - return new FilteringIterator<OrmPersistentAttribute, OrmPersistentAttribute>(specifiedAttributes()) { - @Override - protected boolean accept(OrmPersistentAttribute ormPersistentAttribute) { - return attributeName.equals(ormPersistentAttribute.getName()); - } - }; - } - - @SuppressWarnings("unchecked") - public ListIterator<OrmPersistentAttribute> attributes() { - return new CompositeListIterator<OrmPersistentAttribute>(specifiedAttributes(), virtualAttributes()); - } - - public int attributesSize() { - return specifiedAttributesSize() + virtualAttributesSize(); - } - - public ListIterator<OrmPersistentAttribute> specifiedAttributes() { - return new CloneListIterator<OrmPersistentAttribute>(this.specifiedPersistentAttributes); - } - - public int specifiedAttributesSize() { - return this.specifiedPersistentAttributes.size(); - } - - public ListIterator<OrmPersistentAttribute> virtualAttributes() { - return new CloneListIterator<OrmPersistentAttribute>(this.virtualPersistentAttributes); - } - - public int virtualAttributesSize() { - return this.virtualPersistentAttributes.size(); - } - - protected void addVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - addItemToList(ormPersistentAttribute, this.virtualPersistentAttributes, OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST); - } - - protected void removeVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.virtualPersistentAttributes, OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST); - } - - public boolean containsVirtualPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - return this.virtualPersistentAttributes.contains(ormPersistentAttribute); - } - - public OrmPersistentAttribute addSpecifiedPersistentAttribute(String mappingKey, String attributeName) { - OrmPersistentAttribute persistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, mappingKey); - int index = insertionIndex(persistentAttribute); - if (getMapping().getTypeMappingResource().getAttributes() == null) { - getMapping().getTypeMappingResource().setAttributes(OrmFactory.eINSTANCE.createAttributes()); - } - this.specifiedPersistentAttributes.add(index, persistentAttribute); - persistentAttribute.getMapping().addToResourceModel(getMapping().getTypeMappingResource()); - - persistentAttribute.getSpecifiedMapping().setName(attributeName); - fireItemAdded(PersistentType.SPECIFIED_ATTRIBUTES_LIST, index, persistentAttribute); - return persistentAttribute; - } - - protected int insertionIndex(OrmPersistentAttribute persistentAttribute) { - return CollectionTools.insertionIndexOf(this.specifiedPersistentAttributes, persistentAttribute, buildMappingComparator()); - } - - protected Comparator<OrmPersistentAttribute> buildMappingComparator() { - return new Comparator<OrmPersistentAttribute>() { - public int compare(OrmPersistentAttribute o1, OrmPersistentAttribute o2) { - int o1Sequence = o1.getMapping().getXmlSequence(); - int o2Sequence = o2.getMapping().getXmlSequence(); - if (o1Sequence < o2Sequence) { - return -1; - } - if (o1Sequence == o2Sequence) { - return 0; - } - return 1; - } - }; - } - - - protected void addSpecifiedPersistentAttribute_(OrmPersistentAttribute ormPersistentAttribute) { - addItemToList(ormPersistentAttribute, this.specifiedPersistentAttributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - protected void removeSpecifiedPersistentAttribute_(OrmPersistentAttribute ormPersistentAttribute) { - removeItemFromList(ormPersistentAttribute, this.specifiedPersistentAttributes, PersistentType.SPECIFIED_ATTRIBUTES_LIST); - } - - public void removeSpecifiedPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute) { - int index = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); - this.specifiedPersistentAttributes.remove(ormPersistentAttribute); - ormPersistentAttribute.getMapping().removeFromResourceModel(this.ormTypeMapping.getTypeMappingResource()); - fireItemRemoved(PersistentType.SPECIFIED_ATTRIBUTES_LIST, index, ormPersistentAttribute); - } - - public String getName() { - return getMapping().getClass_(); - } - - public void classChanged(String oldClass, String newClass) { - firePropertyChanged(NAME_PROPERTY, oldClass, newClass); - } - - public boolean isMapped() { - return true; - } - - public String getMappingKey() { - return getMapping().getKey(); - } - - public JavaPersistentType getJavaPersistentType() { - return getMapping().getJavaPersistentType(); - } - - - //TODO is there a way to avoid a method for every mapping type? - //I am trying to take adavantage of generics here, but it sure is - //leading to a lot of duplicated code. - KFM - public void initialize(XmlEntity entity) { - ((OrmEntity) getMapping()).initialize(entity); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(entity); - } - - public void initialize(XmlMappedSuperclass mappedSuperclass) { - ((OrmMappedSuperclass) getMapping()).initialize(mappedSuperclass); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(mappedSuperclass); - } - - public void initialize(XmlEmbeddable embeddable) { - ((OrmEmbeddable) getMapping()).initialize(embeddable); - this.initializeParentPersistentType(); - this.initializePersistentAttributes(embeddable); - } - - protected void initializePersistentAttributes(AbstractXmlTypeMapping typeMapping) { - Attributes attributes = typeMapping.getAttributes(); - if (attributes != null) { - this.initializeSpecifiedPersistentAttributes(attributes); - } - this.initializeVirtualPersistentAttributes(); - } - - protected void initializeSpecifiedPersistentAttributes(Attributes attributes) { - for (XmlId id : attributes.getIds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(id); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlEmbeddedId embeddedId : attributes.getEmbeddedIds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embeddedId); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlBasic basic : attributes.getBasics()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(basic); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlVersion version : attributes.getVersions()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(version); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlManyToOne manyToOne : attributes.getManyToOnes()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToOne); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlOneToMany oneToMany : attributes.getOneToManys()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToMany); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlOneToOne oneToOne : attributes.getOneToOnes()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToOne); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlManyToMany manyToMany : attributes.getManyToManys()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToMany); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlEmbedded embedded : attributes.getEmbeddeds()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embedded); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - for (XmlTransient transientResource : attributes.getTransients()) { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(transientResource); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); - } - } - - protected void initializeVirtualPersistentAttributes() { - ListIterator<JavaPersistentAttribute> javaAttributes = javaPersistentAttributes(); - - while (javaAttributes.hasNext()) { - JavaPersistentAttribute javaPersistentAttribute = javaAttributes.next(); - if (specifiedAttributeNamed(javaPersistentAttribute.getName()) == null) { - OrmPersistentAttribute ormPersistentAttribute = createVirtualPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(ormPersistentAttribute); - } - } - } - - protected ListIterator<JavaPersistentAttribute> javaPersistentAttributes() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - return javaPersistentType.attributes(); - } - return EmptyListIterator.instance(); - } - - protected void initializeParentPersistentType() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - if (javaPersistentType != null) { - this.parentPersistentType = javaPersistentType.getParentPersistentType(); - } - } - - public void update(XmlEntity entity) { - if (getMappingKey() != MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - } - ((OrmEntity) getMapping()).update(entity); - this.updateParentPersistentType(); - this.updatePersistentAttributes(entity); - } - - public void update(XmlMappedSuperclass mappedSuperclass) { - if (getMappingKey() != MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - } - ((OrmMappedSuperclass) getMapping()).update(mappedSuperclass); - this.updateParentPersistentType(); - this.updatePersistentAttributes(mappedSuperclass); - } - - public void update(XmlEmbeddable embeddable) { - if (getMappingKey() != MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY) { - setMappingKey_(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - } - ((OrmEmbeddable) getMapping()).update(embeddable); - this.updateParentPersistentType(); - this.updatePersistentAttributes(embeddable); - } - - protected void updateParentPersistentType() { - JavaPersistentType javaPersistentType = getJavaPersistentType(); - setParentPersistentType(javaPersistentType == null ? null : javaPersistentType.getParentPersistentType()); - } - - protected void updatePersistentAttributes(AbstractXmlTypeMapping typeMapping) { - ListIterator<OrmPersistentAttribute> ormPersistentAttributes = this.specifiedAttributes(); - if (typeMapping.getAttributes() != null) { - this.updateIds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateEmbeddedIds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateBasics(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateVersions(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateManyToOnes(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateOneToManys(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateOneToOnes(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateManyToManys(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateEmbeddeds(typeMapping.getAttributes(), ormPersistentAttributes); - this.updateTransients(typeMapping.getAttributes(), ormPersistentAttributes); - } - while (ormPersistentAttributes.hasNext()) { - this.removeSpecifiedPersistentAttribute_(ormPersistentAttributes.next()); - } - this.updateVirtualPersistentAttributes(); - } - - protected void updateVirtualAttribute(OrmPersistentAttribute ormPersistentAttribute, JavaPersistentAttribute javaAttribute) { - String javaMappingKey = javaAttribute.getMappingKey(); - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaMappingKey = javaAttribute.getDefaultMappingKey(); - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - - if (javaMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlBasic(getMapping(), (JavaBasicMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlEmbedded(getMapping(), (JavaEmbeddedMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlEmbeddedId(getMapping(), (JavaEmbeddedIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlId(getMapping(), (JavaIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlManyToMany(ormPersistentAttribute, (JavaManyToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlManyToOne((JavaManyToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlOneToMany(ormPersistentAttribute, (JavaOneToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlOneToOne((JavaOneToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlTransient((JavaTransientMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlVersion(getMapping(), (JavaVersionMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.update(new VirtualXmlNullAttributeMapping(getMapping(), javaAttributeMapping, getMapping().isMetadataComplete())); - } - } - - protected void updateVirtualPersistentAttributes() { - ListIterator<JavaPersistentAttribute> javaAttributes = this.javaPersistentAttributes(); - ListIterator<OrmPersistentAttribute> xmlVirtualAttributes = this.virtualAttributes(); - for (JavaPersistentAttribute javaAttribute : CollectionTools.iterable(javaAttributes)) { - if (specifiedAttributeNamed(javaAttribute.getName()) == null) { - if (xmlVirtualAttributes.hasNext()) { - updateVirtualAttribute(xmlVirtualAttributes.next(), javaAttribute); - } - else { - OrmPersistentAttribute ormPersistentAttribute = createVirtualPersistentAttribute(javaAttribute); - addVirtualPersistentAttribute(ormPersistentAttribute); - } - } - } - - while (xmlVirtualAttributes.hasNext()) { - this.removeVirtualPersistentAttribute(xmlVirtualAttributes.next()); - } - - } - - protected void addVirtualPersistentAttribute(JavaPersistentAttribute javaAttribute) { - addVirtualPersistentAttribute(createVirtualPersistentAttribute(javaAttribute)); - } - - protected OrmPersistentAttribute createVirtualPersistentAttribute(JavaPersistentAttribute javaAttribute) { - String javaMappingKey = javaAttribute.getMappingKey(); - JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); - if (getMapping().isMetadataComplete()) { - javaMappingKey = javaAttribute.getDefaultMappingKey(); - javaAttributeMapping = javaAttribute.getDefaultMapping(); - } - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, javaMappingKey); - - if (javaMappingKey == MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlBasic(getMapping(), (JavaBasicMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlEmbeddedId(getMapping(), (JavaEmbeddedIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlEmbedded(getMapping(), (JavaEmbeddedMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlId(getMapping(), (JavaIdMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlManyToMany(ormPersistentAttribute, (JavaManyToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlManyToOne((JavaManyToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlOneToMany(ormPersistentAttribute, (JavaOneToManyMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlOneToOne((JavaOneToOneMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlTransient((JavaTransientMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlVersion(getMapping(), (JavaVersionMapping) javaAttributeMapping, getMapping().isMetadataComplete())); - } - else if (javaMappingKey == MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - ormPersistentAttribute.initialize(new VirtualXmlNullAttributeMapping(getMapping(), javaAttributeMapping, getMapping().isMetadataComplete())); - } - return ormPersistentAttribute; - } - - protected void updateIds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlId> ids = new CloneListIterator<XmlId>(attributes.getIds());//prevent ConcurrentModificiationException - for (XmlId id : CollectionTools.iterable(ids)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(id); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(id); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateEmbeddedIds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlEmbeddedId> embeddedIds = new CloneListIterator<XmlEmbeddedId>(attributes.getEmbeddedIds());//prevent ConcurrentModificiationException - for (XmlEmbeddedId embeddedId : CollectionTools.iterable(embeddedIds)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(embeddedId); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embeddedId); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateBasics(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlBasic> basics = new CloneListIterator<XmlBasic>(attributes.getBasics());//prevent ConcurrentModificiationException - for (XmlBasic basic : CollectionTools.iterable(basics)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(basic); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(basic); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateVersions(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlVersion> versions = new CloneListIterator<XmlVersion>(attributes.getVersions());//prevent ConcurrentModificiationException - for (XmlVersion version : CollectionTools.iterable(versions)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(version); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(version); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateManyToOnes(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlManyToOne> manyToOnes = new CloneListIterator<XmlManyToOne>(attributes.getManyToOnes());//prevent ConcurrentModificiationException - for (XmlManyToOne manyToOne : CollectionTools.iterable(manyToOnes)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(manyToOne); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToOne); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateOneToManys(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlOneToMany> oneToManys = new CloneListIterator<XmlOneToMany>(attributes.getOneToManys());//prevent ConcurrentModificiationException - for (XmlOneToMany oneToMany : CollectionTools.iterable(oneToManys)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(oneToMany); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToMany); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateOneToOnes(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlOneToOne> oneToOnes = new CloneListIterator<XmlOneToOne>(attributes.getOneToOnes());//prevent ConcurrentModificiationException - for (XmlOneToOne oneToOne : CollectionTools.iterable(oneToOnes)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(oneToOne); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(oneToOne); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateManyToManys(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlManyToMany> manyToManys = new CloneListIterator<XmlManyToMany>(attributes.getManyToManys());//prevent ConcurrentModificiationException - for (XmlManyToMany manyToMany : CollectionTools.iterable(manyToManys)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(manyToMany); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(manyToMany); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateEmbeddeds(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlEmbedded> embeddeds = new CloneListIterator<XmlEmbedded>(attributes.getEmbeddeds());//prevent ConcurrentModificiationException - for (XmlEmbedded embedded : CollectionTools.iterable(embeddeds)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(embedded); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(embedded); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - protected void updateTransients(Attributes attributes, ListIterator<OrmPersistentAttribute> ormPersistentAttributes) { - ListIterator<XmlTransient> transients = new CloneListIterator<XmlTransient>(attributes.getTransients());//prevent ConcurrentModificiationException - for (XmlTransient transientResource : CollectionTools.iterable(transients)) { - if (ormPersistentAttributes.hasNext()) { - ormPersistentAttributes.next().update(transientResource); - } - else { - OrmPersistentAttribute ormPersistentAttribute = getJpaFactory().buildOrmPersistentAttribute(this, MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute.initialize(transientResource); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); - } - } - } - - public PersistentAttribute resolveAttribute(String attributeName) { - Iterator<OrmPersistentAttribute> attributes = attributesNamed(attributeName); - if (attributes.hasNext()) { - OrmPersistentAttribute attribute = attributes.next(); - return attributes.hasNext() ? null /* more than one */: attribute; - } - else if (getParentPersistentType() != null) { - return getParentPersistentType().resolveAttribute(attributeName); - } - else { - return null; - } - } - - @Override - public OrmPersistentType getOrmPersistentType() { - return this; - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (OrmPersistentAttribute attribute : CollectionTools.iterable(specifiedAttributes())) { - if (attribute.contains(textOffset)) { - return attribute; - } - } - return this; - } - - public boolean contains(int textOffset) { - return this.ormTypeMapping.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return this.ormTypeMapping.getSelectionTextRange(); - } - - //******************** validation ********************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - try { - getMapping().addToMessages(messages); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - - for (OrmPersistentAttribute persistentAttribute : CollectionTools.iterable(this.attributes())) { - try { - persistentAttribute.addToMessages(messages); - } catch(Throwable t) { - JptCorePlugin.log(t); - } - } - } - - public TextRange getValidationTextRange() { - return this.ormTypeMapping.getValidationTextRange(); - } - - public void dispose() { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java deleted file mode 100644 index 4710e4b714..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.Table; - -public class GenericOrmPrimaryKeyJoinColumn extends AbstractOrmNamedColumn<XmlPrimaryKeyJoinColumn> - implements OrmPrimaryKeyJoinColumn -{ - protected String specifiedReferencedColumnName; - - protected String defaultReferencedColumnName; - - protected XmlPrimaryKeyJoinColumn primaryKeyJoinColumn; - - public GenericOrmPrimaryKeyJoinColumn(OrmJpaContextNode parent, OrmBaseJoinColumn.Owner owner) { - super(parent, owner); - } - - public void initializeFrom(PrimaryKeyJoinColumn oldPkJoinColumn) { - super.initializeFrom(oldPkJoinColumn); - setSpecifiedReferencedColumnName(oldPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - @Override - protected XmlPrimaryKeyJoinColumn getColumnResource() { - return this.primaryKeyJoinColumn; - } - - @Override - protected void addColumnResource() { - //primaryKeyJoinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlPrimaryKeyJoinColumn is removed/added to the XmlEntity collection - } - - @Override - protected void removeColumnResource() { - //primaryKeyJoinColumns are part of a collection, the pk-join-column element will be removed/added - //when the XmlPrimaryKeyJoinColumn is removed/added to the XmlEntity collection - } - - public String getReferencedColumnName() { - return (this.getSpecifiedReferencedColumnName() == null) ? getDefaultReferencedColumnName() : this.getSpecifiedReferencedColumnName(); - } - - public String getSpecifiedReferencedColumnName() { - return this.specifiedReferencedColumnName; - } - - public void setSpecifiedReferencedColumnName(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - getColumnResource().setReferencedColumnName(newSpecifiedReferencedColumnName); - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - protected void setSpecifiedReferencedColumnName_(String newSpecifiedReferencedColumnName) { - String oldSpecifiedReferencedColumnName = this.specifiedReferencedColumnName; - this.specifiedReferencedColumnName = newSpecifiedReferencedColumnName; - firePropertyChanged(SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, oldSpecifiedReferencedColumnName, newSpecifiedReferencedColumnName); - } - - public String getDefaultReferencedColumnName() { - return this.defaultReferencedColumnName; - } - - protected void setDefaultReferencedColumnName(String newDefaultReferencedColumnName) { - String oldDefaultReferencedColumnName = this.defaultReferencedColumnName; - this.defaultReferencedColumnName = newDefaultReferencedColumnName; - firePropertyChanged(DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY, oldDefaultReferencedColumnName, newDefaultReferencedColumnName); - } - - @Override - public OrmBaseJoinColumn.Owner getOwner() { - return (OrmBaseJoinColumn.Owner) this.owner; - } - - public Column getDbReferencedColumn() { - Table table = this.dbReferencedColumnTable(); - return (table == null) ? null : table.columnNamed(this.getReferencedColumnName()); - } - - public Table dbReferencedColumnTable() { - return getOwner().getDbReferencedColumnTable(); - } - - @Override - protected String tableName() { - return this.getOwner().getTypeMapping().getTableName(); - } - - public boolean isReferencedColumnResolved() { - return getDbReferencedColumn() != null; - } - - public TextRange getReferencedColumnNameTextRange() { - if (getColumnResource() != null) { - TextRange textRange = getColumnResource().getReferencedColumnNameTextRange(); - if (textRange != null) { - return textRange; - } - } - return getOwner().getValidationTextRange(); - } - - - public boolean isVirtual() { - return getOwner().isVirtual(this); - } - - @Override - public void initialize(XmlPrimaryKeyJoinColumn column) { - this.primaryKeyJoinColumn = column; - super.initialize(column); - this.specifiedReferencedColumnName = specifiedReferencedColumnName(column); - this.defaultReferencedColumnName = defaultReferencedColumnName(); - } - - @Override - public void update(XmlPrimaryKeyJoinColumn column) { - this.primaryKeyJoinColumn = column; - super.update(column); - this.setSpecifiedReferencedColumnName_(specifiedReferencedColumnName(column)); - this.setDefaultReferencedColumnName(defaultReferencedColumnName()); - } - - protected String specifiedReferencedColumnName(XmlPrimaryKeyJoinColumn column) { - return column == null ? null : column.getReferencedColumnName(); - } - - //TODO not correct when we start supporting primaryKeyJoinColumns in 1-1 mappings - protected String defaultReferencedColumnName() { - return defaultName(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java deleted file mode 100644 index 0110bd7884..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmQueryHint.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.QueryHint; -import org.eclipse.jpt.core.context.orm.OrmQuery; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericOrmQueryHint extends AbstractOrmJpaContextNode implements OrmQueryHint -{ - - protected String name; - - protected String value; - - protected XmlQueryHint queryHint; - - public GenericOrmQueryHint(OrmQuery parent) { - super(parent); - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.queryHint.setName(newName); - firePropertyChanged(QueryHint.NAME_PROPERTY, oldName, newName); - } - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.queryHint.setValue(newValue); - firePropertyChanged(QueryHint.VALUE_PROPERTY, oldValue, newValue); - } - - public void initialize(XmlQueryHint queryHint) { - this.queryHint = queryHint; - this.name = queryHint.getName(); - this.value = queryHint.getValue(); - } - - public void update(XmlQueryHint queryHint) { - this.queryHint = queryHint; - this.setName(queryHint.getName()); - this.setValue(queryHint.getValue()); - } - - public TextRange getValidationTextRange() { - return this.queryHint.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java deleted file mode 100644 index 8ccd9ff4e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSecondaryTable.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmBaseJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -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.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -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; - - -public class GenericOrmSecondaryTable extends AbstractOrmTable - implements OrmSecondaryTable -{ - protected XmlSecondaryTable secondaryTable; - - protected final List<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns; - - protected OrmPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn; - - public GenericOrmSecondaryTable(OrmEntity parent, XmlSecondaryTable xmlSecondaryTable) { - super(parent); - this.specifiedPrimaryKeyJoinColumns = new ArrayList<OrmPrimaryKeyJoinColumn>(); - initialize(xmlSecondaryTable); - } - - public void initializeFrom(SecondaryTable oldSecondaryTable) { - super.initializeFrom(oldSecondaryTable); - for (PrimaryKeyJoinColumn oldPkJoinColumn : CollectionTools.iterable(oldSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - OrmPrimaryKeyJoinColumn newPkJoinColumn = addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize()); - newPkJoinColumn.initializeFrom(oldPkJoinColumn); - } - } - - @Override - public OrmEntity getParent() { - return (OrmEntity) super.getParent(); - } - - public OrmEntity getOrmEntity() { - return getParent(); - } - - public OrmPrimaryKeyJoinColumn getDefaultPrimaryKeyJoinColumn() { - return this.defaultPrimaryKeyJoinColumn; - } - - protected void setDefaultPrimaryKeyJoinColumn(OrmPrimaryKeyJoinColumn newPkJoinColumn) { - OrmPrimaryKeyJoinColumn oldPkJoinColumn = this.defaultPrimaryKeyJoinColumn; - this.defaultPrimaryKeyJoinColumn = newPkJoinColumn; - firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldPkJoinColumn, newPkJoinColumn); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumns() : this.defaultPrimaryKeyJoinColumns(); - } - - public int primaryKeyJoinColumnsSize() { - return this.containsSpecifiedPrimaryKeyJoinColumns() ? this.specifiedPrimaryKeyJoinColumnsSize() : this.defaultPrimaryKeyJoinColumnsSize(); - } - - public ListIterator<OrmPrimaryKeyJoinColumn> specifiedPrimaryKeyJoinColumns() { - return new CloneListIterator<OrmPrimaryKeyJoinColumn>(this.specifiedPrimaryKeyJoinColumns); - } - - public int specifiedPrimaryKeyJoinColumnsSize() { - return this.specifiedPrimaryKeyJoinColumns.size(); - } - - protected ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns() { - if (this.defaultPrimaryKeyJoinColumn != null) { - return new SingleElementListIterator<OrmPrimaryKeyJoinColumn>(this.defaultPrimaryKeyJoinColumn); - } - return EmptyListIterator.instance(); - } - - protected int defaultPrimaryKeyJoinColumnsSize() { - return (this.defaultPrimaryKeyJoinColumn == null) ? 0 : 1; - } - - public boolean containsSpecifiedPrimaryKeyJoinColumns() { - return !this.specifiedPrimaryKeyJoinColumns.isEmpty(); - } - - public OrmPrimaryKeyJoinColumn addSpecifiedPrimaryKeyJoinColumn(int index) { - OrmPrimaryKeyJoinColumn oldDefaultPkJoinColumn = this.getDefaultPrimaryKeyJoinColumn(); - if (oldDefaultPkJoinColumn != 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.defaultPrimaryKeyJoinColumn = null; - } - XmlPrimaryKeyJoinColumn xmlPrimaryKeyJoinColumn = OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl(); - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = createPrimaryKeyJoinColumn(xmlPrimaryKeyJoinColumn); - this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - this.secondaryTable.getPrimaryKeyJoinColumns().add(index, xmlPrimaryKeyJoinColumn); - - this.fireItemAdded(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); - if (oldDefaultPkJoinColumn != null) { - this.firePropertyChanged(SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, oldDefaultPkJoinColumn, null); - } - return primaryKeyJoinColumn; - } - - protected OrmBaseJoinColumn.Owner createPrimaryKeyJoinColumnOwner() { - return new PrimaryKeyJoinColumnOwner(); - } - - protected void addSpecifiedPrimaryKeyJoinColumn(int index, OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - addItemToList(index, primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void removeSpecifiedPrimaryKeyJoinColumn(PrimaryKeyJoinColumn pkJoinColumn) { - this.removeSpecifiedPrimaryKeyJoinColumn(this.specifiedPrimaryKeyJoinColumns.indexOf(pkJoinColumn)); - } - - 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. - this.defaultPrimaryKeyJoinColumn = createPrimaryKeyJoinColumn(null); - } - this.secondaryTable.getPrimaryKeyJoinColumns().remove(index); - fireItemRemoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); - if (this.defaultPrimaryKeyJoinColumn != null) { - //fire change notification if a defaultJoinColumn was created above - this.firePropertyChanged(Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN, null, this.defaultPrimaryKeyJoinColumn); - } - } - - protected void removeSpecifiedPrimaryKeyJoinColumn_(OrmPrimaryKeyJoinColumn primaryKeyJoinColumn) { - removeItemFromList(primaryKeyJoinColumn, this.specifiedPrimaryKeyJoinColumns, SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); - } - - public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - CollectionTools.move(this.specifiedPrimaryKeyJoinColumns, targetIndex, sourceIndex); - this.secondaryTable.getPrimaryKeyJoinColumns().move(targetIndex, sourceIndex); - fireItemMoved(SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, targetIndex, sourceIndex); - } - - - public boolean isVirtual() { - return getOrmEntity().containsVirtualSecondaryTable(this); - } - - @Override - protected void addTableResource() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - } - - @Override - protected void removeTableResource() { - //secondaryTables are part of a collection, the secondary-table element will be removed/added - //when the XmlSecondaryTable is removed/added to the XmlEntity collection - } - - @Override - protected XmlSecondaryTable getTableResource() { - return this.secondaryTable; - } - - protected void initialize(XmlSecondaryTable secondaryTable) { - this.secondaryTable = secondaryTable; - super.initialize(secondaryTable); - this.initializeSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.initializeDefaultPrimaryKeyJoinColumn(); - } - - protected void initializeSpecifiedPrimaryKeyJoinColumns(XmlSecondaryTable secondaryTable) { - for (XmlPrimaryKeyJoinColumn primaryKeyJoinColumn : secondaryTable.getPrimaryKeyJoinColumns()) { - this.specifiedPrimaryKeyJoinColumns.add(createPrimaryKeyJoinColumn(primaryKeyJoinColumn)); - } - } - - protected boolean shouldBuildDefaultPrimaryKeyJoinColumn() { - return !containsSpecifiedPrimaryKeyJoinColumns(); - } - - protected void initializeDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - return; - } - this.defaultPrimaryKeyJoinColumn = createPrimaryKeyJoinColumn(null); - } - - public void update(XmlSecondaryTable secondaryTable) { - this.secondaryTable = secondaryTable; - super.update(secondaryTable); - this.updateSpecifiedPrimaryKeyJoinColumns(secondaryTable); - this.updateDefaultPrimaryKeyJoinColumn(); - } - - protected void updateSpecifiedPrimaryKeyJoinColumns(XmlSecondaryTable secondaryTable) { - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<XmlPrimaryKeyJoinColumn> resourcePrimaryKeyJoinColumns = new CloneListIterator<XmlPrimaryKeyJoinColumn>(secondaryTable.getPrimaryKeyJoinColumns());//prevent ConcurrentModificiationException - - while (primaryKeyJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); - if (resourcePrimaryKeyJoinColumns.hasNext()) { - primaryKeyJoinColumn.update(resourcePrimaryKeyJoinColumns.next()); - } - else { - removeSpecifiedPrimaryKeyJoinColumn_(primaryKeyJoinColumn); - } - } - - while (resourcePrimaryKeyJoinColumns.hasNext()) { - addSpecifiedPrimaryKeyJoinColumn(specifiedPrimaryKeyJoinColumnsSize(), createPrimaryKeyJoinColumn(resourcePrimaryKeyJoinColumns.next())); - } - } - - protected void updateDefaultPrimaryKeyJoinColumn() { - if (!shouldBuildDefaultPrimaryKeyJoinColumn()) { - setDefaultPrimaryKeyJoinColumn(null); - return; - } - if (getDefaultPrimaryKeyJoinColumn() == null) { - this.setDefaultPrimaryKeyJoinColumn(createPrimaryKeyJoinColumn(null)); - } - else { - this.defaultPrimaryKeyJoinColumn.update(null); - } - } - - protected OrmPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(XmlPrimaryKeyJoinColumn xmlPrimaryKeyJoinColumn) { - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = getJpaFactory().buildOrmPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); - ormPrimaryKeyJoinColumn.initialize(xmlPrimaryKeyJoinColumn); - return ormPrimaryKeyJoinColumn; - } - - @Override - //no default name for secondaryTables - protected String defaultName() { - return null; - } - - @Override - protected String defaultCatalog() { - return getEntityMappings().getCatalog(); - } - - @Override - protected String defaultSchema() { - return getEntityMappings().getSchema(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addTableMessages(messages); - - for (OrmPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.primaryKeyJoinColumns())) { - pkJoinColumn.addToMessages(messages); - } - } - - protected void addTableMessages(List<IMessage> messages) { - boolean doContinue = connectionProfileIsActive(); - String schema = getSchema(); - - if (doContinue && ! hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, getName()}, - this, - getSchemaTextRange()) - ); - doContinue = false; - } - - if (doContinue && ! isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.SECONDARY_TABLE_UNRESOLVED_NAME, - new String[] {getName()}, - this, - getNameTextRange()) - ); - } - } - - class PrimaryKeyJoinColumnOwner implements OrmBaseJoinColumn.Owner - { - - public TypeMapping getTypeMapping() { - return GenericOrmSecondaryTable.this.getOrmEntity(); - } - - public Table getDbTable(String tableName) { - return GenericOrmSecondaryTable.this.getDbTable(); - } - - public Table getDbReferencedColumnTable() { - return getTypeMapping().getPrimaryDbTable(); - } - - public int joinColumnsSize() { - return GenericOrmSecondaryTable.this.primaryKeyJoinColumnsSize(); - } - - public boolean isVirtual(BaseJoinColumn joinColumn) { - return GenericOrmSecondaryTable.this.defaultPrimaryKeyJoinColumn == joinColumn; - } - - public String getDefaultColumnName() { - if (joinColumnsSize() != 1) { - return null; - } - return getOrmEntity().getParentEntity().getPrimaryKeyColumnName(); - } - - public TextRange getValidationTextRange() { - // TODO Auto-generated method stub - return null; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java deleted file mode 100644 index b42cac0d45..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmSequenceGenerator.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; - - -public class GenericOrmSequenceGenerator extends AbstractOrmGenerator<XmlSequenceGenerator> - implements OrmSequenceGenerator -{ - - protected String specifiedSequenceName; - - protected String defaultSequenceName; - - public GenericOrmSequenceGenerator(OrmJpaContextNode parent) { - super(parent); - } - - public String getSequenceName() { - return (this.getSpecifiedSequenceName() == null) ? getDefaultSequenceName() : this.getSpecifiedSequenceName(); - } - - public String getSpecifiedSequenceName() { - return this.specifiedSequenceName; - } - - public void setSpecifiedSequenceName(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - getGeneratorResource().setSequenceName(newSpecifiedSequenceName); - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - protected void setSpecifiedSequenceName_(String newSpecifiedSequenceName) { - String oldSpecifiedSequenceName = this.specifiedSequenceName; - this.specifiedSequenceName = newSpecifiedSequenceName; - firePropertyChanged(SPECIFIED_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newSpecifiedSequenceName); - } - - public String getDefaultSequenceName() { - return this.defaultSequenceName; - } - - protected void setDefaultSequenceName(String newDefaultSequenceName) { - String oldSpecifiedSequenceName = this.defaultSequenceName; - this.defaultSequenceName = newDefaultSequenceName; - firePropertyChanged(DEFAULT_SEQUENCE_NAME_PROPERTY, oldSpecifiedSequenceName, newDefaultSequenceName); - } - - @Override - public void initialize(XmlSequenceGenerator sequenceGenerator) { - super.initialize(sequenceGenerator); - this.specifiedSequenceName = this.specifiedSequenceName(sequenceGenerator); - //TODO default sequence name - } - - @Override - public void update(XmlSequenceGenerator sequenceGenerator) { - super.update(sequenceGenerator); - this.setSpecifiedSequenceName_(this.specifiedSequenceName(sequenceGenerator)); - //TODO default sequence name - } - - protected String specifiedSequenceName(XmlSequenceGenerator generatorResource) { - return generatorResource.getSequenceName(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java deleted file mode 100644 index d0c3730735..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTable.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericOrmTable extends AbstractOrmTable implements OrmTable -{ - - protected XmlEntity entity; - - public GenericOrmTable(OrmEntity parent) { - super(parent); - } - - public OrmEntity getOrmEntity() { - return (OrmEntity) super.getParent(); - } - - @Override - protected XmlTable getTableResource() { - return this.entity.getTable(); - } - - @Override - protected void removeTableResource() { - this.entity.setTable(null); - } - - @Override - protected void addTableResource() { - this.entity.setTable(OrmFactory.eINSTANCE.createXmlTable()); - - } - - protected JavaTable getJavaTable() { - JavaEntity javaEntity = getOrmEntity().getJavaEntity(); - if (javaEntity != null) { - return javaEntity.getTable(); - } - return null; - } - - public void initialize(XmlEntity entity) { - this.entity = entity; - this.initialize(this.getTableResource()); - } - - public void update(XmlEntity entity) { - this.entity = entity; - this.update(this.getTableResource()); - } - - @Override - protected String defaultName() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null) { - if (!getOrmEntity().isMetadataComplete() && getTableResource() == null && javaTable.getSpecifiedName() != null) { - return javaTable.getSpecifiedName(); - } - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getName(); - } - } - return getOrmEntity().getName(); - } - - @Override - protected String defaultSchema() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null ) { - if (getOrmEntity().isMetadataComplete() || (getTableResource() != null)) { - return javaTable.getDefaultSchema(); - } - return javaTable.getSchema(); - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getSchema(); - } - } - return getEntityMappings().getSchema(); - } - - @Override - protected String defaultCatalog() { - JavaTable javaTable = getJavaTable(); - if (javaTable != null) { - if (getOrmEntity().isMetadataComplete() || (getTableResource() != null)) { - return javaTable.getDefaultCatalog(); - } - return javaTable.getCatalog(); - } - Entity rootEntity = getOrmEntity().getRootEntity(); - if (rootEntity != getOrmEntity()) { - if (rootEntity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - return rootEntity.getTable().getCatalog(); - } - } - return getEntityMappings().getCatalog(); - } - - //*********** Validation ******************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - boolean doContinue = connectionProfileIsActive(); - String schema = this.getSchema(); - - if (doContinue && ! this.hasResolvedSchema()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_SCHEMA, - new String[] {schema, this.getName()}, - this, - this.getSchemaTextRange()) - ); - doContinue = false; - } - - if (doContinue && ! this.isResolved()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.TABLE_UNRESOLVED_NAME, - new String[] {this.getName()}, - this, - this.getNameTextRange()) - ); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java deleted file mode 100644 index 57e8df7551..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTableGenerator.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -public class GenericOrmTableGenerator extends AbstractOrmGenerator<XmlTableGenerator> implements OrmTableGenerator, UniqueConstraint.Owner -{ - protected String specifiedTable; - protected String defaultTable; - - protected String specifiedCatalog; - protected String defaultCatalog; - - protected String specifiedSchema; - protected String defaultSchema; - - protected String specifiedPkColumnName; - protected String defaultPkColumnName; - - protected String specifiedValueColumnName; - protected String defaultValueColumnName; - - protected String specifiedPkColumnValue; - protected String defaultPkColumnValue; - - protected final List<OrmUniqueConstraint> uniqueConstraints; - - - public GenericOrmTableGenerator(OrmJpaContextNode parent) { - super(parent); - this.uniqueConstraints = new ArrayList<OrmUniqueConstraint>(); - } - - 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; - getGeneratorResource().setTable(newSpecifiedTable); - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - protected void setSpecifiedTable_(String newSpecifiedTable) { - String oldSpecifiedTable = this.specifiedTable; - this.specifiedTable = newSpecifiedTable; - firePropertyChanged(SPECIFIED_TABLE_PROPERTY, oldSpecifiedTable, newSpecifiedTable); - } - - public String getDefaultTable() { - return this.defaultTable; - } - - protected void setDefaultTable(String newDefaultTable) { - String oldDefaultTable = this.defaultTable; - this.defaultTable = newDefaultTable; - firePropertyChanged(DEFAULT_TABLE_PROPERTY, oldDefaultTable, newDefaultTable); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newSpecifiedCatalog) { - String oldSpecifiedCatalog = this.specifiedCatalog; - this.specifiedCatalog = newSpecifiedCatalog; - getGeneratorResource().setCatalog(newSpecifiedCatalog); - firePropertyChanged(SPECIFIED_CATALOG_PROPERTY, oldSpecifiedCatalog, newSpecifiedCatalog); - } - - 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(TableGenerator.DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - getGeneratorResource().setSchema(newSpecifiedSchema); - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - protected void setSpecifiedSchema_(String newSpecifiedSchema) { - String oldSpecifiedSchema = this.specifiedSchema; - this.specifiedSchema = newSpecifiedSchema; - firePropertyChanged(SPECIFIED_SCHEMA_PROPERTY, oldSpecifiedSchema, newSpecifiedSchema); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(TableGenerator.DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getPkColumnName() { - return (this.getSpecifiedPkColumnName() == null) ? getDefaultPkColumnName() : this.getSpecifiedPkColumnName(); - } - - public String getSpecifiedPkColumnName() { - return this.specifiedPkColumnName; - } - - public void setSpecifiedPkColumnName(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - getGeneratorResource().setPkColumnName(newSpecifiedPkColumnName); - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - protected void setSpecifiedPkColumnName_(String newSpecifiedPkColumnName) { - String oldSpecifiedPkColumnName = this.specifiedPkColumnName; - this.specifiedPkColumnName = newSpecifiedPkColumnName; - firePropertyChanged(SPECIFIED_PK_COLUMN_NAME_PROPERTY, oldSpecifiedPkColumnName, newSpecifiedPkColumnName); - } - - public String getDefaultPkColumnName() { - return this.defaultPkColumnName; - } - - protected void setDefaultPkColumnName(String newDefaultPkColumnName) { - String oldDefaultPkColumnName = this.defaultPkColumnName; - this.defaultPkColumnName = newDefaultPkColumnName; - firePropertyChanged(DEFAULT_PK_COLUMN_NAME_PROPERTY, oldDefaultPkColumnName, newDefaultPkColumnName); - } - - public String getValueColumnName() { - return (this.getSpecifiedValueColumnName() == null) ? getDefaultValueColumnName() : this.getSpecifiedValueColumnName(); - } - - public String getSpecifiedValueColumnName() { - return this.specifiedValueColumnName; - } - - public void setSpecifiedValueColumnName(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - getGeneratorResource().setValueColumnName(newSpecifiedValueColumnName); - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - protected void setSpecifiedValueColumnName_(String newSpecifiedValueColumnName) { - String oldSpecifiedValueColumnName = this.specifiedValueColumnName; - this.specifiedValueColumnName = newSpecifiedValueColumnName; - firePropertyChanged(SPECIFIED_VALUE_COLUMN_NAME_PROPERTY, oldSpecifiedValueColumnName, newSpecifiedValueColumnName); - } - - public String getDefaultValueColumnName() { - return this.defaultValueColumnName; - } - - protected void setDefaultValueColumnName(String newDefaultValueColumnName) { - String oldDefaultValueColumnName = this.defaultValueColumnName; - this.defaultValueColumnName = newDefaultValueColumnName; - firePropertyChanged(DEFAULT_VALUE_COLUMN_NAME_PROPERTY, oldDefaultValueColumnName, newDefaultValueColumnName); - } - - public String getPkColumnValue() { - return (this.getSpecifiedPkColumnValue() == null) ? getDefaultPkColumnValue() : this.getSpecifiedPkColumnValue(); - } - - public String getSpecifiedPkColumnValue() { - return this.specifiedPkColumnValue; - } - - public void setSpecifiedPkColumnValue(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - getGeneratorResource().setPkColumnValue(newSpecifiedPkColumnValue); - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - protected void setSpecifiedPkColumnValue_(String newSpecifiedPkColumnValue) { - String oldSpecifiedPkColumnValue = this.specifiedPkColumnValue; - this.specifiedPkColumnValue = newSpecifiedPkColumnValue; - firePropertyChanged(SPECIFIED_PK_COLUMN_VALUE_PROPERTY, oldSpecifiedPkColumnValue, newSpecifiedPkColumnValue); - } - - public String getDefaultPkColumnValue() { - return this.defaultPkColumnValue; - } - - public void setDefaultPkColumnValue(String newDefaultPkColumnValue) { - String oldDefaultPkColumnValue = this.defaultPkColumnValue; - this.defaultPkColumnValue = newDefaultPkColumnValue; - firePropertyChanged(DEFAULT_PK_COLUMN_VALUE_PROPERTY, oldDefaultPkColumnValue, newDefaultPkColumnValue); - } - - - // ********** unique constraints ********** - - public ListIterator<OrmUniqueConstraint> uniqueConstraints() { - return new CloneListIterator<OrmUniqueConstraint>(this.uniqueConstraints); - } - - public int uniqueConstraintsSize() { - return this.uniqueConstraints.size(); - } - - public OrmUniqueConstraint addUniqueConstraint(int index) { - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - OrmUniqueConstraint uniqueConstraint = buildUniqueConstraint(uniqueConstraintResource); - this.uniqueConstraints.add(index, uniqueConstraint); - getGeneratorResource().getUniqueConstraints().add(index, uniqueConstraintResource); - fireItemAdded(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, uniqueConstraint); - return uniqueConstraint; - } - - protected void addUniqueConstraint(int index, OrmUniqueConstraint uniqueConstraint) { - addItemToList(index, uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - - public void removeUniqueConstraint(UniqueConstraint uniqueConstraint) { - this.removeUniqueConstraint(this.uniqueConstraints.indexOf(uniqueConstraint)); - } - - public void removeUniqueConstraint(int index) { - OrmUniqueConstraint removedUniqueConstraint = this.uniqueConstraints.remove(index); - getGeneratorResource().getUniqueConstraints().remove(index); - fireItemRemoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, index, removedUniqueConstraint); - } - - protected void removeUniqueConstraint_(OrmUniqueConstraint uniqueConstraint) { - removeItemFromList(uniqueConstraint, this.uniqueConstraints, TableGenerator.UNIQUE_CONSTRAINTS_LIST); - } - - public void moveUniqueConstraint(int targetIndex, int sourceIndex) { - CollectionTools.move(this.uniqueConstraints, targetIndex, sourceIndex); - this.getGeneratorResource().getUniqueConstraints().move(targetIndex, sourceIndex); - fireItemMoved(TableGenerator.UNIQUE_CONSTRAINTS_LIST, targetIndex, sourceIndex); - } - - //******************* UniqueConstraint.Owner implementation ****************** - - public Iterator<String> candidateUniqueConstraintColumnNames() { - org.eclipse.jpt.db.Table dbTable = getDbTable(); - if (dbTable != null) { - return dbTable.columnNames(); - } - return EmptyIterator.instance(); - } - - public Table getDbTable() { - Schema schema = this.getDbSchema(); - return (schema == null) ? null : schema.tableNamed(this.getTable()); - } - - public Schema getDbSchema() { - return this.getDatabase().schemaNamed(this.getSchema()); - } - - // ********** orm resource model -> context model ********** - - @Override - public void initialize(XmlTableGenerator tableGenerator) { - super.initialize(tableGenerator); - this.specifiedTable = this.specifiedTable(tableGenerator); - this.specifiedCatalog = this.specifiedCatalog(tableGenerator); - this.defaultCatalog = this.defaultCatalog(); - this.specifiedSchema = this.specifiedSchema(tableGenerator); - this.defaultSchema = this.defaultSchema(); - this.specifiedPkColumnName = this.specifiedPkColumnName(tableGenerator); - this.specifiedValueColumnName = this.specifiedValueColumnName(tableGenerator); - this.specifiedPkColumnValue = this.specifiedPkColumnValue(tableGenerator); - this.initializeUniqueContraints(tableGenerator); - } - - protected void initializeUniqueContraints(XmlTableGenerator tableGenerator) { - if (tableGenerator == null) { - return; - } - for (XmlUniqueConstraint uniqueConstraint : tableGenerator.getUniqueConstraints()) { - this.uniqueConstraints.add(buildUniqueConstraint(uniqueConstraint)); - } - } - - @Override - public void update(XmlTableGenerator tableGenerator) { - super.update(tableGenerator); - this.setSpecifiedTable_(this.specifiedTable(tableGenerator)); - this.setSpecifiedCatalog_(this.specifiedCatalog(tableGenerator)); - this.setDefaultCatalog(this.defaultCatalog()); - this.setSpecifiedSchema_(this.specifiedSchema(tableGenerator)); - this.setDefaultSchema(this.defaultSchema()); - this.setSpecifiedPkColumnName_(this.specifiedPkColumnName(tableGenerator)); - this.setSpecifiedValueColumnName_(this.specifiedValueColumnName(tableGenerator)); - this.setSpecifiedPkColumnValue_(this.specifiedPkColumnValue(tableGenerator)); - //TODO defaults - this.updateUniqueConstraints(tableGenerator); - } - - protected String specifiedTable(XmlTableGenerator tableGenerator) { - return tableGenerator.getTable(); - } - - protected String specifiedCatalog(XmlTableGenerator tableGenerator) { - return tableGenerator.getCatalog(); - } - - protected String specifiedSchema(XmlTableGenerator tableGenerator) { - return tableGenerator.getSchema(); - } - - protected String specifiedPkColumnName(XmlTableGenerator tableGenerator) { - return tableGenerator.getPkColumnName(); - } - - protected String specifiedValueColumnName(XmlTableGenerator tableGenerator) { - return tableGenerator.getValueColumnName(); - } - - protected String specifiedPkColumnValue(XmlTableGenerator tableGenerator) { - return tableGenerator.getPkColumnValue(); - } - - protected String defaultSchema() { - return getEntityMappings().getSchema(); - } - - protected String defaultCatalog() { - return getEntityMappings().getCatalog(); - } - - protected void updateUniqueConstraints(XmlTableGenerator tableGenerator) { - ListIterator<OrmUniqueConstraint> uniqueConstraints = uniqueConstraints(); - ListIterator<XmlUniqueConstraint> resourceUniqueConstraints; - if (tableGenerator == null) { - resourceUniqueConstraints = EmptyListIterator.instance(); - } - else { - resourceUniqueConstraints = new CloneListIterator<XmlUniqueConstraint>(tableGenerator.getUniqueConstraints());//prevent ConcurrentModificiationException - } - - while (uniqueConstraints.hasNext()) { - OrmUniqueConstraint uniqueConstraint = uniqueConstraints.next(); - if (resourceUniqueConstraints.hasNext()) { - uniqueConstraint.update(resourceUniqueConstraints.next()); - } - else { - removeUniqueConstraint_(uniqueConstraint); - } - } - - while (resourceUniqueConstraints.hasNext()) { - addUniqueConstraint(uniqueConstraintsSize(), buildUniqueConstraint(resourceUniqueConstraints.next())); - } - } - - protected OrmUniqueConstraint buildUniqueConstraint(XmlUniqueConstraint xmlUniqueConstraint) { - return getJpaFactory().buildOrmUniqueConstraint(this, this, xmlUniqueConstraint); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java deleted file mode 100644 index 15aa020230..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmTransientMapping.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTransient; - - -public class GenericOrmTransientMapping extends AbstractOrmAttributeMapping<XmlTransient> implements OrmTransientMapping -{ - - public GenericOrmTransientMapping(OrmPersistentAttribute parent) { - super(parent); - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmTransientMapping(this); - } - - public int getXmlSequence() { - return 9; - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public XmlTransient addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlTransient transientResource = OrmFactory.eINSTANCE.createXmlTransientImpl(); - getPersistentAttribute().initialize(transientResource); - typeMapping.getAttributes().getTransients().add(transientResource); - return transientResource; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getTransients().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - @Override - public void initialize(XmlTransient transientResource) { - super.initialize(transientResource); - } - - @Override - public void update(XmlTransient transientResource) { - super.update(transientResource); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java deleted file mode 100644 index beeda806a7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public class GenericOrmUniqueConstraint extends AbstractOrmJpaContextNode - implements OrmUniqueConstraint -{ - - protected final List<String> columnNames; - - protected XmlUniqueConstraint uniqueConstraint; - - protected UniqueConstraint.Owner owner; - - public GenericOrmUniqueConstraint(OrmJpaContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint uniqueConstraint) { - super(parent); - this.owner = owner; - this.columnNames = new ArrayList<String>(); - this.initialize(uniqueConstraint); - } - - public ListIterator<String> columnNames() { - return new CloneListIterator<String>(this.columnNames); - } - - public int columnNamesSize() { - return this.columnNames.size(); - } - - public void addColumnName(int index, String columnName) { - this.columnNames.add(index, columnName); - this.uniqueConstraint.getColumnNames().add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - protected void addColumnName_(int index, String columnName) { - this.columnNames.add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); - } - - public void removeColumnName(String columnName) { - this.removeColumnName(this.columnNames.indexOf(columnName)); - } - - public void removeColumnName(int index) { - String removedColumnName = this.columnNames.remove(index); - this.uniqueConstraint.getColumnNames().remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - protected void removeColumnName_(int index) { - String removedColumnName = this.columnNames.remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); - } - - public void moveColumnName(int targetIndex, int sourceIndex) { - CollectionTools.move(this.columnNames, targetIndex, sourceIndex); - this.uniqueConstraint.getColumnNames().move(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); - } - - public TextRange getValidationTextRange() { - return this.uniqueConstraint.getValidationTextRange(); - } - - protected void initialize(XmlUniqueConstraint uniqueConstraint) { - this.uniqueConstraint = uniqueConstraint; - this.initializeColumnNames(uniqueConstraint); - } - - protected void initializeColumnNames(XmlUniqueConstraint uniqueConstraint) { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(uniqueConstraint.getColumnNames()); - - for (String annotationColumnName : CollectionTools.iterable(xmlColumnNames)) { - this.columnNames.add(annotationColumnName); - } - } - - public void update(XmlUniqueConstraint uniqueConstraint) { - this.uniqueConstraint = uniqueConstraint; - this.updateColumnNames(uniqueConstraint); - } - - protected void updateColumnNames(XmlUniqueConstraint uniqueConstraint) { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(uniqueConstraint.getColumnNames()); - - int index = 0; - for (String xmlColumnName : CollectionTools.iterable(xmlColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != xmlColumnName) { - addColumnName_(index, xmlColumnName); - } - } - else { - addColumnName_(index, xmlColumnName); - } - index++; - } - - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java deleted file mode 100644 index 488342b8f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.ColumnMapping; -import org.eclipse.jpt.core.context.TemporalType; -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.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -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.db.Table; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - - -public class GenericOrmVersionMapping extends AbstractOrmAttributeMapping<XmlVersion> - implements OrmVersionMapping -{ - protected final OrmColumn column; - - protected TemporalType temporal; - - public GenericOrmVersionMapping(OrmPersistentAttribute parent) { - super(parent); - this.column = getJpaFactory().buildOrmColumn(this, this); - } - - public int getXmlSequence() { - return 3; - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public void initializeOn(OrmAttributeMapping newMapping) { - newMapping.initializeFromOrmVersionMapping(this); - } - - @Override - public void initializeFromXmlColumnMapping(OrmColumnMapping oldMapping) { - super.initializeFromXmlColumnMapping(oldMapping); - setTemporal(oldMapping.getTemporal()); - getColumn().initializeFrom(oldMapping.getColumn()); - } - - public OrmColumn getColumn() { - return this.column; - } - - public TemporalType getTemporal() { - return this.temporal; - } - - public void setTemporal(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - this.getAttributeMapping().setTemporal(TemporalType.toOrmResourceModel(newTemporal)); - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - protected void setTemporal_(TemporalType newTemporal) { - TemporalType oldTemporal = this.temporal; - this.temporal = newTemporal; - firePropertyChanged(ColumnMapping.TEMPORAL_PROPERTY, oldTemporal, newTemporal); - } - - public XmlVersion addToResourceModel(AbstractXmlTypeMapping typeMapping) { - XmlVersion version = OrmFactory.eINSTANCE.createXmlVersionImpl(); - getPersistentAttribute().initialize(version); - typeMapping.getAttributes().getVersions().add(version); - return version; - } - - public void removeFromResourceModel(AbstractXmlTypeMapping typeMapping) { - typeMapping.getAttributes().getVersions().remove(this.getAttributeMapping()); - if (typeMapping.getAttributes().isAllFeaturesUnset()) { - typeMapping.setAttributes(null); - } - } - - public String getDefaultColumnName() { - return getAttributeName(); - } - - public String getDefaultTableName() { - return getTypeMapping().getTableName(); - } - - public Table getDbTable(String tableName) { - return getTypeMapping().getDbTable(tableName); - } - - @Override - public void initialize(XmlVersion version) { - super.initialize(version); - this.temporal = this.specifiedTemporal(version); - this.column.initialize(version.getColumn()); - } - - @Override - public void update(XmlVersion version) { - super.update(version); - this.setTemporal_(this.specifiedTemporal(version)); - this.column.update(version.getColumn()); - } - - protected TemporalType specifiedTemporal(XmlVersion version) { - return TemporalType.fromOrmResourceModel(version.getTemporal()); - } - - //***************** IXmlColumn.Owner implementation **************** - - public XmlColumn getColumnResource() { - return this.getAttributeMapping().getColumn(); - } - - public void addColumnResource() { - this.getAttributeMapping().setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - } - - public void removeColumnResource() { - this.getAttributeMapping().setColumn(null); - } - - // ****************** validation **************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - - if (entityOwned()) { - addColumnMessages(messages); - } - } - - protected void addColumnMessages(List<IMessage> messages) { - OrmColumn column = getColumn(); - String table = column.getTable(); - boolean doContinue = entityOwned() && this.connectionProfileIsActive(); - - if (doContinue && getTypeMapping().tableNameIsInvalid(table)) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_TABLE, - new String[] {getPersistentAttribute().getName(), table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_TABLE, - new String[] {table, column.getName()}, - column, - column.getTableTextRange()) - ); - } - doContinue = false; - } - - if (doContinue && ! column.isResolved()) { - if (getPersistentAttribute().isVirtual()) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_UNRESOLVED_NAME, - new String[] {getPersistentAttribute().getName(), column.getName()}, - column, - column.getNameTextRange()) - ); - } - else { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.COLUMN_UNRESOLVED_NAME, - new String[] {column.getName()}, - column, - column.getNameTextRange()) - ); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java deleted file mode 100644 index 847e081d33..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitDefaults.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.AccessType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; - -public class GenericPersistenceUnitDefaults extends AbstractOrmJpaContextNode - implements PersistenceUnitDefaults -{ - protected String specifiedSchema; - - protected String defaultSchema; - - protected String specifiedCatalog; - - protected String defaultCatalog; - - protected AccessType access; - - protected boolean cascadePersist; - - protected XmlEntityMappings entityMappings; - - public GenericPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.initialize(xmlEntityMappings); - } - - public AccessType getAccess() { - return this.access; - } - - public void setAccess(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - if (oldAccess != newAccess) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setAccess(AccessType.toXmlResourceModel(newAccess)); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setAccess(AccessType.toXmlResourceModel(newAccess)); - } - } - firePropertyChanged(PersistenceUnitDefaults.ACCESS_PROPERTY, oldAccess, newAccess); - } - - protected void setAccess_(AccessType newAccess) { - AccessType oldAccess = this.access; - this.access = newAccess; - firePropertyChanged(PersistenceUnitDefaults.ACCESS_PROPERTY, oldAccess, newAccess); - } - - public String getCatalog() { - return (this.getSpecifiedCatalog() == null) ? this.getDefaultCatalog() : this.getSpecifiedCatalog(); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public String getSpecifiedCatalog() { - return this.specifiedCatalog; - } - - public void setSpecifiedCatalog(String newCatalog) { - String oldCatalog = this.specifiedCatalog; - this.specifiedCatalog = newCatalog; - if (oldCatalog != newCatalog) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setCatalog(newCatalog); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setCatalog(newCatalog); - } - } - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - protected void setSpecifiedCatalog_(String newCatalog) { - String oldCatalog = this.specifiedCatalog; - this.specifiedCatalog = newCatalog; - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_CATALOG_PROPERTY, oldCatalog, newCatalog); - } - - - public String getSchema() { - return (this.getSpecifiedSchema() == null) ? this.getDefaultSchema() : this.getSpecifiedSchema(); - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getSpecifiedSchema() { - return this.specifiedSchema; - } - - public void setSpecifiedSchema(String newSchema) { - String oldSchema = this.specifiedSchema; - this.specifiedSchema = newSchema; - if (oldSchema != newSchema) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setSchema(newSchema); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setSchema(newSchema); - } - } - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_SCHEMA_PROPERTY, oldSchema, newSchema); - } - - protected void setSpecifiedSchema_(String newSchema) { - String oldSchema = this.specifiedSchema; - this.specifiedSchema = newSchema; - firePropertyChanged(PersistenceUnitDefaults.SPECIFIED_SCHEMA_PROPERTY, oldSchema, newSchema); - } - - public boolean isCascadePersist() { - return this.cascadePersist; - } - - public void setCascadePersist(boolean newCascadePersist) { - boolean oldCascadePersist = this.cascadePersist; - this.cascadePersist = newCascadePersist; - if (oldCascadePersist != newCascadePersist) { - if (this.persistenceUnitDefaults() != null) { - this.persistenceUnitDefaults().setCascadePersist(newCascadePersist); - if (this.persistenceUnitDefaults().isAllFeaturesUnset()) { - this.persistenceUnitMetadata().setPersistenceUnitDefaults(null); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - } - else if (newCascadePersist) { - if (persistenceUnitMetadata() == null) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - } - persistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitDefaults().setCascadePersist(newCascadePersist); - } - } - firePropertyChanged(PersistenceUnitDefaults.CASCADE_PERSIST_PROPERTY, oldCascadePersist, newCascadePersist); - } - - protected void setCascadePersist_(boolean newCascadePersist) { - boolean oldCascadePersist = this.cascadePersist; - this.cascadePersist = newCascadePersist; - firePropertyChanged(PersistenceUnitDefaults.CASCADE_PERSIST_PROPERTY, oldCascadePersist, newCascadePersist); - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitDefaults() != null) { - this.access = AccessType.fromXmlResourceModel(this.persistenceUnitDefaults().getAccess()); - this.cascadePersist = this.persistenceUnitDefaults().isCascadePersist(); - this.specifiedCatalog = this.persistenceUnitDefaults().getCatalog(); - this.specifiedSchema = this.persistenceUnitDefaults().getSchema(); - } - } - - - public void update(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitDefaults() != null) { - this.setAccess_(AccessType.fromXmlResourceModel(this.persistenceUnitDefaults().getAccess())); - this.setCascadePersist_(this.persistenceUnitDefaults().isCascadePersist()); - this.setSpecifiedCatalog_(this.persistenceUnitDefaults().getCatalog()); - this.setSpecifiedSchema_(this.persistenceUnitDefaults().getSchema()); - } - else { - this.setAccess_(null); - this.setCascadePersist_(false); - this.setSpecifiedCatalog_(null); - this.setSpecifiedSchema_(null); - } - this.setDefaultSchema(this.projectDefaultSchemaName()); - this.setDefaultCatalog(this.projectDefaultCatalogName()); - } - - protected String projectDefaultSchemaName() { - Schema projectDefaultSchema = getJpaProject().getDefaultSchema(); - return projectDefaultSchema == null ? null : projectDefaultSchema.getName(); - } - - protected String projectDefaultCatalogName() { - Catalog catalog = getJpaProject().getConnectionProfile().getDefaultCatalog(); - return (catalog == null) ? null : catalog.getName(); - } - - protected XmlPersistenceUnitDefaults persistenceUnitDefaults() { - if (persistenceUnitMetadata() != null) { - return persistenceUnitMetadata().getPersistenceUnitDefaults(); - } - return null; - } - - protected XmlPersistenceUnitMetadata persistenceUnitMetadata() { - return this.entityMappings.getPersistenceUnitMetadata(); - } - - public TextRange getValidationTextRange() { - if (persistenceUnitDefaults() != null) { - return persistenceUnitDefaults().getValidationTextRange(); - } - return this.entityMappings.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java deleted file mode 100644 index c970efe73a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericPersistenceUnitMetadata.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.EntityMappings; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -import org.eclipse.jpt.core.utility.TextRange; - -public class GenericPersistenceUnitMetadata extends AbstractOrmJpaContextNode - implements PersistenceUnitMetadata -{ - protected boolean xmlMappingMetadataComplete; - - protected final PersistenceUnitDefaults persistenceUnitDefaults; - - protected XmlEntityMappings entityMappings; - - public GenericPersistenceUnitMetadata(EntityMappings parent, XmlEntityMappings xmlEntityMappings) { - super(parent); - this.persistenceUnitDefaults = getJpaFactory().buildPersistenceUnitDefaults(this, xmlEntityMappings); - this.initialize(xmlEntityMappings); - } - - public boolean isXmlMappingMetadataComplete() { - return this.xmlMappingMetadataComplete; - } - - public void setXmlMappingMetadataComplete(boolean newXmlMappingMetadataComplete) { - boolean oldXmlMappingMetadataComplete = this.xmlMappingMetadataComplete; - this.xmlMappingMetadataComplete = newXmlMappingMetadataComplete; - if (oldXmlMappingMetadataComplete != newXmlMappingMetadataComplete) { - if (this.persistenceUnitMetadata() != null) { - this.persistenceUnitMetadata().setXmlMappingMetadataComplete(newXmlMappingMetadataComplete); - if (this.persistenceUnitMetadata().isAllFeaturesUnset()) { - this.entityMappings.setPersistenceUnitMetadata(null); - } - } - else if (newXmlMappingMetadataComplete) { - this.entityMappings.setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - this.persistenceUnitMetadata().setXmlMappingMetadataComplete(newXmlMappingMetadataComplete); - } - } - firePropertyChanged(PersistenceUnitMetadata.XML_MAPPING_METADATA_COMPLETE_PROPERTY, oldXmlMappingMetadataComplete, newXmlMappingMetadataComplete); - } - - protected void setXmlMappingMetadataComplete_(boolean newXmlMappingMetadataComplete) { - boolean oldXmlMappingMetadataComplete = this.xmlMappingMetadataComplete; - this.xmlMappingMetadataComplete = newXmlMappingMetadataComplete; - firePropertyChanged(PersistenceUnitMetadata.XML_MAPPING_METADATA_COMPLETE_PROPERTY, oldXmlMappingMetadataComplete, newXmlMappingMetadataComplete); - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - return this.persistenceUnitDefaults; - } - - protected void initialize(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitMetadata() != null) { - this.xmlMappingMetadataComplete = this.persistenceUnitMetadata().isXmlMappingMetadataComplete(); - } - } - - public void update(XmlEntityMappings entityMappings) { - this.entityMappings = entityMappings; - if (this.persistenceUnitMetadata() != null) { - setXmlMappingMetadataComplete_(this.persistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - else { - setXmlMappingMetadataComplete_(false); - } - this.persistenceUnitDefaults.update(entityMappings); - } - - protected XmlPersistenceUnitMetadata persistenceUnitMetadata() { - return this.entityMappings.getPersistenceUnitMetadata(); - } - - public TextRange getValidationTextRange() { - if (persistenceUnitMetadata() != null) { - return persistenceUnitMetadata().getValidationTextRange(); - } - return this.entityMappings.getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java deleted file mode 100644 index e5dd187a11..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmBasicMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmBasicMappingProvider INSTANCE = new OrmBasicMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmBasicMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public OrmBasicMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmBasicMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java deleted file mode 100644 index 22a3f1e316..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmCascade.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.context.orm.OrmJpaContextNode; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.resource.orm.CascadeType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; -import org.eclipse.jpt.core.utility.TextRange; - - -public class OrmCascade extends AbstractOrmJpaContextNode implements Cascade, OrmJpaContextNode -{ - - protected boolean all; - - protected boolean persist; - - protected boolean merge; - - protected boolean remove; - - protected boolean refresh; - - - protected XmlRelationshipMapping relationshipMapping; - - protected OrmCascade(OrmRelationshipMapping parent) { - super(parent); - } - - public void initializeFrom(Cascade oldCascade) { - setAll(oldCascade.isAll()); - setPersist(oldCascade.isPersist()); - setMerge(oldCascade.isMerge()); - setRemove(oldCascade.isRemove()); - setRefresh(oldCascade.isRefresh()); - } - - public boolean isAll() { - return this.all; - } - - public void setAll(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - if (oldAll != newAll) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeAll(newAll); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newAll != false) { - addCascadeResource(); - getCascadeResource().setCascadeAll(newAll); - } - } - firePropertyChanged(ALL_PROPERTY, oldAll, newAll); - } - - protected void setAll_(boolean newAll) { - boolean oldAll = this.all; - this.all = newAll; - firePropertyChanged(ALL_PROPERTY, oldAll, newAll); - } - - public boolean isPersist() { - return this.persist; - } - - public void setPersist(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - if (oldPersist != newPersist) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadePersist(newPersist); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newPersist != false) { - addCascadeResource(); - getCascadeResource().setCascadePersist(newPersist); - } - } - firePropertyChanged(PERSIST_PROPERTY, oldPersist, newPersist); - } - - protected void setPersist_(boolean newPersist) { - boolean oldPersist = this.persist; - this.persist = newPersist; - firePropertyChanged(PERSIST_PROPERTY, oldPersist, newPersist); - } - - - public boolean isMerge() { - return this.merge; - } - - public void setMerge(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - if (oldMerge != newMerge) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeMerge(newMerge); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newMerge != false) { - addCascadeResource(); - getCascadeResource().setCascadeMerge(newMerge); - } - } - firePropertyChanged(MERGE_PROPERTY, oldMerge, newMerge); - } - - protected void setMerge_(boolean newMerge) { - boolean oldMerge = this.merge; - this.merge = newMerge; - firePropertyChanged(MERGE_PROPERTY, oldMerge, newMerge); - } - - public boolean isRemove() { - return this.remove; - } - - public void setRemove(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - if (oldRemove != newRemove) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeRemove(newRemove); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newRemove != false) { - addCascadeResource(); - getCascadeResource().setCascadeRemove(newRemove); - } - } - firePropertyChanged(REMOVE_PROPERTY, oldRemove, newRemove); - } - - protected void setRemove_(boolean newRemove) { - boolean oldRemove = this.remove; - this.remove = newRemove; - firePropertyChanged(REMOVE_PROPERTY, oldRemove, newRemove); - } - - public boolean isRefresh() { - return this.refresh; - } - - public void setRefresh(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - if (oldRefresh != newRefresh) { - if (this.getCascadeResource() != null) { - this.getCascadeResource().setCascadeRefresh(newRefresh); - if (this.getCascadeResource().isAllFeaturesUnset()) { - removeCascadeResource(); - } - } - else if (newRefresh != false) { - addCascadeResource(); - getCascadeResource().setCascadeRefresh(newRefresh); - } - } - firePropertyChanged(REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - protected void setRefresh_(boolean newRefresh) { - boolean oldRefresh = this.refresh; - this.refresh = newRefresh; - firePropertyChanged(REFRESH_PROPERTY, oldRefresh, newRefresh); - } - - - protected CascadeType getCascadeResource() { - return this.relationshipMapping.getCascade(); - } - - protected void removeCascadeResource() { - this.relationshipMapping.setCascade(null); - } - - protected void addCascadeResource() { - this.relationshipMapping.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - } - - public void initialize(XmlRelationshipMapping relationshipMapping) { - this.relationshipMapping = relationshipMapping; - CascadeType cascade = getCascadeResource(); - this.all = this.all(cascade); - this.persist = this.persist(cascade); - this.merge = this.merge(cascade); - this.remove = this.remove(cascade); - this.refresh = this.refresh(cascade); - } - - public void update(XmlRelationshipMapping relationshipMapping) { - this.relationshipMapping = relationshipMapping; - CascadeType cascade = getCascadeResource(); - this.setAll_(this.all(cascade)); - this.setPersist_(this.persist(cascade)); - this.setMerge_(this.merge(cascade)); - this.setRemove_(this.remove(cascade)); - this.setRefresh_(this.refresh(cascade)); - } - - protected boolean all(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeAll(); - } - - protected boolean persist(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadePersist(); - } - - protected boolean merge(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeMerge(); - } - - protected boolean remove(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRemove(); - } - - protected boolean refresh(CascadeType cascade) { - return cascade == null ? false : cascade.isCascadeRefresh(); - } - - public TextRange getValidationTextRange() { - return this.getCascadeResource().getValidationTextRange(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java deleted file mode 100644 index 9dc3cae9cb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -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.OrmTypeMappingProvider; - - -public class OrmEmbeddableProvider implements OrmTypeMappingProvider -{ - - public OrmEmbeddable buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmEmbeddable(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java deleted file mode 100644 index 2a3162affd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmEmbeddedIdMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmEmbeddedIdMappingProvider INSTANCE = new OrmEmbeddedIdMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmEmbeddedIdMappingProvider() { - super(); - } - - public OrmEmbeddedIdMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmEmbeddedIdMapping(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java deleted file mode 100644 index dcf069189a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmEmbeddedMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmEmbeddedMappingProvider INSTANCE = new OrmEmbeddedMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmEmbeddedMappingProvider() { - super(); - } - - public OrmEmbeddedMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmEmbeddedMapping(parent); - } - - public String getKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java deleted file mode 100644 index 10c69c5333..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -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.OrmTypeMappingProvider; - - -public class OrmEntityProvider implements OrmTypeMappingProvider -{ - public OrmEntity buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmEntity(parent); - } - - public String getKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java deleted file mode 100644 index 302c800245..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmIdMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmIdMappingProvider INSTANCE = new OrmIdMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmIdMappingProvider() { - super(); - } - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public OrmIdMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmIdMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java deleted file mode 100644 index 5dbfd0c6bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmManyToManyMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmManyToManyMappingProvider INSTANCE = new OrmManyToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmManyToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public OrmManyToManyMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmManyToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java deleted file mode 100644 index bf5acb53c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmManyToOneMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmManyToOneMappingProvider INSTANCE = new OrmManyToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmManyToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public OrmManyToOneMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmManyToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java deleted file mode 100644 index 18e970fd24..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -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.OrmTypeMappingProvider; - - -public class OrmMappedSuperclassProvider implements OrmTypeMappingProvider -{ - public OrmMappedSuperclass buildTypeMapping(JpaFactory factory, OrmPersistentType parent) { - return factory.buildOrmMappedSuperclass(parent); - } - - public String getKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java deleted file mode 100644 index 1ea615a7ee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmNullAttributeMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmNullAttributeMappingProvider INSTANCE = new OrmNullAttributeMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmNullAttributeMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - public OrmAttributeMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmNullAttributeMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java deleted file mode 100644 index 0ec7805f0b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmOneToManyMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmOneToManyMappingProvider INSTANCE = new OrmOneToManyMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmOneToManyMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public OrmOneToManyMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmOneToManyMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java deleted file mode 100644 index 6b600fa27e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; - -public class OrmOneToOneMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmOneToOneMappingProvider INSTANCE = new OrmOneToOneMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmOneToOneMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public OrmOneToOneMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmOneToOneMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java deleted file mode 100644 index c3197b3dcd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; - -public class OrmTransientMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmTransientMappingProvider INSTANCE = new OrmTransientMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmTransientMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public OrmTransientMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmTransientMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java deleted file mode 100644 index 50ac6eaa2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; - -public class OrmVersionMappingProvider implements OrmAttributeMappingProvider -{ - // singleton - private static final OrmVersionMappingProvider INSTANCE = new OrmVersionMappingProvider(); - - /** - * Return the singleton. - */ - public static OrmAttributeMappingProvider instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmVersionMappingProvider() { - super(); - } - - public String getKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public OrmVersionMapping buildAttributeMapping(JpaFactory factory, OrmPersistentAttribute parent) { - return factory.buildOrmVersionMapping(parent); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java deleted file mode 100644 index 3153f0fcfc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.core.resources.IResource; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class OrmXmlImpl extends AbstractOrmJpaContextNode - implements OrmXml -{ - protected OrmResource ormResource; - - protected EntityMappings entityMappings; - - - public OrmXmlImpl(MappingFileRef parent, OrmResource ormResource) { - super(parent); - this.initialize(ormResource); - } - - @Override - public MappingFileRef getParent() { - return (MappingFileRef) super.getParent(); - } - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - if (getEntityMappings() != null) { - return getEntityMappings().getPersistentType(fullyQualifiedTypeName); - } - return null; - } - - @Override - public IResource getResource() { - return ormResource.getFile(); - } - - // **************** persistence ******************************************** - - @Override - public EntityMappings getEntityMappings() { - return this.entityMappings; - } - - protected void setEntityMappings(EntityMappings newEntityMappings) { - EntityMappings oldEntityMappings = this.entityMappings; - this.entityMappings = newEntityMappings; - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, newEntityMappings); - } - - public EntityMappings addEntityMappings() { - if (this.entityMappings != null) { - throw new IllegalStateException(); - } - - XmlEntityMappings xmlEntityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - this.entityMappings = buildEntityMappings(xmlEntityMappings); - this.ormResource.getContents().add(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, null, this.entityMappings); - return this.entityMappings; - } - - public void removeEntityMappings() { - if (this.entityMappings == null) { - throw new IllegalStateException(); - } - this.entityMappings.dispose(); - EntityMappings oldEntityMappings = this.entityMappings; - - this.entityMappings = null; - XmlEntityMappings xmlEntityMappings = this.ormResource.getEntityMappings(); //TODO helper removeEntityMappings method on ormResource?? - this.ormResource.getContents().remove(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, null); - } - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - if (getEntityMappings() != null) { - return getEntityMappings().getPersistenceUnitDefaults(); - } - return null; - } - // **************** updating *********************************************** - - protected void initialize(OrmResource ormResource) { - this.ormResource = ormResource; - if (ormResource.getEntityMappings() != null) { - this.entityMappings = buildEntityMappings(ormResource.getEntityMappings()); - } - } - - public void update(OrmResource ormResource) { - this.ormResource = ormResource; - if (ormResource.getEntityMappings() != null) { - if (this.entityMappings != null) { - this.entityMappings.update(ormResource.getEntityMappings()); - } - else { - setEntityMappings(buildEntityMappings(ormResource.getEntityMappings())); - } - } - else { - if (getEntityMappings() != null) { - getEntityMappings().dispose(); - } - setEntityMappings(null); - } - } - - protected EntityMappings buildEntityMappings(XmlEntityMappings xmlEntityMappings) { - return getJpaFactory().buildEntityMappings(this, xmlEntityMappings); - } - - - // ************************************************************************* - - public JpaStructureNode getStructureNode(int textOffset) { - if (entityMappings.containsOffset(textOffset)) { - return entityMappings.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - if (getEntityMappings() != null) { - getEntityMappings().addToMessages(messages); - } - } - - public void dispose() { - if (getEntityMappings() != null) { - getEntityMappings().dispose(); - } - } -} 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 b5f5c117d7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.CascadeType; - -public class VirtualCascadeType extends AbstractJpaEObject implements CascadeType -{ - Cascade javaCascade; - - protected boolean metadataComplete; - - public VirtualCascadeType(Cascade javaCascade, boolean metadataComplete) { - super(); - this.javaCascade = javaCascade; - this.metadataComplete = metadataComplete; - } - - public void update(Cascade javaCascade) { - this.javaCascade = javaCascade; - } - - public boolean isCascadeAll() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isAll(); - } - - public void setCascadeAll(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeMerge() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isMerge(); - } - - public void setCascadeMerge(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadePersist() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isPersist(); - } - - public void setCascadePersist(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeRefresh() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRefresh(); - } - - public void setCascadeRefresh(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isCascadeRemove() { - if (this.metadataComplete) { - return false; - } - return this.javaCascade.isRemove(); - } - - public void setCascadeRemove(boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } -} 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 f354af95fe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualMapKey.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaMultiRelationshipMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.MapKey; - -public class VirtualMapKey extends AbstractJpaEObject implements MapKey -{ - JavaMultiRelationshipMapping javaMultiRelationshipMapping; - - protected boolean metadataComplete; - - public VirtualMapKey(JavaMultiRelationshipMapping javaMultiRelationshipMapping, boolean metadataComplete) { - super(); - this.javaMultiRelationshipMapping = javaMultiRelationshipMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaMultiRelationshipMapping.getMapKey(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaMultiRelationshipMapping javaMultiRelationshipMapping) { - this.javaMultiRelationshipMapping = javaMultiRelationshipMapping; - } -} 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 7618d713d0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlAttributeOverride.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlColumn; - -public class VirtualXmlAttributeOverride extends AbstractJpaEObject implements XmlAttributeOverride -{ - - protected String name; - - protected final XmlColumn column; - - protected VirtualXmlAttributeOverride(String name, XmlColumn xmlColumn) { - super(); - this.name = name; - this.column = xmlColumn; - } - - public String getName() { - return this.name; - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } -} 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 9ac0ae3828..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlBasic.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlBasic -{ - JavaBasicMapping javaBasicMapping; - - protected final VirtualXmlColumn column; - - protected boolean metadataComplete; - - public VirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping, boolean metadataComplete) { - super(); - this.javaBasicMapping = javaBasicMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaBasicMapping.getColumn(), metadataComplete); - } - - public String getName() { - return this.javaBasicMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaBasicMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaBasicMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaBasicMapping.getDefaultOptional(); - } - return this.javaBasicMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public boolean isLob() { - if (this.metadataComplete) { - return false; - } - return this.javaBasicMapping.isLob(); - } - - public void setLob(boolean newLob) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaBasicMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EnumType getEnumerated() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(this.javaBasicMapping.getDefaultEnumerated()); - } - return org.eclipse.jpt.core.context.EnumType.toOrmResourceModel(this.javaBasicMapping.getEnumerated()); - } - - public void setEnumerated(EnumType newEnumerated) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public void update(JavaBasicMapping javaBasicMapping) { - this.javaBasicMapping = javaBasicMapping; - this.column.update(javaBasicMapping.getColumn()); - } - - public TextRange getNameTextRange() { - 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 7c8dbce6ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlColumn.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlColumn -{ - - protected Column column; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - - protected VirtualXmlColumn(OrmTypeMapping ormTypeMapping, Column column, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.column = column; - this.metadataComplete = metadataComplete; - } - - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.column.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getInsertable() { - if (this.metadataComplete) { - return this.column.getDefaultInsertable(); - } - return this.column.getInsertable(); - } - - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getLength() { - if (this.metadataComplete) { - return this.column.getDefaultLength(); - } - return this.column.getLength(); - } - - public void setLength(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return this.column.getDefaultName(); - } - return this.column.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getNullable() { - if (this.metadataComplete) { - return this.column.getDefaultNullable(); - } - return this.column.getNullable(); - } - - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getPrecision() { - if (this.metadataComplete) { - return this.column.getDefaultPrecision(); - } - return this.column.getPrecision(); - } - - public void setPrecision(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getScale() { - if (this.metadataComplete) { - return this.column.getDefaultScale(); - } - return this.column.getScale(); - } - - public void setScale(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (!this.metadataComplete) { - if (this.column.getSpecifiedTable() != null) { - return this.column.getSpecifiedTable(); - } - } - return this.ormTypeMapping.getTableName(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUnique() { - if (this.metadataComplete) { - return this.column.getDefaultUnique(); - } - return this.column.getUnique(); - } - - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUpdatable() { - if (this.metadataComplete) { - return this.column.getDefaultUpdatable(); - } - return this.column.getUpdatable(); - } - - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(Column column) { - this.column = column; - } - - public TextRange getNameTextRange() { - return null; - } - - 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 2e144ba5b1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbedded.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlEmbedded -{ - JavaEmbeddedMapping javaEmbeddedMapping; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - public VirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaEmbeddedMapping = javaEmbeddedMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaEmbeddedMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.metadataComplete) { - javaAttributeOverrides = this.javaEmbeddedMapping.attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaEmbeddedMapping.virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn(), this.metadataComplete); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } - - public void update(JavaEmbeddedMapping javaEmbeddedMapping) { - this.javaEmbeddedMapping = javaEmbeddedMapping; - } - - public TextRange getNameTextRange() { - return null; - } -} 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 8b1a6f6dc7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlEmbeddedId.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlEmbeddedId -{ - JavaEmbeddedIdMapping javaEmbeddedIdMapping; - - protected boolean metadataComplete; - - protected OrmTypeMapping ormTypeMapping; - - public VirtualXmlEmbeddedId(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping, boolean metadataComplete) { - super(); - this.ormTypeMapping = ormTypeMapping; - this.javaEmbeddedIdMapping = javaEmbeddedIdMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaEmbeddedIdMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlAttributeOverride> getAttributeOverrides() { - EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED_ID__ATTRIBUTE_OVERRIDES); - ListIterator<JavaAttributeOverride> javaAttributeOverrides; - if (!this.metadataComplete) { - javaAttributeOverrides = this.javaEmbeddedIdMapping.attributeOverrides(); - } - else { - javaAttributeOverrides = this.javaEmbeddedIdMapping.virtualAttributeOverrides(); - } - for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { - XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn(), this.metadataComplete); - XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); - attributeOverrides.add(xmlAttributeOverride); - } - return attributeOverrides; - } - - public void update(JavaEmbeddedIdMapping javaEmbeddedIdMapping) { - this.javaEmbeddedIdMapping = javaEmbeddedIdMapping; - } - - public TextRange getNameTextRange() { - return null; - } -} 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 ba814d42c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlGeneratedValue -{ - JavaGeneratedValue javaGeneratedValue; - - protected boolean metadataComplete; - - - public VirtualXmlGeneratedValue(JavaGeneratedValue javaGeneratedValue, boolean metadataComplete) { - super(); - this.javaGeneratedValue = javaGeneratedValue; - this.metadataComplete = metadataComplete; - } - - - public String getGenerator() { - if (this.metadataComplete) { - return null; - } - return this.javaGeneratedValue.getGenerator(); - } - - public GenerationType getStrategy() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.javaGeneratedValue.getStrategy()); - } - - public void setGenerator(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void setStrategy(GenerationType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TextRange getGeneratorTextRange() { - return null; - } - - public void update(JavaGeneratedValue javaGeneratedValue) { - this.javaGeneratedValue = javaGeneratedValue; - } -} 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 308ce8b5e7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlId.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaIdMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlId -{ - JavaIdMapping javaIdMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlColumn column; - - protected final VirtualXmlGeneratedValue virtualGeneratedValue; - - protected final VirtualXmlTableGenerator virtualTableGenerator; - - protected final VirtualXmlSequenceGenerator virtualSequenceGenerator; - - - - public VirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping, boolean metadataComplete) { - super(); - this.javaIdMapping = javaIdMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaIdMapping.getColumn(), metadataComplete); - this.virtualGeneratedValue = new VirtualXmlGeneratedValue(javaIdMapping.getGeneratedValue(), metadataComplete); - this.virtualTableGenerator = new VirtualXmlTableGenerator(javaIdMapping.getTableGenerator(), metadataComplete); - this.virtualSequenceGenerator = new VirtualXmlSequenceGenerator(javaIdMapping.getSequenceGenerator(), metadataComplete); - } - - public String getName() { - return this.javaIdMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaIdMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public XmlGeneratedValue getGeneratedValue() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getGeneratedValue() != null) { - return this.virtualGeneratedValue; - } - return null; - } - - public void setGeneratedValue(XmlGeneratedValue value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlSequenceGenerator getSequenceGenerator() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getSequenceGenerator() != null) { - return this.virtualSequenceGenerator; - } - return null; - } - - public void setSequenceGenerator(XmlSequenceGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlTableGenerator getTableGenerator() { - if (this.metadataComplete) { - return null; - } - if (this.javaIdMapping.getTableGenerator() != null) { - return this.virtualTableGenerator; - } - return null; - } - - public void setTableGenerator(XmlTableGenerator value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public void update(JavaIdMapping javaIdMapping) { - this.javaIdMapping = javaIdMapping; - this.column.update(javaIdMapping.getColumn()); - this.virtualGeneratedValue.update(javaIdMapping.getGeneratedValue()); - this.virtualTableGenerator.update(javaIdMapping.getTableGenerator()); - this.virtualSequenceGenerator.update(javaIdMapping.getSequenceGenerator()); - } - - public TextRange getNameTextRange() { - 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 60505b096e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinColumn.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaJoinColumn; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlJoinColumn extends AbstractJpaEObject implements XmlJoinColumn -{ - protected JavaJoinColumn javaJoinColumn; - - protected boolean metadataComplete; - - protected VirtualXmlJoinColumn(JavaJoinColumn javaJoinColumn, boolean metadataComplete) { - super(); - this.javaJoinColumn = javaJoinColumn; - this.metadataComplete = metadataComplete; - } - - public String getColumnDefinition() { - if (this.metadataComplete) { - return null; - } - return this.javaJoinColumn.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getInsertable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultInsertable(); - } - return this.javaJoinColumn.getInsertable(); - } - - public void setInsertable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultName(); - } - return this.javaJoinColumn.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getReferencedColumnName() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultReferencedColumnName(); - } - return this.javaJoinColumn.getReferencedColumnName(); - } - - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getNullable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultNullable(); - } - return this.javaJoinColumn.getNullable(); - } - - public void setNullable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultTable(); - } - return this.javaJoinColumn.getTable(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUnique() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultUnique(); - } - return this.javaJoinColumn.getUnique(); - } - - public void setUnique(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getUpdatable() { - if (this.metadataComplete) { - return this.javaJoinColumn.getDefaultUpdatable(); - } - return this.javaJoinColumn.getUpdatable(); - } - - public void setUpdatable(Boolean value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaJoinColumn javaJoinColumn) { - this.javaJoinColumn = javaJoinColumn; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getTableTextRange() { - return null; - } - - 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 9275d0a514..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlJoinTable.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; -import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlJoinTable -{ - - protected JavaJoinTable javaJoinTable; - - protected boolean metadataComplete; - - protected OrmPersistentAttribute ormPersistentAttribute; - - - protected VirtualXmlJoinTable(OrmPersistentAttribute ormPersistentAttribute, JavaJoinTable javaJoinTable, boolean metadataComplete) { - super(); - this.ormPersistentAttribute = ormPersistentAttribute; - this.javaJoinTable = javaJoinTable; - this.metadataComplete = metadataComplete; - } - - protected OrmRelationshipMapping ormRelationshipMapping() { - return (OrmRelationshipMapping) this.ormPersistentAttribute.getMapping(); - } - - public String getName() { - if (!this.metadataComplete) { - if (this.javaJoinTable.getSpecifiedName() != null) { - return this.javaJoinTable.getSpecifiedName(); - } - } - return MappingTools.buildJoinTableDefaultName(ormRelationshipMapping()); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getCatalog() { - if (this.metadataComplete) { - return this.javaJoinTable.getDefaultCatalog(); - } - return this.javaJoinTable.getCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - if (this.metadataComplete) { - return this.javaJoinTable.getDefaultSchema(); - } - return this.javaJoinTable.getSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaJoinTable.specifiedJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - //VirtualXmlJoinTable is rebuilt every time, so just rebuilding the joinColumns list as well - public EList<XmlJoinColumn> getInverseJoinColumns() { - EList<XmlJoinColumn> inverseJoinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__INVERSE_JOIN_COLUMNS); - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaJoinTable.specifiedInverseJoinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - inverseJoinColumns.add(xmlJoinColumn); - } - - return inverseJoinColumns; - } - - public EList<XmlUniqueConstraint> getUniqueConstraints() { - EList<XmlUniqueConstraint> xmlUniqueConstraints = new EObjectContainmentEList<XmlUniqueConstraint>(XmlUniqueConstraint.class, this, OrmPackage.XML_JOIN_TABLE__UNIQUE_CONSTRAINTS); - - for (JavaUniqueConstraint uniqueConstraint : CollectionTools.iterable(this.javaJoinTable.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - public void update(JavaJoinTable javaJoinTable) { - this.javaJoinTable = javaJoinTable; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getCatalogTextRange() { - return null; - } - - public TextRange getSchemaTextRange() { - return null; - } - - public boolean isSpecified() { - return this.javaJoinTable.isSpecified(); - } -} 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 3983e29227..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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.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 AbstractJpaEObject implements XmlManyToMany -{ - JavaManyToManyMapping javaManyToManyMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - //TODO joinColumns not yet supported in the context model -// protected EList<JoinColumn> virtualJoinColumns; - - public VirtualXmlManyToMany(OrmPersistentAttribute ormPersistentAttribute, JavaManyToManyMapping javaManyToManyMapping, boolean metadataComplete) { - super(); - this.javaManyToManyMapping = javaManyToManyMapping; - this.metadataComplete = metadataComplete; -// this.initializeJoinColumns(javaOneToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaManyToManyMapping.getCascade(), this.metadataComplete); - this.virtualJoinTable = new VirtualXmlJoinTable(ormPersistentAttribute, javaManyToManyMapping.getJoinTable(), metadataComplete); - this.mapKey = new VirtualMapKey(javaManyToManyMapping, metadataComplete); - } - -// protected void initializeJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// this.virtualJoinColumns = new BasicEList<JoinColumn>(); -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumns.next(), this.metadataComplete)); -// } -// } - - public String getName() { - return this.javaManyToManyMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToManyMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToManyMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - return this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaManyToManyMapping.getDefaultTargetEntity(); - } - return this.javaManyToManyMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaManyToManyMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public MapKey getMapKey() { - return this.mapKey; - } - - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getOrderBy() { - if (this.metadataComplete) { - return null; - } - return this.javaManyToManyMapping.getOrderBy(); - } - - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaManyToManyMapping javaManyToManyMapping) { - this.javaManyToManyMapping = javaManyToManyMapping; - this.virtualCascadeType.update(javaManyToManyMapping.getCascade()); - this.virtualJoinTable.update(javaManyToManyMapping.getJoinTable()); -// this.updateJoinColumns(javaOneToManyMapping); - } - -// protected void updateJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// ListIterator<JoinColumn> virtualJoinColumns = this.virtualJoinColumns.listIterator(); -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// IJavaJoinColumn javaJoinColumn = javaJoinColumns.next(); -// if (virtualJoinColumns.hasNext()) { -// VirtualJoinColumn virtualJoinColumn = (VirtualJoinColumn) virtualJoinColumns.next(); -// virtualJoinColumn.update(javaJoinColumn); -// } -// else { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumn, this.metadataComplete)); -// } -// } -// -// while(virtualJoinColumns.hasNext()) { -// this.virtualJoinColumns.remove(virtualJoinColumns.next()); -// } -// } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - 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 349ec76333..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlManyToOne -{ - JavaManyToOneMapping javaManyToOneMapping; - - protected boolean metadataComplete; - -// protected VirtualJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - public VirtualXmlManyToOne(JavaManyToOneMapping javaManyToOneMapping, boolean metadataComplete) { - super(); - this.javaManyToOneMapping = javaManyToOneMapping; - this.metadataComplete = metadataComplete; - this.virtualCascadeType = new VirtualCascadeType(javaManyToOneMapping.getCascade(), this.metadataComplete); - } - - public String getName() { - return this.javaManyToOneMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToOneMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaManyToOneMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaManyToOneMapping.getDefaultOptional(); - } - return this.javaManyToOneMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_JOIN_TABLE__JOIN_COLUMNS); - //TODO here i'm using joinColumns() while VirtualXmlJoinTable uses specifiedJoinColumns()??? - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaManyToOneMapping.joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaManyToOneMapping.getDefaultTargetEntity(); - } - return this.javaManyToOneMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaManyToOneMapping javaManyToOneMapping) { - this.javaManyToOneMapping = javaManyToOneMapping; - this.virtualCascadeType.update(javaManyToOneMapping.getCascade()); - } - - public TextRange getNameTextRange() { - 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 7f63835d9a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlNullAttributeMapping.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlNullAttributeMapping -{ - JavaAttributeMapping javaAttributeMapping; - - protected boolean metadataComplete; - - public VirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, boolean metadataComplete) { - super(); - this.javaAttributeMapping = javaAttributeMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaAttributeMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaAttributeMapping javaAttributeMapping) { - this.javaAttributeMapping = javaAttributeMapping; - } - - 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 53469b4aba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.OrmPersistentAttribute; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlOneToMany -{ - JavaOneToManyMapping javaOneToManyMapping; - - protected boolean metadataComplete; - - protected final VirtualXmlJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - protected final MapKey mapKey; - - //TODO joinColumns not yet supported in the context model -// protected EList<JoinColumn> virtualJoinColumns; - - public VirtualXmlOneToMany(OrmPersistentAttribute ormPersistentAttribute, JavaOneToManyMapping javaOneToManyMapping, boolean metadataComplete) { - super(); - this.javaOneToManyMapping = javaOneToManyMapping; - this.metadataComplete = metadataComplete; -// this.initializeJoinColumns(javaOneToManyMapping); - this.virtualCascadeType = new VirtualCascadeType(javaOneToManyMapping.getCascade(), this.metadataComplete); - this.virtualJoinTable = new VirtualXmlJoinTable(ormPersistentAttribute, javaOneToManyMapping.getJoinTable(), metadataComplete); - this.mapKey = new VirtualMapKey(javaOneToManyMapping, metadataComplete); - } - -// protected void initializeJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// this.virtualJoinColumns = new BasicEList<JoinColumn>(); -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumns.next(), this.metadataComplete)); -// } -// } - - public String getName() { - return this.javaOneToManyMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToManyMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToManyMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - return null; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - return this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaOneToManyMapping.getDefaultTargetEntity(); - } - return this.javaOneToManyMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToManyMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - public MapKey getMapKey() { - return this.mapKey; - } - - public void setMapKey(MapKey value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getOrderBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToManyMapping.getOrderBy(); - } - - public void setOrderBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaOneToManyMapping javaOneToManyMapping) { - this.javaOneToManyMapping = javaOneToManyMapping; - this.virtualCascadeType.update(javaOneToManyMapping.getCascade()); - this.virtualJoinTable.update(javaOneToManyMapping.getJoinTable()); -// this.updateJoinColumns(javaOneToManyMapping); - } - -// protected void updateJoinColumns(IJavaOneToManyMapping javaOneToManyMapping) { -// ListIterator<IJavaJoinColumn> javaJoinColumns; -// ListIterator<JoinColumn> virtualJoinColumns = this.virtualJoinColumns.listIterator(); -// if (this.metadataComplete) { -// javaJoinColumns = this.javaOneToManyMapping.defaultJoinColumns(); -// } -// else { -// javaJoinColumns = this.javaOneToManyMapping.joinColumns(); -// } -// -// while (javaJoinColumns.hasNext()) { -// IJavaJoinColumn javaJoinColumn = javaJoinColumns.next(); -// if (virtualJoinColumns.hasNext()) { -// VirtualJoinColumn virtualJoinColumn = (VirtualJoinColumn) virtualJoinColumns.next(); -// virtualJoinColumn.update(javaJoinColumn); -// } -// else { -// this.virtualJoinColumns.add(new VirtualJoinColumn(javaJoinColumn, this.metadataComplete)); -// } -// } -// -// while(virtualJoinColumns.hasNext()) { -// this.virtualJoinColumns.remove(virtualJoinColumns.next()); -// } -// } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - 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 b771b2b2c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlOneToOne -{ - JavaOneToOneMapping javaOneToOneMapping; - - protected boolean metadataComplete; - -// protected VirtualJoinTable virtualJoinTable; - - protected final VirtualCascadeType virtualCascadeType; - - public VirtualXmlOneToOne(JavaOneToOneMapping javaOneToOneMapping, boolean metadataComplete) { - super(); - this.javaOneToOneMapping = javaOneToOneMapping; - this.metadataComplete = metadataComplete; - this.virtualCascadeType = new VirtualCascadeType(javaOneToOneMapping.getCascade(), this.metadataComplete); - } - - public String getName() { - return this.javaOneToOneMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public FetchType getFetch() { - if (this.metadataComplete) { - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToOneMapping.getDefaultFetch()); - } - return org.eclipse.jpt.core.context.FetchType.toOrmResourceModel(this.javaOneToOneMapping.getFetch()); - } - - public void setFetch(FetchType newFetch) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Boolean getOptional() { - if (this.metadataComplete) { - return this.javaOneToOneMapping.getDefaultOptional(); - } - return this.javaOneToOneMapping.getOptional(); - } - - public void setOptional(Boolean newOptional) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlJoinColumn> getJoinColumns() { - //TODO need to check metadataComplete here - EList<XmlJoinColumn> joinColumns = new EObjectContainmentEList<XmlJoinColumn>(XmlJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__JOIN_COLUMNS); - //TODO here i'm using joinColumns() while VirtualXmlJoinTable uses specifiedJoinColumns()??? - for (JavaJoinColumn joinColumn : CollectionTools.iterable(this.javaOneToOneMapping.joinColumns())) { - XmlJoinColumn xmlJoinColumn = new VirtualXmlJoinColumn(joinColumn, this.metadataComplete); - joinColumns.add(xmlJoinColumn); - } - return joinColumns; - } - - public CascadeType getCascade() { - return this.virtualCascadeType; - } - - public void setCascade(CascadeType value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlJoinTable getJoinTable() { - //TODO we don't yet support JoinTable in the context model for many-to-one mappings - return null;//this.virtualJoinTable; - } - - public void setJoinTable(XmlJoinTable value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTargetEntity() { - if (this.metadataComplete) { - return this.javaOneToOneMapping.getDefaultTargetEntity(); - } - return this.javaOneToOneMapping.getTargetEntity(); - } - - public void setTargetEntity(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getMappedBy() { - if (this.metadataComplete) { - return null; - } - return this.javaOneToOneMapping.getMappedBy(); - } - - public void setMappedBy(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> joinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_ONE_TO_ONE__PRIMARY_KEY_JOIN_COLUMNS); - if (!this.metadataComplete) { - for (JavaPrimaryKeyJoinColumn joinColumn : CollectionTools.iterable(this.javaOneToOneMapping.primaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(joinColumn/*, this.metadataComplete*/); - joinColumns.add(xmlJoinColumn); - } - } - return joinColumns; - } - - public void update(JavaOneToOneMapping javaOneToOneMapping) { - this.javaOneToOneMapping = javaOneToOneMapping; - this.virtualCascadeType.update(javaOneToOneMapping.getCascade()); - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getMappedByTextRange() { - 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 9465b2ec3c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlPrimaryKeyJoinColumn.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlPrimaryKeyJoinColumn -{ - - protected JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn; - - - protected VirtualXmlPrimaryKeyJoinColumn(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - super(); - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } - - public String getName() { - return this.javaPrimaryKeyJoinColumn.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getColumnDefinition() { - return this.javaPrimaryKeyJoinColumn.getColumnDefinition(); - } - - public void setColumnDefinition(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getReferencedColumnName() { - return this.javaPrimaryKeyJoinColumn.getReferencedColumnName(); - } - - public void setReferencedColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getReferencedColumnNameTextRange() { - return null; - } - - public void update(JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn) { - this.javaPrimaryKeyJoinColumn = javaPrimaryKeyJoinColumn; - } -} 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 5d5a009a51..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSecondaryTable.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.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 AbstractJpaEObject implements XmlSecondaryTable -{ - - protected JavaSecondaryTable javaSecondaryTable; - - protected VirtualXmlSecondaryTable(JavaSecondaryTable javaSecondaryTable) { - super(); - this.javaSecondaryTable = javaSecondaryTable; - } - - public String getName() { - return this.javaSecondaryTable.getSpecifiedName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getCatalog() { - return this.javaSecondaryTable.getSpecifiedCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - return this.javaSecondaryTable.getSpecifiedSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - //VirtualXmlSecondaryTable is rebuilt everytime, so rebuilding the joinColumns list as well - public EList<XmlPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { - EList<XmlPrimaryKeyJoinColumn> primaryKeyJoinColumns = new EObjectContainmentEList<XmlPrimaryKeyJoinColumn>(XmlPrimaryKeyJoinColumn.class, this, OrmPackage.XML_SECONDARY_TABLE_IMPL__PRIMARY_KEY_JOIN_COLUMNS); - - for (JavaPrimaryKeyJoinColumn pkJoinColumn : CollectionTools.iterable(this.javaSecondaryTable.specifiedPrimaryKeyJoinColumns())) { - XmlPrimaryKeyJoinColumn xmlPkJoinColumn = new VirtualXmlPrimaryKeyJoinColumn(pkJoinColumn); - primaryKeyJoinColumns.add(xmlPkJoinColumn); - } - - return primaryKeyJoinColumns; - } - - 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; - } - - public TextRange getNameTextRange() { - return null; - } - - public TextRange getCatalogTextRange() { - return null; - } - - public TextRange getSchemaTextRange() { - return null; - } - - public void update(JavaSecondaryTable javaSecondaryTable) { - this.javaSecondaryTable = javaSecondaryTable; - } - -} 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 c6ab23dc26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlSequenceGenerator.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaSequenceGenerator; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.utility.TextRange; - -public class VirtualXmlSequenceGenerator extends AbstractJpaEObject implements XmlSequenceGenerator -{ - JavaSequenceGenerator javaSequenceGenerator; - - protected boolean metadataComplete; - - - public VirtualXmlSequenceGenerator(JavaSequenceGenerator javaSequenceGenerator, boolean metadataComplete) { - super(); - this.javaSequenceGenerator = javaSequenceGenerator; - this.metadataComplete = metadataComplete; - } - - public String getSequenceName() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getSequenceName(); - } - - public void setSequenceName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getAllocationSize(); - } - - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getInitialValue(); - } - - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaSequenceGenerator.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaSequenceGenerator javaSequenceGenerator) { - this.javaSequenceGenerator = javaSequenceGenerator; - } - - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - 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 332f6cae25..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTableGenerator.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaTableGenerator; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class VirtualXmlTableGenerator extends AbstractJpaEObject implements XmlTableGenerator -{ - JavaTableGenerator javaTableGenerator; - - protected boolean metadataComplete; - - - public VirtualXmlTableGenerator(JavaTableGenerator javaTableGenerator, boolean metadataComplete) { - super(); - this.javaTableGenerator = javaTableGenerator; - this.metadataComplete = metadataComplete; - } - - public String getCatalog() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getCatalog(); - } - - public void setCatalog(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getPkColumnName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getPkColumnName(); - } - - public void setPkColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getPkColumnValue() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getPkColumnValue(); - } - - public void setPkColumnValue(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getSchema() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getSchema(); - } - - public void setSchema(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getTable() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getTable(); - } - - public void setTable(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getValueColumnName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getValueColumnName(); - } - - public void setValueColumnName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getAllocationSize() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getAllocationSize(); - } - - public void setAllocationSize(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public Integer getInitialValue() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getInitialValue(); - } - - public void setInitialValue(Integer value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public String getName() { - if (this.metadataComplete) { - return null; - } - return this.javaTableGenerator.getName(); - } - - public void setName(String value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - - - 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.javaTableGenerator.uniqueConstraints())) { - XmlUniqueConstraint xmlUniqueConstraint = new VirtualXmlUniqueConstraint(uniqueConstraint, this.metadataComplete); - xmlUniqueConstraints.add(xmlUniqueConstraint); - } - - return xmlUniqueConstraints; - } - - public void update(JavaTableGenerator javaTableGenerator) { - this.javaTableGenerator = javaTableGenerator; - } - - public TextRange getNameTextRange() { - return getValidationTextRange(); - } - - 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 8e80ccc9e3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlTransient.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlTransient -{ - JavaTransientMapping javaTransientMapping; - - protected boolean metadataComplete; - - public VirtualXmlTransient(JavaTransientMapping javaTransientMapping, boolean metadataComplete) { - super(); - this.javaTransientMapping = javaTransientMapping; - this.metadataComplete = metadataComplete; - } - - public String getName() { - return this.javaTransientMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaTransientMapping javaTransientMapping) { - this.javaTransientMapping = javaTransientMapping; - } - - - public TextRange getNameTextRange() { - return null; - } - -} 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 4f106eace8..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 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.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlUniqueConstraint -{ - protected JavaUniqueConstraint javaUniqueConstraint; - - protected boolean metadataComplete; - - protected VirtualXmlUniqueConstraint(JavaUniqueConstraint javaUniqueConstraint, boolean metadataComplete) { - super(); - this.javaUniqueConstraint = javaUniqueConstraint; - this.metadataComplete = metadataComplete; - } - - public EList<String> getColumnNames() { - EList<String> columnNames = new EDataTypeEList<String>(String.class, this, OrmPackage.XML_UNIQUE_CONSTRAINT_IMPL__COLUMN_NAMES); - - for (String columnName : CollectionTools.iterable(this.javaUniqueConstraint.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 c402e38e7e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlVersion.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.JavaVersionMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.common.AbstractJpaEObject; -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 AbstractJpaEObject implements XmlVersion -{ - JavaVersionMapping javaVersionMapping; - - protected final VirtualXmlColumn column; - - protected boolean metadataComplete; - - public VirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping, boolean metadataComplete) { - super(); - this.javaVersionMapping = javaVersionMapping; - this.metadataComplete = metadataComplete; - this.column = new VirtualXmlColumn(ormTypeMapping, javaVersionMapping.getColumn(), metadataComplete); - } - - public String getName() { - return this.javaVersionMapping.getPersistentAttribute().getName(); - } - - public void setName(String newName) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public XmlColumn getColumn() { - return this.column; - } - - public void setColumn(XmlColumn value) { - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public TemporalType getTemporal() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.TemporalType.toOrmResourceModel(this.javaVersionMapping.getTemporal()); - } - - public void setTemporal(TemporalType newTemporal){ - throw new UnsupportedOperationException("cannot set values on a virtual mapping"); - } - - public void update(JavaVersionMapping javaVersionMapping) { - this.javaVersionMapping = javaVersionMapping; - this.column.update(javaVersionMapping.getColumn()); - } - - - public TextRange getNameTextRange() { - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java deleted file mode 100644 index 0896417bdd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceJpaContextNode.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.persistence; - -import java.util.List; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.persistence.PersistenceJpaContextNode; -import org.eclipse.jpt.core.internal.context.AbstractJpaContextNode; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public abstract class AbstractPersistenceJpaContextNode extends AbstractJpaContextNode implements PersistenceJpaContextNode -{ - // ********** constructor ********** - - protected AbstractPersistenceJpaContextNode(JpaContextNode parent) { - super(parent); - } - - // ********** validation ********** - - /** - * All subclass implementations {@link #addToMessages(List<IMessage>)} - * should be preceded by a "super" call to this method - */ - public void addToMessages(List<IMessage> messages) { - - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java deleted file mode 100644 index 2cf6519bf9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import java.util.List; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -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.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -/** - * This is the context model object which corresponds to the - * persistence resource model object XmlJavaClassRef. - * XmlJavaClassRef corresponds to the class tag in the persistence.xml - */ -public class GenericClassRef extends AbstractPersistenceJpaContextNode - implements ClassRef -{ - //this is null for the implied classRef case - protected XmlJavaClassRef xmlJavaClassRef; - - protected String className; - - protected JavaPersistentType javaPersistentType; - - - public GenericClassRef(PersistenceUnit parent, XmlJavaClassRef classRef) { - super(parent); - initialize(classRef); - } - - public GenericClassRef(PersistenceUnit parent, String className) { - super(parent); - initialize(className); - } - - public String getId() { - return PersistenceStructureNodes.CLASS_REF_ID; - } - - public boolean isFor(String fullyQualifiedTypeName) { - if (getClassName() == null) { - return false; - } - return getClassName().equals(fullyQualifiedTypeName); - } - - public boolean isVirtual() { - return this.xmlJavaClassRef == null; - } - - - // **************** class name ********************************************* - - public String getClassName() { - return this.className; - } - - public void setClassName(String newClassName) { - String oldClassName = this.className; - this.className = newClassName; - this.xmlJavaClassRef.setJavaClass(newClassName); - firePropertyChanged(CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - protected void setClassName_(String newClassName) { - String oldClassName = this.className; - this.className = newClassName; - firePropertyChanged(CLASS_NAME_PROPERTY, oldClassName, newClassName); - } - - - // **************** java persistent type *********************************** - - public JavaPersistentType getJavaPersistentType() { - return this.javaPersistentType; - } - - protected void setJavaPersistentType(JavaPersistentType newJavaPersistentType) { - JavaPersistentType oldJavaPersistentType = this.javaPersistentType; - this.javaPersistentType = newJavaPersistentType; - firePropertyChanged(ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY, oldJavaPersistentType, newJavaPersistentType); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlJavaClassRef classRef) { - this.xmlJavaClassRef = classRef; - this.className = classRef.getJavaClass(); - initializeJavaPersistentType(); - } - - protected void initialize(String className) { - this.className = className; - initializeJavaPersistentType(); - } - - protected void initializeJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJpaProject().getJavaPersistentTypeResource(getClassName()); - if (persistentTypeResource != null) { - this.javaPersistentType = buildJavaPersistentType(persistentTypeResource); - } - } - - public void update(XmlJavaClassRef classRef) { - this.xmlJavaClassRef = classRef; - setClassName_(classRef.getJavaClass()); - updateJavaPersistentType(); - } - - public void update(String className) { - this.xmlJavaClassRef = null; - setClassName_(className); - updateJavaPersistentType(); - } - - protected void updateJavaPersistentType() { - JavaResourcePersistentType persistentTypeResource = getJpaProject().getJavaPersistentTypeResource(getClassName()); - if (persistentTypeResource == null) { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - setJavaPersistentType(null); - } - else { - if (getJavaPersistentType() != null) { - getJavaPersistentType().update(persistentTypeResource); - } - else { - setJavaPersistentType(buildJavaPersistentType(persistentTypeResource)); - } - } - } - - protected JavaPersistentType buildJavaPersistentType(JavaResourcePersistentType resourcePersistentType) { - return getJpaFactory().buildJavaPersistentType(this, resourcePersistentType); - } - - - // ************************************************************************* - - // ************************* validation ********************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addUnspecifiedClassMessage(messages); - addUnresolvedClassMessage(messages); - addJavaPersistentTypeMessages(messages); - } - - protected void addUnspecifiedClassMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getClassName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_CLASS, - this, getValidationTextRange()) - ); - } - } - - protected void addUnresolvedClassMessage(List<IMessage> messages) { - if (! StringTools.stringIsEmpty(getClassName()) && getJavaPersistentType() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_CLASS, - new String[] {getClassName()}, - this, - this.getValidationTextRange()) - ); - } - } - - protected void addJavaPersistentTypeMessages(List<IMessage> messages) { - if (getJavaPersistentType() != null) { //class might not resolve to a java type - MappingFileRef mappingFileRef = getMappingFileContaining(getClassName()); - if (mappingFileRef != null) { - messages.add(DefaultJpaValidationMessages.buildMessage( - IMessage.LOW_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS, - new String[] { this.getClassName(), mappingFileRef.getFileName()}, - this, - this.getValidationTextRange())); - } - else { - try { - //bug 190062 - only add java validation messages if this class is not listed in a mapping file - getJavaPersistentType().addToMessages(messages); - } catch (Throwable t) { - JptCorePlugin.log(t); - } - } - } - } - - //possibly move this and make it API on PersistenceUnit - /** - * Return the mapping file that contains a persistent type for the given - * type name. Return null if no mapping file contains the persistent type. - */ - protected MappingFileRef getMappingFileContaining(String fullyQualifiedTypeName) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(getPersistenceUnit().mappingFileRefs())) { - if (mappingFileRef.getPersistentType(fullyQualifiedTypeName) != null) { - return mappingFileRef; - } - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean containsOffset(int textOffset) { - if (isVirtual()) { - return false; - } - return this.xmlJavaClassRef.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlJavaClassRef.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlJavaClassRef.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(getClassName()); - } - - public void dispose() { - if (getJavaPersistentType() != null) { - getJavaPersistentType().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java deleted file mode 100644 index c53de37e86..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import java.util.List; -import org.eclipse.core.resources.IProject; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericMappingFileRef extends AbstractPersistenceJpaContextNode - implements MappingFileRef -{ - //this is null for the implied mappingFileRef case - protected XmlMappingFileRef xmlMappingFileRef; - - protected String fileName; - - protected OrmXml ormXml; - - public GenericMappingFileRef(PersistenceUnit parent, XmlMappingFileRef mappingFileRef) { - super(parent); - this.initialize(mappingFileRef); - } - - public String getId() { - return PersistenceStructureNodes.MAPPING_FILE_REF_ID; - } - - - public boolean isVirtual() { - return xmlMappingFileRef == null; - } - - - // **************** file name ********************************************** - - public String getFileName() { - return this.fileName; - } - - public void setFileName(String newFileName) { - this.xmlMappingFileRef.setFileName(newFileName); - setFileName_(newFileName); - } - - protected void setFileName_(String newFileName) { - String oldFileName = this.fileName; - this.fileName = newFileName; - firePropertyChanged(FILE_NAME_PROPERTY, oldFileName, newFileName); - } - - public OrmXml getOrmXml() { - return this.ormXml; - } - - protected void setOrmXml(OrmXml newOrmXml) { - OrmXml oldOrmXml = this.ormXml; - this.ormXml = newOrmXml; - firePropertyChanged(ORM_XML_PROPERTY, oldOrmXml, newOrmXml); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlMappingFileRef mappingFileRef) { - this.xmlMappingFileRef = mappingFileRef; - initializeFileName(); - initializeOrmXml(); - } - - protected void initializeFileName() { - if (isVirtual()) { - fileName = JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH; - } - else { - fileName = xmlMappingFileRef.getFileName(); - } - } - - protected void initializeOrmXml() { - if (fileName != null) { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - OrmResource ormResource = oae.getResource(fileName); - - if (ormResource != null && ormResource.exists()) { - ormXml = buildOrmXml(ormResource); - } - oae.dispose(); - } - } - - public void update(XmlMappingFileRef mappingFileRef) { - xmlMappingFileRef = mappingFileRef; - updateFileName(); - updateOrmXml(); - } - - protected void updateFileName() { - if (isVirtual()) { - setFileName_(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - } - else { - setFileName_(xmlMappingFileRef.getFileName()); - } - } - - protected void updateOrmXml() { - if (fileName != null) { - IProject project = getJpaProject().getProject(); - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(project); - OrmResource ormResource = oae.getResource(JptCorePlugin.getOrmXmlDeploymentURI(project, fileName)); - if (ormResource != null && ormResource.exists()) { - if (ormXml != null) { - ormXml.update(ormResource); - } - else { - setOrmXml(buildOrmXml(ormResource)); - } - } - else { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - setOrmXml(null); - } - oae.dispose(); - } - else { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - setOrmXml(null); - } - } - - protected OrmXml buildOrmXml(OrmResource ormResource) { - return getJpaFactory().buildOrmXml(this, ormResource); - } - - - // ************************************************************************* - - public PersistenceUnitDefaults getPersistenceUnitDefaults() { - if (getOrmXml() != null) { - return getOrmXml().getPersistenceUnitDefaults(); - } - return null; - } - - public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { - if (getOrmXml() != null) { - return getOrmXml().getPersistentType(fullyQualifiedTypeName); - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public boolean containsOffset(int textOffset) { - if (this.xmlMappingFileRef == null) { - return false; - } - return this.xmlMappingFileRef.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - if (isVirtual()) { - return null; - } - return this.xmlMappingFileRef.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - if (isVirtual()) { - return getPersistenceUnit().getValidationTextRange(); - } - return this.xmlMappingFileRef.getValidationTextRange(); - } - - //**************** Validation ************************* - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - this.addUnspecifiedMappingFileMessage(messages); - this.addUnresolvedMappingFileMessage(messages); - this.addInvalidMappingFileContentMessage(messages); - if (getOrmXml() != null) { - getOrmXml().addToMessages(messages); - } - } - - - protected void addUnspecifiedMappingFileMessage(List<IMessage> messages) { - if (StringTools.stringIsEmpty(getFileName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_MAPPING_FILE, - this, - getValidationTextRange()) - ); - } - } - - protected void addUnresolvedMappingFileMessage(List<IMessage> messages) { - if (!StringTools.stringIsEmpty(getFileName()) && getOrmXml() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_MAPPING_FILE, - new String[] {getFileName()}, - this, - getValidationTextRange()) - ); - } - } - - protected void addInvalidMappingFileContentMessage(List<IMessage> messages) { - if (getOrmXml() != null - && getOrmXml().getEntityMappings() == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_INVALID_MAPPING_FILE, - new String[] {getFileName()}, - this, - getValidationTextRange()) - ); - } - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getFileName()); - } - - public void dispose() { - if (getOrmXml() != null) { - getOrmXml().dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java deleted file mode 100644 index 9aa1a83e05..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.CollectionTools; -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; - -public class GenericPersistence extends AbstractPersistenceJpaContextNode - implements Persistence -{ - protected XmlPersistence xmlPersistence; - - // the implementation here is a single persistence unit, although the API - // is for a list. we will want to support multiple persistence units soon. - protected PersistenceUnit persistenceUnit; - - public GenericPersistence(PersistenceXml parent, XmlPersistence xmlPersistence) { - super(parent); - this.initialize(xmlPersistence); - } - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_ID; - } - - - // **************** persistence units ************************************** - - public ListIterator<PersistenceUnit> persistenceUnits() { - if (persistenceUnit == null) { - return EmptyListIterator.instance(); - } - else { - return new SingleElementListIterator<PersistenceUnit>(persistenceUnit); - } - } - - public int persistenceUnitsSize() { - return (persistenceUnit == null) ? 0 : 1; - } - - public PersistenceUnit addPersistenceUnit() { - return addPersistenceUnit(persistenceUnitsSize()); - } - - public PersistenceUnit addPersistenceUnit(int index) { - if (index > 0 || persistenceUnit != null) { - throw new IllegalStateException("This implementation does not support multiple persistence units."); - } - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - persistenceUnit = createPersistenceUnit(xmlPersistenceUnit); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - fireItemAdded(PERSISTENCE_UNITS_LIST, index, persistenceUnit); - return persistenceUnit; - } - - public void removePersistenceUnit(PersistenceUnit persistenceUnit) { - removePersistenceUnit(0); - } - - public void removePersistenceUnit(int index) { - if (index > 0 ) { - throw new IllegalArgumentException(new Integer(index).toString()); - } - PersistenceUnit oldPersistenceUnit = persistenceUnit; - persistenceUnit.dispose(); - persistenceUnit = null; - xmlPersistence.getPersistenceUnits().remove(index); - fireItemRemoved(PERSISTENCE_UNITS_LIST, index, oldPersistenceUnit); - } - - protected void addPersistenceUnit_(PersistenceUnit newPersistenceUnit) { - persistenceUnit = newPersistenceUnit; - fireItemAdded(PERSISTENCE_UNITS_LIST, 0, persistenceUnit); - } - - protected void removePersistenceUnit_(PersistenceUnit oldPersistenceUnit) { - persistenceUnit.dispose(); - persistenceUnit = null; - fireItemRemoved(PERSISTENCE_UNITS_LIST, 0, oldPersistenceUnit); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlPersistence xmlPersistence) { - this.xmlPersistence = xmlPersistence; - initializePersistenceUnits(xmlPersistence); - } - - protected void initializePersistenceUnits(XmlPersistence persistence) { - // only adding one here, until we support multiple persistence units - if (xmlPersistence.getPersistenceUnits().size() > 0) { - persistenceUnit = createPersistenceUnit(persistence.getPersistenceUnits().get(0)); - } - } - - public void update(XmlPersistence persistence) { - this.xmlPersistence = persistence; - getJpaFile(this.xmlPersistence.getResource().getResourceModel()).addRootStructureNode(this, this); - XmlPersistenceUnit xmlPersistenceUnit = null; - if (persistence.getPersistenceUnits().size() > 0) { - xmlPersistenceUnit = persistence.getPersistenceUnits().get(0); - } - - if (persistenceUnit != null) { - if (xmlPersistenceUnit != null) { - persistenceUnit.update(xmlPersistenceUnit); - } - else { - removePersistenceUnit_(persistenceUnit); - } - } - else { - if (xmlPersistenceUnit != null) { - addPersistenceUnit_(createPersistenceUnit(xmlPersistenceUnit)); - } - } - } - - protected PersistenceUnit createPersistenceUnit(XmlPersistenceUnit xmlPersistenceUnit) { - return getJpaFactory().buildPersistenceUnit(this, xmlPersistenceUnit); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No PersistenceUnit in this context"); - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (PersistenceUnit persistenceUnit : CollectionTools.iterable(persistenceUnits())) { - if (persistenceUnit.containsOffset(textOffset)) { - return persistenceUnit.getStructureNode(textOffset); - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (xmlPersistence == null) { - return false; - } - return xmlPersistence.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return xmlPersistence.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return xmlPersistence.getValidationTextRange(); - } - - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - //persistence root validation - addNoPersistenceUnitMessage(messages); - - // note to neil (or whomever): extraneous persistence units can be - // accessed through the XmlPersistence resource object - addMultiplePersistenceUnitMessage(messages); - - - //persistence unit validation - if (persistenceUnit != null) { - persistenceUnit.addToMessages(messages); - } - } - - protected void addNoPersistenceUnitMessage(List<IMessage> messages) { - if (persistenceUnit == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_NO_PERSISTENCE_UNIT, - this, - this.getValidationTextRange()) - ); - } - } - - protected void addMultiplePersistenceUnitMessage(List<IMessage> messages) { - if (xmlPersistence.getPersistenceUnits().size() > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.NORMAL_SEVERITY, - JpaValidationMessages.PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS, - this, - this.getValidationTextRange()) - ); - } - } - - public void dispose() { - getJpaFile(this.xmlPersistence.getResource().getResourceModel()).removeRootStructureNode(this); - for (PersistenceUnit persistenceUnit : CollectionTools.iterable(persistenceUnits())) { - persistenceUnit.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java deleted file mode 100644 index 395bc9c04f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceUnit.java +++ /dev/null @@ -1,1245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.persistence; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; -import java.util.Set; - -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.PersistentType; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlProperties; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -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.ReadOnlyCompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericPersistenceUnit extends AbstractPersistenceJpaContextNode - implements PersistenceUnit -{ - protected XmlPersistenceUnit xmlPersistenceUnit; - - protected String name; - - protected PersistenceUnitTransactionType specifiedTransactionType; - - protected PersistenceUnitTransactionType defaultTransactionType; - - protected String description; - - protected String provider; - - protected String jtaDataSource; - - protected String nonJtaDataSource; - - protected final List<MappingFileRef> specifiedMappingFileRefs; - - protected MappingFileRef impliedMappingFileRef; - - protected final List<ClassRef> specifiedClassRefs; - - protected final List<ClassRef> impliedClassRefs; - - protected Boolean specifiedExcludeUnlistedClasses; - - protected boolean defaultExcludeUnlistedClasses = false; - - protected final List<Property> properties; - - /* global generator definitions, defined elsewhere in model */ - protected final List<Generator> generators; - - /* global query definitions, defined elsewhere in model */ - protected final List<Query> queries; - - - protected String defaultSchema; - protected String defaultCatalog; - protected AccessType defaultAccess; - protected boolean defaultCascadePersist; - - public GenericPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) { - super(parent); - this.specifiedMappingFileRefs = new ArrayList<MappingFileRef>(); - this.specifiedClassRefs = new ArrayList<ClassRef>(); - this.impliedClassRefs = new ArrayList<ClassRef>(); - this.properties = new ArrayList<Property>(); - this.generators = new ArrayList<Generator>(); - this.queries = new ArrayList<Query>(); - this.initialize(persistenceUnit); - } - - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(GENERATORS_LIST); - nonUpdateAspectNames.add(QUERIES_LIST); - } - - public String getId() { - return PersistenceStructureNodes.PERSISTENCE_UNIT_ID; - } - - @Override - public PersistenceUnit getPersistenceUnit() { - return this; - } - - - // **************** parent ************************************************* - - @Override - public Persistence getParent() { - return (Persistence) super.getParent(); - } - - - // **************** name *************************************************** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.xmlPersistenceUnit.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - - // **************** transaction type *************************************** - - public PersistenceUnitTransactionType getTransactionType() { - return (isTransactionTypeDefault()) ? - getDefaultTransactionType() : getSpecifiedTransactionType(); - } - - public PersistenceUnitTransactionType getSpecifiedTransactionType() { - return this.specifiedTransactionType; - } - - public void setSpecifiedTransactionType(PersistenceUnitTransactionType newTransactionType) { - PersistenceUnitTransactionType oldTransactionType = this.specifiedTransactionType; - this.specifiedTransactionType = newTransactionType; - this.xmlPersistenceUnit.setTransactionType(PersistenceUnitTransactionType.toXmlResourceModel(newTransactionType)); - firePropertyChanged(SPECIFIED_TRANSACTION_TYPE_PROPERTY, oldTransactionType, newTransactionType); - } - - public boolean isTransactionTypeDefault() { - return this.specifiedTransactionType == null; - } - - public PersistenceUnitTransactionType getDefaultTransactionType() { - return this.defaultTransactionType; - } - - protected void setDefaultTransactionType(PersistenceUnitTransactionType newTransactionType) { - PersistenceUnitTransactionType oldTransactionType = this.defaultTransactionType; - this.defaultTransactionType = newTransactionType; - firePropertyChanged(DEFAULT_TRANSACTION_TYPE_PROPERTY, oldTransactionType, newTransactionType); - } - - // **************** description ******************************************** - - public String getDescription() { - return this.description; - } - - public void setDescription(String newDescription) { - String oldDescription = this.description; - this.description = newDescription; - this.xmlPersistenceUnit.setDescription(newDescription); - firePropertyChanged(DESCRIPTION_PROPERTY, oldDescription, newDescription); - } - - - // **************** provider *********************************************** - - public String getProvider() { - return this.provider; - } - - public void setProvider(String newProvider) { - String oldProvider = this.provider; - this.provider = newProvider; - this.xmlPersistenceUnit.setProvider(newProvider); - firePropertyChanged(PROVIDER_PROPERTY, oldProvider, newProvider); - } - - - // **************** jta data source **************************************** - - public String getJtaDataSource() { - return this.jtaDataSource; - } - - public void setJtaDataSource(String newJtaDataSource) { - String oldJtaDataSource = this.jtaDataSource; - this.jtaDataSource = newJtaDataSource; - this.xmlPersistenceUnit.setJtaDataSource(newJtaDataSource); - firePropertyChanged(JTA_DATA_SOURCE_PROPERTY, oldJtaDataSource, newJtaDataSource); - } - - - // **************** non-jta data source ************************************ - - public String getNonJtaDataSource() { - return this.nonJtaDataSource; - } - - public void setNonJtaDataSource(String newNonJtaDataSource) { - String oldNonJtaDataSource = this.nonJtaDataSource; - this.nonJtaDataSource = newNonJtaDataSource; - this.xmlPersistenceUnit.setNonJtaDataSource(newNonJtaDataSource); - firePropertyChanged(NON_JTA_DATA_SOURCE_PROPERTY, oldNonJtaDataSource, newNonJtaDataSource); - } - - - // **************** mapping file refs ************************************** - - public ListIterator<MappingFileRef> mappingFileRefs() { - if (impliedMappingFileRef == null) { - return specifiedMappingFileRefs(); - } - else { - return new ReadOnlyCompositeListIterator<MappingFileRef>( - specifiedMappingFileRefs(), impliedMappingFileRef); - } - } - - public int mappingFileRefsSize() { - if (impliedMappingFileRef == null) { - return specifiedMappingFileRefsSize(); - } - return 1 + specifiedMappingFileRefsSize(); - } - - // **************** specified mapping file refs **************************** - - public ListIterator<MappingFileRef> specifiedMappingFileRefs() { - return new CloneListIterator<MappingFileRef>(specifiedMappingFileRefs); - } - - public int specifiedMappingFileRefsSize() { - return specifiedMappingFileRefs.size(); - } - - public MappingFileRef addSpecifiedMappingFileRef() { - return addSpecifiedMappingFileRef(specifiedMappingFileRefs.size()); - } - - public MappingFileRef addSpecifiedMappingFileRef(int index) { - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - MappingFileRef mappingFileRef = buildMappingFileRef(xmlMappingFileRef); - specifiedMappingFileRefs.add(index, mappingFileRef); - this.xmlPersistenceUnit.getMappingFiles().add(index, xmlMappingFileRef); - fireItemAdded(SPECIFIED_MAPPING_FILE_REF_LIST, index, mappingFileRef); - return mappingFileRef; - } - - public void removeSpecifiedMappingFileRef(MappingFileRef mappingFileRef) { - removeSpecifiedMappingFileRef(specifiedMappingFileRefs.indexOf(mappingFileRef)); - } - - public void removeSpecifiedMappingFileRef(int index) { - MappingFileRef mappingFileRefRemoved = specifiedMappingFileRefs.remove(index); - mappingFileRefRemoved.dispose(); - this.xmlPersistenceUnit.getMappingFiles().remove(index); - fireItemRemoved(SPECIFIED_MAPPING_FILE_REF_LIST, index, mappingFileRefRemoved); - } - - protected void addSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - addSpecifiedMappingFileRef_(specifiedMappingFileRefs.size(), mappingFileRef); - } - - protected void addSpecifiedMappingFileRef_(int index, MappingFileRef mappingFileRef) { - addItemToList(index, mappingFileRef, specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REF_LIST); - } - - protected void removeSpecifiedMappingFileRef_(MappingFileRef mappingFileRef) { - removeSpecifiedMappingFileRef_(specifiedMappingFileRefs.indexOf(mappingFileRef)); - } - - protected void removeSpecifiedMappingFileRef_(int index) { - specifiedMappingFileRefs.get(index).dispose(); - removeItemFromList(index, specifiedMappingFileRefs, SPECIFIED_MAPPING_FILE_REF_LIST); - } - - - // **************** implied mapping file ref ******************************* - - public MappingFileRef getImpliedMappingFileRef() { - return impliedMappingFileRef; - } - - protected MappingFileRef setImpliedMappingFileRef() { - if (impliedMappingFileRef != null) { - throw new IllegalStateException("The implied mapping file ref is already set."); - } - MappingFileRef mappingFileRef = buildMappingFileRef(null); - impliedMappingFileRef = mappingFileRef; - firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, null, mappingFileRef); - return mappingFileRef; - } - - protected void unsetImpliedMappingFileRef() { - if (impliedMappingFileRef == null) { - throw new IllegalStateException("The implied mapping file ref is already unset."); - } - MappingFileRef mappingFileRef = impliedMappingFileRef; - impliedMappingFileRef.dispose(); - impliedMappingFileRef = null; - firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, mappingFileRef, null); - } - - - // **************** class refs ********************************************* - - @SuppressWarnings("unchecked") - public ListIterator<ClassRef> classRefs() { - return new ReadOnlyCompositeListIterator<ClassRef>( - specifiedClassRefs(), impliedClassRefs()); - } - - public int classRefsSize() { - return specifiedClassRefsSize() + impliedClassRefsSize(); - } - - // **************** specified class refs *********************************** - - public ListIterator<ClassRef> specifiedClassRefs() { - return new CloneListIterator<ClassRef>(this.specifiedClassRefs); - } - - public int specifiedClassRefsSize() { - return specifiedClassRefs.size(); - } - - public ClassRef addSpecifiedClassRef() { - return addSpecifiedClassRef(this.specifiedClassRefsSize()); - } - - public ClassRef addSpecifiedClassRef(int index) { - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - ClassRef classRef = buildClassRef(xmlClassRef); - this.specifiedClassRefs.add(index, classRef); - this.xmlPersistenceUnit.getClasses().add(index, xmlClassRef); - fireItemAdded(SPECIFIED_CLASS_REF_LIST, index, classRef); - return classRef; - } - - public void removeSpecifiedClassRef(ClassRef classRef) { - removeSpecifiedClassRef(this.specifiedClassRefs.indexOf(classRef)); - } - - public void removeSpecifiedClassRef(int index) { - ClassRef classRefRemoved = this.specifiedClassRefs.remove(index); - classRefRemoved.dispose(); - this.xmlPersistenceUnit.getClasses().remove(index); - fireItemRemoved(SPECIFIED_CLASS_REF_LIST, index, classRefRemoved); - } - - protected void addSpecifiedClassRef_(ClassRef classRef) { - addSpecifiedClassRef_(this.specifiedClassRefs.size(), classRef); - } - - protected void addSpecifiedClassRef_(int index, ClassRef classRef) { - addItemToList(index, classRef, this.specifiedClassRefs, SPECIFIED_CLASS_REF_LIST); - } - - protected void removeSpecifiedClassRef_(ClassRef classRef) { - classRef.dispose(); - removeSpecifiedClassRef_(this.specifiedClassRefs.indexOf(classRef)); - } - - protected void removeSpecifiedClassRef_(int index) { - removeItemFromList(index, this.specifiedClassRefs, SPECIFIED_CLASS_REF_LIST); - } - - - // **************** implied class refs ************************************* - - public ListIterator<ClassRef> impliedClassRefs() { - return new CloneListIterator<ClassRef>(impliedClassRefs); - } - - public int impliedClassRefsSize() { - return impliedClassRefs.size(); - } - - protected ClassRef addImpliedClassRef(String className) { - return addImpliedClassRef(impliedClassRefs.size(), className); - } - - protected ClassRef addImpliedClassRef(int index, String className) { - ClassRef classRef = buildClassRef(className); - addItemToList(index, classRef, impliedClassRefs, IMPLIED_CLASS_REF_LIST); - return classRef; - } - - protected void removeImpliedClassRef(ClassRef classRef) { - classRef.dispose(); - removeImpliedClassRef(impliedClassRefs.indexOf(classRef)); - } - - protected void removeImpliedClassRef(int index) { - removeItemFromList(index, impliedClassRefs, IMPLIED_CLASS_REF_LIST); - } - - - // **************** exclude unlisted classes ******************************* - - public boolean isExcludeUnlistedClasses() { - return getSpecifiedExcludeUnlistedClasses() == null ? getDefaultExcludeUnlistedClasses() : getSpecifiedExcludeUnlistedClasses().booleanValue(); - } - - public Boolean getSpecifiedExcludeUnlistedClasses() { - return this.specifiedExcludeUnlistedClasses; - } - - public void setSpecifiedExcludeUnlistedClasses(Boolean newExcludeUnlistedClasses) { - Boolean oldExcludeUnlistedClasses = this.specifiedExcludeUnlistedClasses; - this.specifiedExcludeUnlistedClasses = newExcludeUnlistedClasses; - - this.xmlPersistenceUnit.setExcludeUnlistedClasses(this.specifiedExcludeUnlistedClasses); - - firePropertyChanged(SPECIFIED_EXCLUDE_UNLISTED_CLASSED_PROPERTY, oldExcludeUnlistedClasses, newExcludeUnlistedClasses); - } - - public boolean getDefaultExcludeUnlistedClasses() { - // TODO - calculate default - // This is determined from the project - return this.defaultExcludeUnlistedClasses; - } - - - // **************** properties ********************************************* - - public ListIterator<Property> properties() { - return new CloneListIterator<Property>(this.properties); - } - - public int propertiesSize() { - return this.properties.size(); - } - - public Property getProperty(String key) { - if (key == null) { - throw new IllegalStateException("Cannot getProperty: key is null."); - } - for(Property property : this.properties) { - if(key.equals(property.getName())) { - return property; - } - } - return null; - } - - public ListIterator<Property> propertiesWithPrefix(String keyPrefix) { - if (keyPrefix == null) { - throw new IllegalStateException("Cannot find propertiesWithPrefix: keyPrefix is null."); - } - List<Property> properties = new ArrayList<Property>(); - - for(Property property : this.properties) { - if(property.getName() != null && property.getName().startsWith(keyPrefix)) { - properties.add( property); - } - } - return properties.listIterator(); - } - - public Property getProperty(String key, String value) { - if (key == null || value == null) { - throw new IllegalStateException("Cannot getProperty: key or value is null."); - } - for(Property property : this.properties) { - if(key.equals(property.getName())) { - if(value.equals(property.getValue())) { - return property; - } - } - } - return null; - } - - protected Property getProperty(int index) { - return this.properties.get(index); - } - - protected XmlProperty getXmlProperty(String name, String value) { - if (this.xmlPersistenceUnit.getProperties() == null) { - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - this.xmlPersistenceUnit.setProperties(xmlProperties); - } - for(XmlProperty xmlProperty : this.xmlPersistenceUnit.getProperties().getProperties()) { - if(name.equals(xmlProperty.getName()) && value.equals(xmlProperty.getValue())) { - return xmlProperty; - } - } - return null; - } - - /** - * Adds or Changes Property with the given key and value. - */ - public void putProperty(String key, String value, boolean allowDuplicates) { - if( ! allowDuplicates && this.containsProperty(key)) { - this.putXmlProperty(key, value, this.getProperty(key).getValue()); - return; - } - if( value != null) { - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName(key); - xmlProperty.setValue(value); - - this.addXmlProperty(xmlProperty, propertiesSize()); - return; - } - } - - public void replacePropertyValue(String key, String oldValue, String newValue) { - - this.putXmlProperty(key, newValue, oldValue); - } - - protected void putXmlProperty(String key, String value, String oldValue) { - if( value == null) { - this.removeProperty(key); - return; - } - - XmlProperty xmlProperty = this.getXmlProperty(key, oldValue); - if(xmlProperty == null) { - throw new NoSuchElementException("Missing Property name: " + key + ", value: " + oldValue); - } - xmlProperty.setValue(value); - } - - public boolean containsProperty(String key) { - return (this.getProperty(key) != null); - } - - public Property addProperty() { - return addProperty(propertiesSize()); - } - - public Property addProperty(int index) { - return this.addXmlProperty(PersistenceFactory.eINSTANCE.createXmlProperty(), index); - } - - protected Property addXmlProperty(XmlProperty xmlProperty, int index) { - - Property property = buildProperty(xmlProperty); - - if (this.xmlPersistenceUnit.getProperties() == null) { - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - this.xmlPersistenceUnit.setProperties(xmlProperties); - } - - this.properties.add(index, property); - this.xmlPersistenceUnit.getProperties().getProperties().add(index, xmlProperty); - this.fireItemAdded(PROPERTIES_LIST, index, property); - return property; - } - - public void removeProperty(String key) { - this.removeProperty(this.getProperty(key)); - } - - public void removeProperty(String key, String value) { - this.removeProperty(this.getProperty(key, value)); - } - - public void removeProperty(Property property) { - if (property != null) { - this.removeProperty(this.properties.indexOf(property)); - } - } - - protected void removeProperty(int index) { - Property propertyRemoved = this.properties.remove(index); - this.xmlPersistenceUnit.getProperties().getProperties().remove(index); - - if (this.xmlPersistenceUnit.getProperties().getProperties().isEmpty()) { - this.xmlPersistenceUnit.setProperties(null); - } - - fireItemRemoved(PROPERTIES_LIST, index, propertyRemoved); - } - - protected void addProperty_(Property property) { - addProperty_(this.properties.size(), property); - } - - protected void addProperty_(int index, Property property) { - addItemToList(index, property, this.properties, PROPERTIES_LIST); - } - - protected void removeProperty_(Property property) { - removeProperty_(this.properties.indexOf(property)); - } - - protected void removeProperty_(int index) { - removeItemFromList(index, this.properties, PROPERTIES_LIST); - } - - - // **************** Persistence Unit Defaults ********************************************* - - //TODO validation for multiple persistenceUnitDefaults. - - //Take the first PersistenceUnitDefaults found in an orm.xml file and use - //this for the defaults of the PersistenceUnit. - protected PersistenceUnitDefaults persistenceUnitDefaults() { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - PersistenceUnitDefaults persistenceUnitDefaults = mappingFileRef.getPersistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - return persistenceUnitDefaults; - } - } - return null; - } - - public String getDefaultSchema() { - return this.defaultSchema; - } - - protected void setDefaultSchema(String newDefaultSchema) { - String oldDefaultSchema = this.defaultSchema; - this.defaultSchema = newDefaultSchema; - firePropertyChanged(DEFAULT_SCHEMA_PROPERTY, oldDefaultSchema, newDefaultSchema); - } - - public String getDefaultCatalog() { - return this.defaultCatalog; - } - - protected void setDefaultCatalog(String newDefaultCatalog) { - String oldDefaultCatalog = this.defaultCatalog; - this.defaultCatalog = newDefaultCatalog; - firePropertyChanged(DEFAULT_CATALOG_PROPERTY, oldDefaultCatalog, newDefaultCatalog); - } - - public AccessType getDefaultAccess() { - return this.defaultAccess; - } - - protected void setDefaultAccess(AccessType newDefaultAccess) { - AccessType oldDefaultAccess = this.defaultAccess; - this.defaultAccess = newDefaultAccess; - firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldDefaultAccess, newDefaultAccess); - } - - public boolean getDefaultCascadePersist() { - return this.defaultCascadePersist; - } - - protected void setDefaultCascadePersist(boolean newDefaultCascadePersist) { - boolean oldDefaultCascadePersist = this.defaultCascadePersist; - this.defaultCascadePersist = newDefaultCascadePersist; - firePropertyChanged(DEFAULT_CASCADE_PERSIST_PROPERTY, oldDefaultCascadePersist, newDefaultCascadePersist); - } - - - // **************** global generator and query support ********************* - - public void addGenerator(Generator generator) { - this.generators.add(generator); - } - - public ListIterator<Generator> allGenerators() { - return new CloneListIterator<Generator>(this.generators); - } - - public void addQuery(Query query) { - this.queries.add(query); - } - - public ListIterator<Query> allQueries() { - return new CloneListIterator<Query>(this.queries); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlPersistenceUnit xmlPersistenceUnit) { - this.xmlPersistenceUnit = xmlPersistenceUnit; - this.name = xmlPersistenceUnit.getName(); - - //initialize specified classRefs before mappingFileRefs because of - //JpaFile rootStructureNode, we want the mapping file to "win", - //as it would in a Jpa runtime implementation - initializeSpecifiedClassRefs(xmlPersistenceUnit); - initializeMappingFileRefs(xmlPersistenceUnit); - //initialize implied classRefs last since they depend on both - //specified classRefs and mappingFileRefs - initializeImpliedClassRefs(xmlPersistenceUnit); - initializeProperties(xmlPersistenceUnit); - initializePersistenceUnitDefaults(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - this.specifiedTransactionType = specifiedTransactionType(xmlPersistenceUnit); - this.defaultTransactionType = defaultTransacationType(); - this.description = xmlPersistenceUnit.getDescription(); - this.provider = xmlPersistenceUnit.getProvider(); - this.jtaDataSource = xmlPersistenceUnit.getJtaDataSource(); - this.nonJtaDataSource = xmlPersistenceUnit.getNonJtaDataSource(); - this.specifiedExcludeUnlistedClasses = xmlPersistenceUnit.getExcludeUnlistedClasses(); - } - - protected void initializeMappingFileRefs(XmlPersistenceUnit xmlPersistenceUnit) { - for (XmlMappingFileRef xmlMappingFileRef : xmlPersistenceUnit.getMappingFiles()) { - specifiedMappingFileRefs.add(buildMappingFileRef(xmlMappingFileRef)); - } - if (! impliedMappingFileIsSpecified() && impliedMappingFileExists()) { - impliedMappingFileRef = buildMappingFileRef(null); - } - } - - protected void initializeSpecifiedClassRefs(XmlPersistenceUnit xmlPersistenceUnit) { - for (XmlJavaClassRef xmlJavaClassRef : xmlPersistenceUnit.getClasses()) { - specifiedClassRefs.add(buildClassRef(xmlJavaClassRef)); - } - } - - protected void initializeImpliedClassRefs(XmlPersistenceUnit xmlPersistenceUnit) { - if (getJpaProject().discoversAnnotatedClasses() && ! isExcludeUnlistedClasses()) { - for (String typeName : CollectionTools.iterable(this.getJpaProject().annotatedClassNames())) { - if ( ! classIsSpecified(typeName)) { - impliedClassRefs.add(buildClassRef(typeName)); - } - } - } - } - - protected void initializeProperties(XmlPersistenceUnit xmlPersistenceUnit) { - XmlProperties xmlProperties = xmlPersistenceUnit.getProperties(); - if (xmlProperties == null) { - return; - } - for (XmlProperty xmlProperty : xmlProperties.getProperties()) { - this.properties.add(buildProperty(xmlProperty)); - } - } - - protected void initializePersistenceUnitDefaults() { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - this.defaultSchema = this.schema(persistenceUnitDefaults); - this.defaultCatalog = this.catalog(persistenceUnitDefaults); - this.defaultAccess = this.access(persistenceUnitDefaults); - this.defaultCascadePersist = this.cascadePersist(persistenceUnitDefaults); - } - else { - this.defaultSchema = null; - this.defaultCatalog = null; - this.defaultAccess = null; - this.defaultCascadePersist = false; - } - } - - public void update(XmlPersistenceUnit persistenceUnit) { - this.xmlPersistenceUnit = persistenceUnit; - this.generators.clear(); - this.queries.clear(); - updateName(persistenceUnit); - updateSpecifiedTransactionType(persistenceUnit); - updateDefaultTransactionType(); - updateDescription(persistenceUnit); - updateProvider(persistenceUnit); - updateJtaDataSource(persistenceUnit); - updateNonJtaDataSource(persistenceUnit); - //update specified classRefs before mappingFileRefs because of - //JpaFile rootStructureNode, we want the mapping file to "win", - //as it would in a Jpa runtime implementation - updateSpecifiedClassRefs(persistenceUnit); - updateMappingFileRefs(persistenceUnit); - //update implied classRefs last since they depend on both - //specified classRefs and mappingFileRefs - updateImpliedClassRefs(persistenceUnit); - updateExcludeUnlistedClasses(persistenceUnit); - updateProperties(persistenceUnit); - updatePersistenceUnitDefaults(); - generatorRepositoryUpdated(); - queryRepositoryUpdated(); - } - - protected void updateName(XmlPersistenceUnit persistenceUnit) { - setName(persistenceUnit.getName()); - } - - protected void updateSpecifiedTransactionType(XmlPersistenceUnit persistenceUnit) { - setSpecifiedTransactionType(specifiedTransactionType(persistenceUnit)); - } - - protected PersistenceUnitTransactionType specifiedTransactionType(XmlPersistenceUnit persistenceUnit) { - return PersistenceUnitTransactionType.fromXmlResourceModel(persistenceUnit.getTransactionType()); - } - - protected void updateDefaultTransactionType() { - setDefaultTransactionType(defaultTransacationType()); - } - - protected PersistenceUnitTransactionType defaultTransacationType() { - // TODO - calculate default - // From the JPA spec: "In a Java EE environment, if this element is not - // specified, the default is JTA. In a Java SE environment, if this element - // is not specified, a default of RESOURCE_LOCAL may be assumed." - return null; - } - - protected void updateDescription(XmlPersistenceUnit persistenceUnit) { - setDescription(persistenceUnit.getDescription()); - } - - protected void updateProvider(XmlPersistenceUnit persistenceUnit) { - setProvider(persistenceUnit.getProvider()); - } - - protected void updateJtaDataSource(XmlPersistenceUnit persistenceUnit) { - setJtaDataSource(persistenceUnit.getJtaDataSource()); - } - - protected void updateNonJtaDataSource(XmlPersistenceUnit persistenceUnit) { - setNonJtaDataSource(persistenceUnit.getNonJtaDataSource()); - } - - protected void updateMappingFileRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<MappingFileRef> stream = specifiedMappingFileRefs(); - Iterator<XmlMappingFileRef> stream2 = new CloneIterator<XmlMappingFileRef>(persistenceUnit.getMappingFiles());//prevent ConcurrentModificiationException - - while (stream.hasNext()) { - MappingFileRef mappingFileRef = stream.next(); - if (stream2.hasNext()) { - mappingFileRef.update(stream2.next()); - } - else { - removeSpecifiedMappingFileRef_(mappingFileRef); - } - } - - while (stream2.hasNext()) { - addSpecifiedMappingFileRef_(buildMappingFileRef(stream2.next())); - } - - if (impliedMappingFileIsSpecified()) { - if (impliedMappingFileRef != null) { - unsetImpliedMappingFileRef(); - } - } - else { - if (impliedMappingFileExists()) { - if (impliedMappingFileRef == null) { - setImpliedMappingFileRef(); - } - getImpliedMappingFileRef().update(null); - } - else { - if (impliedMappingFileRef != null) { - unsetImpliedMappingFileRef(); - } - } - } - } - - protected boolean impliedMappingFileIsSpecified() { - String impliedMappingFile = JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH; - for (MappingFileRef each : specifiedMappingFileRefs) { - if (impliedMappingFile.equals(each.getFileName())) { - return true; - } - } - return false; - } - - protected boolean impliedMappingFileExists() { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForRead(getJpaProject().getProject()); - OrmResource or = oae.getResource(JptCorePlugin.getDefaultOrmXmlDeploymentURI(getJpaProject().getProject())); - boolean exists = or != null && or.exists(); - oae.dispose(); - return exists; - } - - protected MappingFileRef buildMappingFileRef(XmlMappingFileRef xmlMappingFileRef) { - return getJpaFactory().buildMappingFileRef(this, xmlMappingFileRef); - } - - protected void updateSpecifiedClassRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<ClassRef> stream = specifiedClassRefs(); - Iterator<XmlJavaClassRef> stream2 = new CloneIterator<XmlJavaClassRef>(persistenceUnit.getClasses());//prevent ConcurrentModificiationException - - while (stream.hasNext()) { - ClassRef classRef = stream.next(); - if (stream2.hasNext()) { - classRef.update(stream2.next()); - } - else { - removeSpecifiedClassRef_(classRef); - } - } - - while (stream2.hasNext()) { - addSpecifiedClassRef_(buildClassRef(stream2.next())); - } - } - - protected void updateImpliedClassRefs(XmlPersistenceUnit persistenceUnit) { - Iterator<ClassRef> impliedRefs = impliedClassRefs(); - Iterator<String> annotatedClassNames = getJpaProject().annotatedClassNames(); - - - if ( ! isExcludeUnlistedClasses()) { - while (impliedRefs.hasNext()) { - ClassRef classRef = impliedRefs.next(); - boolean updated = false; - while (! updated && annotatedClassNames.hasNext()) { - String annotatedClassName = annotatedClassNames.next(); - if ( ! classIsSpecified(annotatedClassName)) { - classRef.update(annotatedClassName); - updated = true; - } - } - if (! annotatedClassNames.hasNext() && ! updated) { - removeImpliedClassRef(classRef); - } - } - - while (annotatedClassNames.hasNext()) { - String annotatedClassName = annotatedClassNames.next(); - if ( ! classIsSpecified(annotatedClassName)) { - addImpliedClassRef(annotatedClassName); - } - } - } - else { - for (ClassRef classRef : CollectionTools.iterable(impliedClassRefs())) { - removeImpliedClassRef(classRef); - } - } - } - - protected ClassRef buildClassRef(XmlJavaClassRef xmlClassRef) { - return getJpaFactory().buildClassRef(this, xmlClassRef); - } - - protected ClassRef buildClassRef(String className) { - return getJpaFactory().buildClassRef(this, className); - } - - /** - * Return true if the class is specified either as a class - * or listed in a mapping file - */ - protected boolean classIsSpecified(String className) { - for (ClassRef specifiedClassRef : CollectionTools.iterable(specifiedClassRefs())) { - if (className.equals(specifiedClassRef.getClassName())) { - return true; - } - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - if (mappingFileRef.getPersistentType(className) != null) { - return true; - } - } - return false; - } - - protected void updateExcludeUnlistedClasses(XmlPersistenceUnit persistenceUnit) { - setSpecifiedExcludeUnlistedClasses(persistenceUnit.getExcludeUnlistedClasses()); - } - - protected void updateProperties(XmlPersistenceUnit persistenceUnit) { - XmlProperties xmlProperties = persistenceUnit.getProperties(); - - Iterator<Property> stream = properties(); - Iterator<XmlProperty> stream2; - - if (xmlProperties == null) { - stream2 = EmptyIterator.instance(); - } - else { - stream2 = new CloneIterator<XmlProperty>(xmlProperties.getProperties());//avoid ConcurrentModificationException - } - - while (stream.hasNext()) { - Property property = stream.next(); - if (stream2.hasNext()) { - property.update(stream2.next()); - } - else { - removeProperty_(property); - } - } - - while (stream2.hasNext()) { - addProperty_(buildProperty(stream2.next())); - } - } - - protected Property buildProperty(XmlProperty xmlProperty) { - return getJpaFactory().buildProperty(this, xmlProperty); - } - - protected void updatePersistenceUnitDefaults() { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - this.setDefaultSchema(this.schema(persistenceUnitDefaults)); - this.setDefaultCatalog(this.catalog(persistenceUnitDefaults)); - this.setDefaultAccess(this.access(persistenceUnitDefaults)); - this.setDefaultCascadePersist(this.cascadePersist(persistenceUnitDefaults)); - } - - protected String schema(PersistenceUnitDefaults persistenceUnitDefaults) { - if (persistenceUnitDefaults != null) { - if (persistenceUnitDefaults.getSchema() != null) { - return persistenceUnitDefaults.getSchema(); - } - } - Schema projectDefaultSchema = projectDefaultSchema(); - return projectDefaultSchema == null ? null : projectDefaultSchema.getName(); - } - - protected Schema projectDefaultSchema() { - return getJpaProject().getDefaultSchema(); - } - - protected String catalog(PersistenceUnitDefaults persistenceUnitDefaults) { - if (persistenceUnitDefaults != null) { - if (persistenceUnitDefaults.getCatalog() != null) { - return persistenceUnitDefaults.getCatalog(); - } - } - return projectDefaultCatalogName(); - } - - protected String projectDefaultCatalogName() { - Catalog catalog = getJpaProject().getConnectionProfile().getDefaultCatalog(); - return (catalog == null) ? null : catalog.getName(); - } - - protected AccessType access(PersistenceUnitDefaults persistenceUnitDefaults) { - return persistenceUnitDefaults == null ? null : persistenceUnitDefaults.getAccess(); - } - - protected boolean cascadePersist(PersistenceUnitDefaults persistenceUnitDefaults) { - return persistenceUnitDefaults == null ? false : persistenceUnitDefaults.isCascadePersist(); - } - - // This is called after the persistence unit has been updated to ensure - // we catch all added generators - protected void generatorRepositoryUpdated() { - fireListChanged(GENERATORS_LIST); - } - - // This is called after the persistence unit has been updated to ensure - // we catch all added queries - protected void queryRepositoryUpdated() { - fireListChanged(QUERIES_LIST); - } - - - // ********** Validation *********************************************** - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addMappingFileMessages(messages); - addClassMessages(messages); - } - - protected void addMappingFileMessages(List<IMessage> messages) { - addMultipleMetadataMessages(messages); - addDuplicateMappingFileMessages(messages); - - for (Iterator<MappingFileRef> stream = mappingFileRefs(); stream.hasNext();) { - stream.next().addToMessages(messages); - } - } - - protected void addMultipleMetadataMessages(List<IMessage> messages) { - Collection<PersistenceUnitDefaults> puDefaultsCollection = persistenceUnitDefaultsForValidation(); - if (puDefaultsCollection.size() > 1) { - for (PersistenceUnitDefaults puDefaults : puDefaultsCollection) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ENTITY_MAPPINGS_MULTIPLE_METADATA, - new String[] {this.getName()}, - puDefaults) - ); - } - } - } - - protected void addDuplicateMappingFileMessages(List<IMessage> messages) { - HashBag<String> fileBag = new HashBag<String>( - CollectionTools.collection( - new TransformationIterator<MappingFileRef, String>(this.mappingFileRefs()) { - @Override - protected String transform(MappingFileRef mappingFileRef) { - return mappingFileRef.getFileName(); - } - } - ) - ); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(this.mappingFileRefs())) { - if (fileBag.count(mappingFileRef.getFileName()) > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_MAPPING_FILE, - new String[] {mappingFileRef.getFileName()}, - mappingFileRef, - mappingFileRef.getValidationTextRange()) - ); - } - } - } - - protected void addClassMessages(List<IMessage> messages) { - addDuplicateClassMessages(messages); - - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - classRef.addToMessages(messages); - } - } - - protected void addDuplicateClassMessages(List<IMessage> messages) { - HashBag<String> classNameBag = new HashBag<String>( - CollectionTools.collection( - new TransformationIterator<ClassRef, String>(this.classRefs()) { - @Override - protected String transform(ClassRef classRef) { - return classRef.getClassName(); - } - } - ) - ); - for (ClassRef javaClassRef : CollectionTools.iterable(this.classRefs())) { - if (javaClassRef.getClassName() != null - && classNameBag.count(javaClassRef.getClassName()) > 1) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_CLASS, - new String[] {javaClassRef.getClassName()}, - javaClassRef, - javaClassRef.getValidationTextRange()) - ); - } - } - } - - private Collection<PersistenceUnitDefaults> persistenceUnitDefaultsForValidation() { - ArrayList<PersistenceUnitDefaults> puDefaults = new ArrayList<PersistenceUnitDefaults>(); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - PersistenceUnitDefaults persistenceUnitDefaults = mappingFileRef.getPersistenceUnitDefaults(); - if (persistenceUnitDefaults != null) { - puDefaults.add(persistenceUnitDefaults); - } - } - return puDefaults; - } - - //************************************* - - public PersistentType getPersistentType(String fullyQualifiedTypeName) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - OrmPersistentType ormPersistentType = mappingFileRef.getPersistentType(fullyQualifiedTypeName); - if (ormPersistentType != null) { - return ormPersistentType; - } - } - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - if (classRef.isFor(fullyQualifiedTypeName)) { - return classRef.getJavaPersistentType(); - } - } - return null; - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - if (mappingFileRef.containsOffset(textOffset)) { - return mappingFileRef; - } - } - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - if (classRef.containsOffset(textOffset)) { - return classRef; - } - } - return this; - } - - public boolean containsOffset(int textOffset) { - if (xmlPersistenceUnit == null) { - return false; - } - return xmlPersistenceUnit.containsOffset(textOffset); - } - - public TextRange getSelectionTextRange() { - return xmlPersistenceUnit.getSelectionTextRange(); - } - - public TextRange getValidationTextRange() { - return xmlPersistenceUnit.getValidationTextRange(); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); - } - - public void dispose() { - for (ClassRef classRef : CollectionTools.iterable(classRefs())) { - classRef.dispose(); - } - for (MappingFileRef mappingFileRef : CollectionTools.iterable(mappingFileRefs())) { - mappingFileRef.dispose(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java deleted file mode 100644 index f0d76469bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import java.util.List; -import org.eclipse.core.resources.IResource; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; - -public class GenericPersistenceXml extends AbstractPersistenceJpaContextNode - implements PersistenceXml -{ - protected PersistenceResource persistenceResource; - - protected Persistence persistence; - - - public GenericPersistenceXml(JpaRootContextNode parent, PersistenceResource persistenceResource) { - super(parent); - this.initialize(persistenceResource); - } - - public String getId() { - // isn't actually displayed, so needs no details page - return null; - } - - @Override - public JpaRootContextNode getParent() { - return (JpaRootContextNode) super.getParent(); - } - - @Override - public IResource getResource() { - return persistenceResource.getFile(); - } - - // **************** persistence ******************************************** - - public Persistence getPersistence() { - return persistence; - } - - public Persistence addPersistence() { - if (persistence != null) { - throw new IllegalStateException(); - } - - XmlPersistence xmlPersistence = PersistenceFactory.eINSTANCE.createXmlPersistence(); - persistence = buildPersistence(xmlPersistence); - persistenceResource.getContents().add(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, null, persistence); - return persistence; - } - - public void removePersistence() { - if (persistence == null) { - throw new IllegalStateException(); - } - this.persistence.dispose(); - Persistence oldPersistence = persistence; - persistence = null; - XmlPersistence xmlPersistence = persistenceResource.getPersistence(); - persistenceResource.getContents().remove(xmlPersistence); - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, null); - } - - protected void setPersistence_(Persistence newPersistence) { - Persistence oldPersistence = persistence; - persistence = newPersistence; - firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, newPersistence); - } - - - // **************** updating *********************************************** - - protected void initialize(PersistenceResource persistenceResource) { - this.persistenceResource = persistenceResource; - if (persistenceResource.getPersistence() != null) { - this.persistence = buildPersistence(persistenceResource.getPersistence()); - } - } - - public void update(PersistenceResource persistenceResource) { - this.persistenceResource = persistenceResource; - if (persistenceResource.getPersistence() != null) { - if (this.persistence != null) { - this.persistence.update(persistenceResource.getPersistence()); - } - else { - setPersistence_(buildPersistence(persistenceResource.getPersistence())); - } - } - else { - if (getPersistence() != null) { - getPersistence().dispose(); - } - setPersistence_(null); - } - } - - protected Persistence buildPersistence(XmlPersistence xmlPersistence) { - return getJpaFactory().buildPersistence(this, xmlPersistence); - } - - - // ************************************************************************* - - @Override - public PersistenceUnit getPersistenceUnit() { - throw new UnsupportedOperationException("No PersistenceUnit in this context"); - } - - - public JpaStructureNode getStructureNode(int textOffset) { - if (persistence.containsOffset(textOffset)) { - return persistence.getStructureNode(textOffset); - } - return this; - } - - // never actually selected - public TextRange getSelectionTextRange() { - return TextRange.Empty.instance(); - } - - public TextRange getValidationTextRange() { - return TextRange.Empty.instance(); - } - - - // **************** validation ********************************************* - - private boolean okToContinueValidation = true; - - @Override - public void addToMessages(List<IMessage> messages) { - super.addToMessages(messages); - addInvalidPersistenceXmlContentMessage(messages); - - if (okToContinueValidation){ - getPersistence().addToMessages(messages); - } - } - - protected void addInvalidPersistenceXmlContentMessage(List<IMessage> messages) { - if (this.persistence == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_XML_INVALID_CONTENT, - this) - ); - okToContinueValidation = false; - } - } - - public void dispose() { - this.persistence.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java deleted file mode 100644 index f3d17d64ec..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericProperty.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericProperty extends AbstractPersistenceJpaContextNode - implements Property -{ - protected String name; - - protected String value; - - protected XmlProperty property; - - public GenericProperty(PersistenceUnit parent, XmlProperty property) { - super(parent); - this.initialize(property); - } - - // **************** name *************************************************** - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - this.property.setName(newName); - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - - // **************** value ************************************************** - - public String getValue() { - return this.value; - } - - public void setValue(String newValue) { - String oldValue = this.value; - this.value = newValue; - this.property.setValue(newValue); - firePropertyChanged(VALUE_PROPERTY, oldValue, newValue); - } - - - // **************** updating *********************************************** - - protected void initialize(XmlProperty property) { - this.property = property; - this.name = property.getName(); - this.value = property.getValue(); - } - - public void update(XmlProperty property) { - this.property = property; - setName(property.getName()); - setValue(property.getValue()); - } - - // **************** validation *********************************************** - - public TextRange getValidationTextRange() { - return this.property.getValidationTextRange(); - } - - // **************** toString - @Override - public void toString(StringBuilder sb) - { - sb.append(" (name: "); - sb.append(name); - sb.append(", value: "); - sb.append(value); - sb.append(')'); - } - -} |